Bare Metal Recovery + Shutdown Script

Forums Operating Systems Windows Server 2008 R2 Miscellaneous Bare Metal Recovery + Shutdown Script

Viewing 1 reply thread
  • Author
    Posts
    • #44372

      I thought I would post a simple script on how you can perform a bare metal recovery image of your server which would allow you restore the entire OS in the event of a virus outbreak or corruption. The advantage of creating a bare metal image in a batch file is that you can schedule the computer to shutdown afterwords. This script is also useful for those who have recently installed R2 and fully configured it and want a nice baseline to go off just in case something screwy happens later and you don’t want all that effort gone to waste.

      *****SCRIPT ***************

      wbadmin start backup -backupTarget:D: -include:C: -systemState -allcritical -quiet
      shutdown /s /t 0

      *****SCRIPT ***************

      Copy the two lines in notepad and save it as backupandshutdown.bat or something similar.

      This will perform a bare metal recovery of your OS, entire SYSTEM drive, as well as system state, so if you have installed quite a bit this could take an hour or so. This script requires 2 partitions to perform this backup, preferably a 2nd physical drive. You may also have to adjust the backup target to match the drive letter of the target you wish to backup your server to. For example your external might be marked K: so you would want to put -backupTarget:K: in the script.

      In the screenshot below you can see the command-line script in the right window and the GUI front end equivalent of what you would see if you configured it from the UI. It is the same function, just showing you exactly what the script is doing, from a GUI perspective.

      [attachment=0:38iz65sh]backupandshutdown.jpg[/attachment:38iz65sh]

      As far as re-imaging is concerned, you can take wbadmin tool to keep 2 copies of the backup image by adding the -keepVersions:2 to the script, but that would take up a lot of space. There is a way to remove the system state backup from wbadmin but not the whole entire backup image as far as I know. To circumvent this you could easily just create an additional line of code in the script that would navigate to the backup directory and remove it, like such:

      D:
      cd WindowsImageBackup
      RD %COMPUTERNAME% /s /q

      Your final script could look such

      ************************************************************
      #Remove existing backup
      D:
      cd WindowsImageBackup
      rd %computername% /s /q
      #Create new system image
      wbadmin start backup -backupTarget:D: -include:C: -systemState -allcritical -quiet
      #After performing backup, shutdown computer.
      shutdown /s /t 0

      ************************************************************

      You could create an inital system backup image (a clean, safe virus free one) on a separate drive, and then use an additional drive to create a “refresh” image sort to speak. The inital image on the plus side contains your “barebone” OS, while the refresh image contains the most up-to-date software, games, documents, settings, etc. You might, for example install Battlefield 3 on this current image, but 3 months down the road you do not want BF3 no more and wish not to include it in the backup. This refresh image script would be ideal for maximizing your disk space and keeping your PC current. If a virus or some configuration goes wrong and messes up Windows you can easily revert back to the last date of your backup and the only thing that would be lost was data was the past few days, or hours. A lot better than spending hours and hours again re-creating everything back from scratch!

      Hope you have appreciated my tips and have a great day.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.