Wednesday, November 23, 2011

Customizing Windows Server Backup Schedule


Windows Server Backup (WSB) is the built-in backup solution for Windows Server 2008 that replaces the venerable NT Backup from Windows Server 2003 and before.  WSB protects the files and the server os/application binaries within itself as a single-server solution.  To consolidate protection across multiple servers or applications like SQL Server, Exchange, SharePoint or Hyper-V, then Microsoft would recommend looking at System Center Data Protection Manager (DPM).

By design, WSB ensures that you have recent backups by performing its local backup operations at least once per day. While this is good and recommended there may be reasons specific to your environment where you may want to take backups at a lesser frequency or have multiple backup schedules (e.g. daily and weekly). For example, you may want to backup your files every day, while backing up the system state at lesser frequency say once a week.

You can extend the functionality of Windows Server Backup to meet all these advanced needs through simple scripts that uses Windows Server Backup Command Line Tool (WBADMIN) and the Windows Task Scheduler (SCHTASKS).

If you are not aware of Task Scheduler, it is a a management application provided in Windows operating systems that allows you to schedule any task for a given set of conditions. Task Scheduler also provides a command line interface (CLI) through the command SCHTASKS.
Samples
The samples here assume the following configuration of the system:
·        A single disk containing system drive (C:),
·        Two data volumes (D: and E:)
·        Dedicated backup volumes (H:, I: and J:).

These volume names and parameters are used as boldface in the samples below. Readers can customize them as per their requirements.
 Sample 1: Daily Data Volume Backup
The following command will create a Task Scheduler task named DailyVolumeBackup with the start time of 23:00. This task will run DAILY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup volume E: to target volume H:.

Syntax:

SCHTASKS /Create /SC DAILY /TN /RL HIGHEST /ST /TR

Example:

SCHTASKS /Create /SC DAILY /TN DailyVolumeBackup /RL HIGHEST /ST 23:00 /TR "WBADMIN START BACKUP -backupTarget:H: -include:e: -quiet >> C:\backupLogs.txt"
Sample 2 : Weekly Backup of System State
The following command will create a Task Scheduler task named WeeklySystemStateBackup that runs every Saturday (SAT) at 19:00. This task will run WEEKLY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup SYSTEMSTATEBACKUP to target volume I:.

Syntax:

SCHTASKS /Create /SC WEEKLY /D  /TN /RL HIGHEST /ST /TR

Example:

SCHTASKS /Create /SC WEEKLY /D SAT /TN WeeklySystemStateBackup /RL HIGHEST /ST 19:00  /TR "WBADMIN START SYSTEMSTATEBACKUP -backupTarget:I: -quiet  >> C:\backupLogs.txt "
Sample 3 : Complete System Backup Once in Two Weeks
The following  command will create a Task Scheduler task named OnceInTwoWeeksFullBackup that runs every Sunday (SUN) at 1:00 once every 2 weeks. This task will run WEEKLY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup allCritical volumes to target volume J:.

Syntax:

SCHTASKS /Create /SC WEEKLY /MO  /D  /TN /RL HIGHEST /ST /TR

Example:

SCHTASKS /Create /SC WEEKLY /MO 2 /D SUN  /TN OnceInTwoWeeksFullBackup /RL HIGHEST /ST 01:00  /TR "WBADMIN START BACKUP -backupTarget:J: -allCritical -quiet  >> C:\backupLogs.txt "
Notes:
  1. Above tasks needs to be ran with highest privileges as Windows Sever Backup requires administrative privileges to run. If you are using “Task Scheduler” UI to configure the jobs make sure you use the "[  ] Run with highest priviledges" UI option in the security options of the task.
  2. Since WBADMIN command will fail if any other backup job is already running, ensure that the backup jobs are scheduled with a sufficiently long time interval between two jobs.
  3. Backups scheduled using windows scheduler (SCHTASKS) will not appear in the Windows Server Backup application user interface.
  4. You can use a network location (i.e. \\servername\foldername) as a backup target in above commands. However, network backups will save only the latest version of the backup, deleting the previous version, as multiple versions on the network share are not supported.
  5. You can use other WBADMIN CLI options to customize the backup, such as the option vssFull. Please see Windows Server Backup CLI for more details on CLI options.
  6. You can use Task Scheduler advance functions  like setup  additional tasks to run before/after the above jobs.  Example of the pre-tasks are disabling an antivirus, closing a service etc. Example of the post-tasks are upload the logs, send an email etc.
  7. Since command line interface is interactive in nature and give error/completion information in the console itself, output of all the above invocation should be directed to a log file so that it can be referred in case of any error while running the backup.
  8. For optimal storage space utilization on the backup target you can modify the VSS shadow storage using the following command:vssadmin resize shadowstorage /for= /on= /maxsize=UNBOUNDEDFor example: vssadmin resize shadowstorage /for=H: /on=H: /maxsize=UNBOUNDED

No comments: