In the first part I gave you an example of automating backup on windows 2003 server using batch files and scheduled tasks. In this second part, I will give another example on automating backup using the same technique but on windows 2008.
Windows 2008 already comes with a predefined template for scheduling backup using task scheduler but using this simple method will only have the option of backing up the whole disk (taking an image of the disk), but fortunately there is an ability to select what to backup using the wbadmincommand through the command prompt.
You must run wbadminfrom an elevated command prompt. Click Start, right-click Command Prompt, and then click Run as administrator.
First we have to prepare the backup destination, in our example here it will be a shared folder, as if you will backup to another disk, wbadmin will format it to place the image. For example the share path will be \\server01\winbackup
Create a batch file “DailyBackup.bat” which will have the following commands:
set backupshare=\\server01\winbackup << This will assign the share name to the a variable to be used in backup script
Specify the volumes to be included in the backup, remember in windows 2008 you can only select the entire volume (C: D: …) but you cannot select individual files or folders. If you use 2008 R2 you can do so and I will explain it in Part 3.
set include=c:,d: <<volume names separated by comma, volume drive letters, volume mount points, or GUID-based volume names
Make sure that you have created the three empty folders inside share1 (Today, Yesterday and Old) and rotate backup among them. Please refer to part 1 to understand why I used these three folders.
del %backupshare%\old\*.* /q
rd %backupshare%\old
ren %backupshare%\yesterday old
ren %backupshare%\today yesterday
md %backupshare%\today
Executing the wbadmin command:
wbadmin start backup -backuptarget:%backupshare%\today -include:%include% -allCritical –quiet
This will execute the image backup of the selected drives. Remember as you must take backup of the entire volume and you can not select certain items, but you can restore individual files and folders or selected items. Each time you execute this batch file will delete the oldest backup and will rename today & yesterday’s back then create new backup in today’s folder.
Scheduling the Backup operation:
Open the Task Scheduler: Control Panel > Administrator tools > Task Scheduler
From the menu select Create Task.
In the Triggers tab, click New, then Select the daily time to execute the task, make sure it is enabled.
Click OK. A new window will open to enter the username & password of the user the task will use when executed. (e.g. username member of the backup operators and permitted to access the backup share folder)
About Restoring Backup in windows 2008:
You have to restore the backup using wbadmin, below are steps to consider:
1- Get the version number of the backup you will restore from:
wbadmin get versions -backupTarget:\\server01\winbackup\today -machine:server01
The output of the command is something similar to the following:
wbadmin 1.0 – Backup command-line tool
(C) Copyright 2004 Microsoft Corp.
Backup time: 8/12/2011 3:44 PM
Backup target: Network Share labeled \\server01\winbackup\Today
Version identifier: 08/12/2011-13:44 ß this is the version number you need
Can Recover: Volume(s), File(s), Application(s), Bare Metal Recovery, System State
2-Get the Items that you can restore:
wbadmin get items -version:08/12/2011-13:44 -backupTarget:\\server01\winbackup\today -machine:server01
The output of the command is something similar to the following:
wbadmin 1.0 – Backup command-line tool
(C) Copyright 2004 Microsoft Corp.
Volume Id = {f711229f-b5cb-11e0-a3f1-806e6f6e6963}
Volume ‘<Unlabeled Volume>’, mounted at C:
Application = FRS
Component = 8C0936D1-A5B0-4F05-99E7-A79FC7873694-C018CBC4-8D91-4BAD-B92A-6E91D97AA640 (SYSVOL\8C0936D1-A5B0-4F05-99E7-A79FC7873694-C018CBC4-8D91-4BAD-B92A-6E91D97AA640)
Application = AD
Component = ntds (C:_Windows_NTDS\ntds)
Application = Registry
Component = Registry (\Registry)
3- Now you can perform one of the following tasks:
Restore the entire drive:
wbadmin start recovery -version:08/12/2011-13:44 -BackupTarget:\\server01\winbackup\today -itemType:Volume -items:c: -machine:server01
Restore System Recovery (Bare Metal)
wbadmin start sysrecovery -version:08/12/2011-13:44 -BackupTarget:\\server01\winbackup\today -machine:server01
Restore System State Recovery
wbadmin start systemstaterecovery -version:08/12/2011-13:44 BackupTarget:\\server01\winbackup\today -authsysvol -machine:server01
Restore Registry
wbadmin start recovery -version:08/12/2011-13:44 -BackupTarget:\\server01\winbackup\today -itemType:App -items:Registry -machine:server01
Restore Files or Folders (e.g. folder1)
wbadmin start recovery -version:08/12/2011-13:44 -BackupTarget:\\server01\winbackup\today -itemType:File -items:c:\folder -recursive
Remember
In most cases you will recover the system (restore the backup) from a connected media (volume) such as a hard Disk, DVD drive, USB drive and so on… Usually when recovering a system it rearly to restore a backup from a shared foler. Accordingly, your -backuptarget option will be a volume (e.g. -backuptarget:F:). In that case the backup folder ” WindowsImageBackup ” should be on the root of that volume.
When berforming the backup and your backuptarget is a volume, then the backup program will format that volume and if there were old backups, they will be lost. That’s why the shared folder is used for backups in windows 2008.
Blogger Comment
Facebook Comment