You may choose to back up and recover your systems
with command-line tools. Specifically, in the case of a Windows Server
2008 R2 Server Core installation, two options are available to you; they
are the command-line tool wbadmin.exe (the command-line equivalent of the Windows Server Backup GUI) and PowerShell cmdlets.
Regardless of which tool you
use, the techniques, terminology. These tools provide the same capabilities as the GUI for Windows
Server Backup. Therefore, you do not need to relearn all the previously
mentioned information—the command-line versions are just an alternative
way to access the tools.
In this section, you will see how to back up and recover your systems with the command-line tools.
1. Use wbadmin.exe
Using the command-line tool wbadmin.exe
provides you with a method to create scripts for backup as well as a
method to back up servers like Server Core installations where there is
no GUI present. Table 1 describes some of the common switches for the wbadmin.exe backup. For more information on how to use wbadmin.exe, in a command prompt, type the following command and hit Enter:
wbadmin /?
Table 1. wbadmin.exe Common Switches
Switch | Explanation |
---|
enable backup | Allows you to modify or create a backup schedule |
start backup | Performs a one-time backup |
get disks | Lists the current disks available and online |
start systemstatebackup | Allows you create a system state backup |
start recovery | Begins the recovery process from an existing backup |
1.1. wbadmin.exe Examples
Here are some examples on how you can use wbadmin.exe to perform the various tasks of backup and recovery.
Before you back up the systems,
you will need to see what drives are available on the system. When you
create a backup, you can use the drive letter if one exists, or you will
need the disk identifier. To see what drives are available, run the
following command:
wbadmin get disks
Your output will look similar to Figure 1.
The following command will
create a backup of the C and D drives and would occur daily at 4 a.m.
and 10 p.m. The backup would be stored on the disk {7caba166-0000-0000-0000-000000000000}.
wbadmin enable backup
-addtarget:{7caba166-0000-0000-0000-000000000000}
-schedule:04:00,22:00 -include:c:,d:
If you wanted the backup to occur just once, the command would look like this:
wbadmin start backup
-backuptarget:{7caba166-0000-0000-0000-000000000000}
-include:c:,d:
The following command would back up the system state to the disk {7caba166-0000-0000-0000-000000000000}:
wbadmin start systemstatebackup
-backuptarget:{7caba166-0000-0000-0000-000000000000}
To be able to restore items with wbadmin.exe, you need to know two things: the backup version identifier and what items are stored in the backup. You use wbadmin get versions
to find out what backups you currently have available. Specifically,
you are looking for the version identifier, which is formatted as a date
and timestamp. You would run the following command to see the items
backed up on June 30, 2009, at 2:05 p.m.
wbadmin get items -version:06/30/2009-14:05
The results would look similar to Figure 2.
The following command would restore the C volume from the backup taken on June 30, 2009, at 2:05 p.m.:
wbadmin start recovery —version:06/30/2009-14:05
-itemType:Volume -items:c:
2. Use PowerShell
These cmdlets provide another tool to perform your server recovery. If
you choose to install the command-line tools for Windows Server Backup,
you will have access to the PowerShell backup and restore cmdlets as
well. Before you can run these tools, you have to verify the PowerShell
snap-in for backing up has been loaded.
To verify the tools have been loaded, run the following command from a PowerShell window. Then verify you see Windows.ServerBackup as the loaded snap-in.
Get-PSSnapin
If you do not see Windows Server Backup in your loaded snap-ins, you will need to run this command:
Add-PSSnapin windows.serverbackup
Working with the PowerShell is quite a bit more complex than working with wbadmin.exe
to perform backup tasks. You need to create a PowerShell script to
accomplish your tasks. Although PowerShell can be more complex, it does
offer some nice flexibility to performing backups. All the capabilities
of PowerShell are determined by what backup policy you set. The backup
policy for PowerShell is stored in an object called WBPolicy. The WBPolicy object contains all the settings for the backup, including the schedule, backup types, backup targets, and so on.
Working with PowerShell and backup, you need to understand how to set the values for the WBPolicy object. Table 2 describes some of the common PowerShell commands used for backup and recovery and how to set the parameters for WBPolicy. For a full listing of the PowerShell cmdlets for backing up the system, run the following cmdlet:
Get-Command *wb* -CommandType cmdlet
Table 2. PowerShell Backup Cmdlets
cmdlets | Explanation |
---|
Get-WBPolicy | Displays the current settings for the WBPolicy object on the server |
Set-WBPolicy | Allows you to set the parameters for the WBPolicy |
Add-WBVolume | Adds a volume to the WBPolicy object to be backed up |
Add-WBSystemState | Adds the system state to the WBPolicy object to be backed up |
Set-WBSchedule | Sets the time for your daily backup schedule |
Start-WBBackup | Starts a one-time backup |
Get-WBJob | Shows the current status of a running backup job |
2.1. PowerShell Examples
As you can see in Table 8.5,
only a few of the commands are available to work with PowerShell in
Group Policy. This section gives a couple of examples to allow you to
get used to using PowerShell.
The following two lines will
back up your system with your current backup policy settings. You can
create a PowerShell script to run these commands, or you can run each
line separately by hitting Enter after each line:
$policy = Get-WBPolicy
Start-WBBackup -Policy $policy
This first line sets the $policy variable to the current settings in WBPolicy. The second line starts the backup process with settings currently in the WPObject object's $policy variable.
The following script will
back up the C, D, and system state on your system to your Z drive.
Notice you will be using a variety of the Add cmdlets to modify the value of the variable $policy, as well as variables for target and paths:
$policy = New-WBPolicy
$volume = Get-WBVolume -VolumePath c:
Add-WBVolume -Policy $policy -volume $volume
$volume1 = Get-WBVolume -VolumePath d:
Add-WBVolume -Policy $policy -volume $volume1
Add-WBSystemState -Policy $policy
$target = New-WBBackupTarget -VolumePath Z:
Add-WBBackuptarget -Policy $policy -target $target
Start-WBBackup -Policy $policy