There are two ways to do backups from the command line—using
Windows PowerShell or using the Wbadmin command. Personally, we much
prefer using Windows PowerShell for everything we can, but there are
limitations here. The PowerShell interface to backups is done through
a PowerShell snap-in, and this snap-in does not provide any interface
to doing restores, only backups. This isn’t a huge problem because in
the vast majority of cases you don’t need to automate restores, but
you can and should be automating backups.
The other significant limitation of Windows PowerShell support
for managing backups is that it isn’t available on the Microsoft
Hyper-V Server. This means that you can’t use Windows PowerShell to
manage your backups on the Microsoft Hyper-V Server if you’re using
that as your virtualization solution. You’ll need to use the Wbadmin
command.
1. Using the Windows.Serverbackup PowerShell Snap-in
Windows Server Backup includes the Windows.Serverbackup PowerShell snap-in. This snap-in
includes the cmdlets necessary to configure and manage backups on the SBS server. Table 1 includes a
list of the cmdlets included in the snap-in.
Table 1. The cmdlets in the Window.Serverbackup snap-in
NAME | SYNOPSIS |
---|
Get-WBDisk | Returns a list of internal and external disks
that are attached to the local computer. |
Get-WBVolume | Returns a list of volumes that are included in
the current backup policy. |
Add-WBVolume | Adds volumes to the current backup
policy. |
Remove-WBVolume | Removes volumes from the current backup
policy. |
New-WBPolicy | Creates a new backup policy (WBPolicy
object). |
Get-WBPolicy | Returns the current backup policy for the
computer. |
Set-WBPolicy | Sets a WBPolicy object as the current backup
policy for scheduled backups. |
Remove-WBPolicy | Deletes the current backup
policy. |
Get-WBSummary | Returns a history of backup
operations. |
New-WBBackupTarget | Creates a new backup location. |
Get-WBBackupTarget | Returns the current backup target
locations. |
Add-WBBackupTarget | Adds a backup target location to the backup
policy. |
Remove-WBBackupTarget | Removes the backup target locations from the
backup policy. |
Get-WBSchedule | Returns the current backup schedule for
backups. |
Set-WBSchedule | Sets the times for daily
backups. |
Get-WBBackupSet | Returns the list of backups. |
Start-WBBackup | Initiates a one-time backup. |
Get-WBJob | Returns the currently running backup
job. |
New-WBFileSpec | Creates a new WBFileSpec object. FileSpec
objects describe files, folders, and volumes that are
included or excluded from the backup. |
Add-WBFileSpec | Adds the WBFileSpec object to the backup
policy. |
Remove-WBFileSpec | Removes the WBFileSpec object (and the files,
folders, and volumes that it includes or excludes) from the
backup policy. |
Get-WBFileSpec | Returns a list of WBFileSpec objects associated
with the backup policy. |
Add-WBSystemState | Adds the necessary items to the backup policy
to allow for system state recovery. |
Get-WBSystemState | Returns $true if system
state is part of the backup policy. |
Remove-WBSystemState | Removes system state from the backup
policy. |
Add-WBBareMetalRecovery | Adds the necessary items to the backup policy
to ensure a full bare-metal recovery. |
Get-WBBareMetalRecovery | Returns $true if the
backup policy includes the necessary items to ensure a full
bare-metal recovery. |
Remove-WBBareMetalRecovery | Removes the necessary items from the backup
policy that ensure a bare-metal recovery. |
Set-WBVssBackupOptions | Sets the VSS backup type for the backup
policy. |
Get-WBVssBackupOptions | Returns the VSS backup type for the backup
policy. |
The process of defining and using Windows PowerShell to manage backups requires first creating the Windows Backup
policy object and then configuring it with one or more file
specification objects (WBFileSpec), a schedule object (WBSchedule), system state and bare-metal recovery
options, and a Volume Shadow Service (VSS) backup type. So, to
define a full-server backup to the network share
\\wss-200\serverbackup that included all the files on volumes C and
D except those in \temp, and included the necessary files for
bare-metal and system state recovery, using a VSS backup type of VSS
Full Backup, the PowerShell script would be:
# Script to set a Windows Server Backup policy for SBS
# Created 27/12/2010
# Assumes: Volumes C:, D: and E: to backup.
# : Target - \\wss-200\serverbackup
# : Exclusions - D:\temp, E:\temp
# : VSS Mode - Full Backup
# : System State - True
# : Bare Metal Recovery - True
# : Schedule - 12:30 PM, 9:00 PM
# ModHist: 27/12/10 - initial
# : 28/12/10 - Final
#
# The following will error if already loaded, but continue, so ignore
Add-PSSnapin Windows.ServerBackup
# First, create a new empty policy
$BackupPolicy = New-WBPolicy
# Now, define the parts of it.
# First, let's do the volumes. This requires us to first get a list of them,
# and then parse that list to add the ones we want (C:, D: and E:)
# We don't actually need C:, since we'll get that as part of Bare Metal Restore,
# but we include it anyway for completeness
$volC = Get-WBVolume -AllVolumes | Where {$_.MountPath -eq "C:"}
$volD = Get-WBVolume -AllVolumes | Where {$_.MountPath -eq "D:"}
$volE = Get-WBVolume -AllVolumes | Where {$_.MountPath -eq "E:"}
$Volumes = $volC,$volD,$volE
# now, add that to the blank policy
Add-WBVolume -policy $BackupPolicy -volume $Volumes
#Define the Exclusions.
$excD = New-WBFileSpec -Filespec D:\Temp -exclude
$excE = New-WBFileSpec -Filespec E:\Temp -exclude
$FileExclusions = $excE,$excD
# and then add that to the policy we're building
Add-WBFileSpec -policy $BackupPolicy -filespec $FileExclusions
# Define the backup target
# First, you need to create a credential to connect to the remote share
# You can specify the username here (DOMAIN\User) but will be
# prompted for the password
$Cred = Get-Credential example\Charlie
# Now, define the target
$Target = New-WBBackupTarget -NetworkPath \\WSS-200\ServerBackup -Credential $Cred
# Add the target to the policy
Add-WBBackupTarget -policy $BackupPolicy -target $Target
# Define the schedule
$sch1 = [datetime]"12/27/2010 12:30:00"
$sch2 = [datetime]"12/27/2010 21:00:00"
Set-WBSchedule -policy $BackupPolicy -schedule $sch1,$sch2
# Set for system state and for bare metal recovery
Add-WBSystemState -policy $BackupPolicy
Add-WBBareMetalRecovery -policy $BackupPolicy
# Finally, set for full VSS Backup
Set-WBVssBackupOptions -policy $BackupPolicy -VssFullBackup
# Finally, we need to SET the policy before it actually takes control
Set-WBPolicy -force -policy $BackupPolicy
# This completes the configuration of the SBS server backup policy
$SBSname = (hostname).tolower()
" The SBS Server $SBSname now has the following backup configuration: "
""
Get-WBPolicy
2. Using the Wbadmin Command
The Wbadmin command allows you to back up and restore volumes
and files from the command line. Wbadmin replaces the Ntbackup command that was part of SBS 2003. You can’t
use Wbadmin to recover backups created with Ntbackup. However, if you need to
recover backups made with Ntbackup, you can download a version of
Ntbackup usable with Windows Server 2008 R2. This downloadable
version of Ntbackup allows you to perform recoveries of legacy
backups, but you cannot use it on Windows Server 2008 R2 to create
new backups. To download this version of Ntbackup, see http://go.microsoft.com/fwlink/?LinkId=82917.
The next sections list Wbadmin commands and syntax. Table 2 lists and describes the parameters
used with Wbadmin. For additional assistance, type Wbadmin /? at a command prompt.
Note:
Not all the Wbadmin commands are visible from the command line.
Certain commands are available only from the Windows Recovery
Environment, or are hidden but available for use. For the complete
Command Reference see http://go.microsoft.com/fwlink/?LinkId=93131.
Table 2. Wbadmin parameters
PARAMETER | DESCRIPTION |
---|
-addtarget | Storage location for backup. Disk is formatted
before use and any existing data on it is permanently
erased. |
-allCritical | Automatically includes all critical volumes
(volumes that contain system state data). Can be used along
with the -include
option. |
-backupTarget | Storage location for this backup. Requires a
hard disk drive letter (f:) or a Universal Naming Convention
(UNC) path to a shared network folder
(\\servername\sharename).
If a shared network folder is specified, this backup will
overwrite any existing backup in that
location. |
-dfsAuth | Marks the restore as authoritative. Can be used
only when the server being recovered is hosting folders that
are being replicated by Distributed File System Replication
(DFSR). This parameter makes the recovered version of the
replicated folders the authoritative copy, thereby
overwriting the version stored on other members of the
replication group. If this parameter is not used, the data
is restored as a nonauthoritative copy. |
-excludeDisks | Can be used only with the
-recreateDisks parameter. Must be input
as a comma-delimited list of disk identifiers (as listed in
the output of wbadmin get disks). Excluded disks are not
partitioned or formatted. This parameter helps preserve data
on disks that you do not want modified during the
recovery. |
-include | Comma-delimited list of volume drive letters,
volume mount points, or GUID-based volume names to include
in the backup. |
-noInheritAcl | If specified, the computer-name folder applies
ACLs for the user whose credentials were given when running
the backup and grants access to the Administrators group and
Backup Operators group on the computer with the shared
network folder. If -noInheritAcl is not
used, the ACL permissions from the remote shared folder are
applied to the <ComputerBackedUp> folder by default so
that anyone with access to the remote shared folder can
access the backup. |
-items | Comma-delimited list of volumes, applications,
and files to recover. If
-itemtype is Volume, it can be only a
single volume that is specified by providing the volume
drive letter, volume mount point, or GUID-based volume
name. If -itemtype is App,
it can be only a single application. Applications that can
be recovered include SQL Server and Windows SharePoint
Services. You can also use the value
ADExtended to recover an installation
of Active Directory. If
-itemtype is File, it can be files or
directories, but it should be part of the same volume and it
should be under the same parent. |
-itemtype | Type of items to recover. Must be Volume, App,
or File. |
-machine | Specifies the name of the computer for which
you want to recover the backup. Should be used when
-backupTarget is
specified. |
-notrestoreacl | Can be used only when recovering files.
Specifies to not restore the security ACLs of the files
being recovered from backup. By default, the
security ACLs are restored. (The default value is
true.) If this parameter is used, the
default ACLs for the location that the files are being
restored to are applied. |
-noVerify | If specified, backups written to removable
media (such as a DVD) are not verified for errors. If not
specified, backups written to such media are verified for
errors. |
-overwrite | Valid only when recovering files. Specifies the
action to take when a file that is being recovered already
exists in the same location.
Overwrite causes the recovery to
overwrite the existing file with the file from the
backup. CreateCopy causes
the recovery to create a copy of the existing file so that
the existing file is not modified.
Skip causes the recovery to skip
the existing file and continue with recovery of the next
file. |
-password | Password for the user name that is specified by
the parameter -user. |
-recoveryTarget | Specifies the drive to restore to. Use if this
drive is different than the one that was previously backed
up. Can also be used for restorations of volumes, files, or
applications. If you are restoring a volume, you can specify
the volume drive letter of the alternate volume. If you are
restoring a file or application, you can specify an
alternate backup path. |
-recreateDisks | Restores a disk configuration to the state that
existed when the backup was created. |
-recursive | Can be used only when recovering files.
Recovers the files in the folders and all files subordinate
to the specified folders. By default, only files that reside
directly under the specified folders are
recovered. |
-removetarget | Storage location specified in the existing
backup schedule. |
-restoreAllVolumes | Restores all volumes from the selected backup.
If this parameter is not specified, only critical volumes
(volumes that contain system state data) are restored from
the selected backup. Useful when you need to restore
noncritical volumes during system recovery. |
-schedule | Comma-delimited times of day specified as
HH:MM. |
-showsummary | Can be used only with Wbadmin start sysstaterecovery. Reports the
summary of the last run of this command. This parameter
cannot be accompanied by any other
parameters. |
-skipBadClusterCheck | Can be used only when recovering volumes. This
skips checking your recovery destination disks for bad
cluster information. If you are restoring to an alternate
server or hardware, this switch should not be used. You can
manually run the command chkdsk /b on
your recovery disks at any time to check them for bad
clusters, and then update the file system information
accordingly |
-user | Specifies the user name with write access to
the backup destination (if it is a shared network folder).
The user needs to be a member of the Administrators or
Backup Operators group on this computer. |
-quiet | Runs the command with no prompts to the
user. |
-version | Specifies the version of the backup in
MM/DD/YYYY-HH:MM format, as listed by wbadmin get versions. |
-vssFull | If specified, performs a full backup using
Volume Shadow Copy Service (VSS). Each file’s history is
updated to reflect that it was backed up. If
this parameter is not specified, Start Backup makes a copy
backup, but the history of files being backed up is not
updated. Caution: Do not use this parameter
when using a non-Microsoft program to back up
applications. |
2.1. Wbadmin Enable Backup
The following subcommand enables or configures scheduled
daily backup:
Wbadmin enable backup
[-addtarget:{backuptargetdisk | backuptargetnetworkshare}]
[-removetarget:{backuptargetdisk | backuptargetnetworkshare}]
[-schedule:timetorunbackup]
[-include:volumestoinclude]
[-allcritical]
[-user:username]
[-password:password]
[-inheritacl:inheritacl]
[-quiet]
2.2. Wbadmin disable backup
The following subcommand disables running scheduled daily
backups:
wbadmin disable backup
[-quiet]
2.3. Wbadmin start backup
The following subcommand runs a backup job:
wbadmin start backup
[-backupTarget:{TargetVolume | TargetNetworkShare}]
[-include:VolumesToInclude]
[-allCritical]
[-vssFull]
[-noVerify]
[-user:UserName]
[-password:Password]
[-noinheritAcl]
[-quiet]
2.4. Wbadmin stop job
The following subcommand stops a running backup or recovery
job:
Wbadmin stop job
[-quiet]
2.5. Wbadmin start recovery
The following subcommand runs a recovery based on the
specified parameters:
wbadmin start recovery
-version:VersionIdentifier
-items:VolumesToRecover | AppsToRecover | FilesOrFoldersToRecover}
-itemtype:{Volume | App | File}
[-backupTarget:{VolumeHostingBackup | NetworkShareHostingBackup}]
[-machine:BackupMachineName]
[-recoveryTarget:{TargetVolumeForRecovery | TargetPathForRecovery}]
[-recursive]
[-overwrite:{Overwrite | CreateCopy | Skip}]
[-notRestoreAcl]
[-skipBadClusterCheck]
[-noRollForward]
[-quiet]
2.6. Wbadmin start systemstatebackup
The following subcommand creates a backup of the system
state of a computer. A backup of the system state can be saved
only to a locally attached disk (either internal or external). It
cannot be saved to a DVD or to a remote shared folder. In
addition, only the system state and system applications can be
recovered from this backup—volumes and files cannot be recovered
from this backup.
wbadmin start systemstatebackup
-backupTarget:<VolumeName>
[-quiet]
2.7. Wbadmin start systemstaterecovery
The following subcommand runs a system state recovery based
on the supplied parameters:
wbadmin start systemstaterecovery
-version:VersionIdentifier
-showsummary
[-backupTarget:{VolumeName | NetworkSharePath}]
[-machine:BackupMachineName]
[-recoveryTarget:TargetPathForRecovery]
[-excludeSystemFiles]
[-authsysvol]
[-quiet]
2.8. Wbadmin start sysrecovery
The following subcommand runs a system recovery based on
specified parameters. This command can be run only from the
Windows Recovery Environment, and it is not listed by default in
the usage text of Wbadmin. (You can access the Windows Recovery
Environment from a Windows Server 2008 R2 installation DVD by
inserting the DVD and following the steps in the wizard until you
see the option Repair Your Computer. Click this link to open the
System Recovery Options dialog box.)
wbadmin start sysrecovery
-version:VersionIdentifier
-backupTarget:{VolumeHostingBackup | NetworkShareHostingBackup}
[-machine:BackupMachineName]
[-restoreAllVolumes]
[-recreateDisks]
[-excludeDisks]
[-dfsAuth]
[-skipBadClusterCheck]
[-quiet]
2.9. Windows Recovery Environment
Windows Recovery Environment (Windows RE) is a recovery
platform designed to automatically repair common causes of
unbootable operating system installations. When the computer fails
to start, Windows automatically fails over into this environment,
and the Startup Repair tool in Windows RE automates diagnosis and
repair. In addition, Windows RE is a starting point for various
tools for manual system recovery.
Windows RE is a partial version of the operating system plus
a set of tools you can use to carry out operating system or full
server recoveries, using a backup that you created earlier using
Windows Server Backup.
2.10. Wbadmin get versions
The following subcommand reports on the available backups:
wbadmin get versions
[-backupTarget:{VolumeName | NetworkSharePath}]
[-machine:BackupMachineName]
2.11. Wbadmin get status
The following subcommand reports the status of the current
backup or recovery:
wbadmin get status