DESKTOP

Windows Server 2008 R2 Powershell Cmdlets (part 6) - Windows Server Backup cmdlets

2/27/2014 2:20:03 AM

6. Windows Server Backup cmdlets

The Windows Server Backup cmdlets are the family of cmdlets that help the administrator manage his backups, just as the name implies. Before these cmdlets can be used, you once again need to import the snap-in that contains all these cmdlets. Importing these cmdlets is not as straightforward as some of the other modules. First, you need to install the Windows Server Backup Tools and then, you need to import the PowerShell snap-in. To enable the Windows Server Backup cmdlets, you first install the Windows Server Backup Tools using Server Manager as follows:

1.
Click Start

2.
Click Administrative Tools

3.
Click Server Manager

4.
Server Manager will run, click on Features on the left panel

5.
This will bring up the features panel on the right side

6.
Click Add Features on the right panel

7.
This will open the Add Features wizard and expand Windows Server Backup Features

8.
Check the checkbox for Windows Server Backup

9.
Check the checkbox for Command-line Tools

10.
Click Install

11.
Once the installation is complete, you have the backup tools and are almost done. Now, you need to import the Windows Server Backup cmdlet snap-in as follows:

12.
Startup PowerShell

13.
Type add-pssnapin windows.serverbackup and hit enter

The windows server backup cmdlets snap-in should now be available. You can verify whether it has been imported properly by typing the getpssnapin cmdlet, which will list all the snap-ins, and check to make sure that the windows.serverbackup snap-in is listed (see Figure 22).

Figure 22. Windows.serverbackup is in the snap-in list.

Once this is done, you are ready to start with the Server Backup cmdlets. You divide the cmdlets into five categories: the cmdlets that create, the cmdlets that get, the cmdlets that set, the cmdlets that remove, and the miscellaneous cmdlets (see Tables 1721).

Table 17. Windows Backup cmdlets That Create Objects, the Constructors
cmdlet NameDescription
New-WBPolicyThis cmdlet is used to create a new empty WBPolicy object. This is the object that will govern all your backup rules once you set it. You will need to populate it with all the specifications and properties you want it to have
New-WBFileSpecThis cmdlet is used to create a new WBFileSpec object. This object specifies a rule about what to include or exclude in a WBPolicy when the backup is run
New-WBBackupTargetThis cmdlet is used to create a new WBBackupTarget object. This object specifies where the backups are to be stored

Table 18. Windows Backup cmdlets That Get Items, the Getters
cmdlet NameDescription
Get-WBBackupSetThis cmdlet gets an object that represents a list of all the backups created for the location you specify
Get-WBBackupTargetThis cmdlet gets an object representing the backup target location for the specified policy
Get-WBBareMetalRecoveryThis cmdlet gets a value that represents if the policy specified has the bare metal recovery option enabled. If this is enabled, then backups created by the policy can be used for bare metal recovery
Get-WBDiskThis cmdlet gets a list of disks that are available for the computer
Get-WBFileSpecThis cmdlet gets a list of the WBFileSpec objects that have been associated with the specified policy
Get-WBJobThis cmdlet gets the currently running WBJob object which represents a backup job
Get-WBPolicyThis cmdlet gets the policy that is currently set as the backup policy for the computer
Get-WBScheduleThis cmdlet gets the backup schedule for the specified policy. Giving it no parameter will default to the current active backup policy
Get-WBSummaryThis cmdlet gets the history of backups performed
Get-WBSystemStateThis cmdlet gets a value that represents if the policy specified has the system state recovery option enabled. If this is enabled, then backups created by the policy can be used for system state recovery
Get-WBVolumeThis cmdlet gets a list of volumes determined by the parameters you give it
Get-WBVssBackupOptionsThis cmdlet gets a value of either VssFullbackup or VssCopyBackup depending on the setting of the policy specified

Table 19. Windows Backup cmdlets That Set or Modify Items, the Setters
cmdlet NameDescription
Set-WBPolicyThis cmdlet sets the specified policy as the active policy to be used for backups
Set-WBScheduleThis cmdlet sets the time or times to create daily backups for the specified policy
Set-WBVssBackupOptionsThis cmdlet sets the value specifying if the backups created by this policy are going to be VssFullbackups or VssCopyBackups

Table 20. Windows Backup cmdlets That Remove or Delete Items
cmdlet NameDescription
Remove-WBBackupTargetThis cmdlet removes a specified WBBackupTarget from a specified policy
Remove-This cmdlet removes the bare metal recovery capability from the specified policy.
WBBareMetalRecoveryBackups created by the policy after this cmdlet is run will not be able to be used to make a bare metal recovery
Remove-WBFileSpecThis cmdlet removes a specified WBFileSpec from a specified policy
Remove-WBPolicyThis cmdlet removes the currently set backup policy if no policy is specified. If a policy is specified it removes it as long as it is the currently set backup policy
Remove-WBSystemStateThis cmdlet removes the system state recovery option from the specified policy. Backups created by the policy will no longer be able to be used to make system state recoveries
Remove-WBVolumeThis cmdlet removes a specified volume from a specified policy

Table 21. Miscellaneous Windows Backup cmdlets
cmdlet NameDescription
Start-WBBackupThis cmdlet starts a backup operation using the specified policy

The Windows Server Backup PowerShell cmdlets give you access to all the tools you need to create your own backups, specify when they need to run, and specify what to backup and where to put it. Let us say you walk into work one day, and after passing through all the metal detectors and security checkpoints, you arrive at your desk. On it, you see a curious manila folder with the words TOP SECRET in red. You open it and pull out some yellow-lined paper with strange, illegible writing. You quickly take out your decoder ring and you are able to read the first few lines, “I need you to set up a Backup Policy” it says, followed by more and more specifics. You decide that the first thing you will need to do is create a WBPolicy object. You type $secretPolicy = New-WBPolicy at the prompt and hit enter. When the cmdlet completes, you will have created a new empty WBPolicy object in the $secretPolicy variable. It is this object that you will use to set up your backups. You want to make sure that your policy will create backups that can be used for bare metal recoveries if needed. You type Add-WBBareMetalRecoveryPolicy $secretPolicy and hit enter. This adds the bare metal recovery setting to the policy you created. Using the Add-WBBareMetalRecovery cmdlet on a policy not only adds the bare metal recovery setting to the policy but also adds the system state recovery setting without having to run the Add-WBSystemState cmdlet. So, now the policy can create backups which can be used for bare metal or system state recoveries as well as full server recovery. Decoding a few more lines, you read that the backups must be full VSS backups. You put the decoder ring down and type Set-WBVssBackupOptionsPolicy $secretPolicyVssFullBackup and hit enter. Now that you have taken care of that, you will also need to decide where you are going to back up to. You will need to set up a backup target object. Because you might not be aware of all the disks you could back up to in your server, you will check to see what is available by typing Get-WBDisk and hitting enter. When the cmdlet executes, you see a list of all the disks on the system (see Figure 23).

Figure 23. A single disk on the system.

You then specify a backup location using the New-WBBackupTarget cmdlet by specifying the disk you want to backup to. In this case, you decide that to back up everything to a volume, set aside just for backups, you will be backing up to volume D:. You type $secretDriveBackupLocation = NewWBBackupTargetVolumePath D: and hit enter. This has now created a WBBackupTarget object for you in the $secretDriveBackupLocation variable. You still need to do a few more things before you are ready because your policy is still empty. You have a backup policy and a backup target; you need to decide what exactly needs to be backed up. You check your top-secret mission objectives with your decoder ring and find that you need to back up all the files in a directory called C:\ForYourEyesOnly. Easy enough, you realize you need to create a WBFileSpec object to specify what to backup and what to exclude if anything. You will name the WBFileSpec object $secretFileSpec to be consistent and type $secretFileSpec = New-WBFileSpecFileSpec C:\ForYourEyesOnly and hit enter. The C:\ForYourEyesOnly directory contents and all its subfolders have been marked for backup with this WBFileSpec. If you want to exclude some of the files in the directory, you would use the –Exclude flag. Reading in, you notice that you need to exclude any files that have the word medals at the beginning. You create another WBFileSpec object by typing $noMedalsFileSpec = New-WBFileSpecFileSpec C:\ForYourEyesOnly \*medals*.* -Exclude and hit enter. You pick up your decoder ring and read through the instructions but they seem to stop suddenly. “Typical,” you mumble to yourself. You once again open your desk drawer and take out the special pen that was handed to you for just an occasion. You quickly scribble with the pen over the next section of the instructions and wait for them to appear. You are to set the backup process to run at a secret time of your choosing. It can be anytime as long as you do not tell anyone. You decide to schedule it at 11 pm during the off-peak hours. You will set the WB schedule straight into the secret policy with the SetWBSchedule cmdlet by typing Set-WBSchedulePolicy $secretPolicySchedule 23:00 and hitting enter. The time for the –Schedule flag must be written in HH:MM format. If you need to include more than one time to make backups, at then you can separate them with a comma. Once the cmdlet executes, you will see a confirmation that will show the next time the backup will run according to schedule, you set on that policy. You now have all the basic pieces and just need to put them together. First, you add all the WBFileSpec objects you created to the policy, otherwise it will not know what to backup and what to exclude. You type Add-WBFileSpecPolicy $secretPolicy $secretFileSpec, $noMedalsFileSpec and hit enter. This will add both of your specifications to the policy. If you had any more specifications, you would just create them and add them the same way. You can check the specifications on the policy by typing Get-WBFileSpecPolicy $secretPolicy and hit enter. This will list the specifications you have added so far (see Figure 24).

Figure 24. Listing of the WBFileSpec Objects in the $secretPolicy Policy.

You continue by adding the BackupTarget object you created earlier to the policy. You type Add-WBBackupTargetPolicy $secretPolicyTarget $secretDriveBackupLocation and hit enter, suppressing the urge to look around the room in a paranoid way. When the cmdlet executes, the display will show you a list of properties as confirmation. You are pretty much done. You can put away the decoder ring and special pen and get ready to burn the directions in the garbage can. All that is left to do is set the policy you created as the backup policy. This time you disable the smoke detector before you set the garbage can contents on fire and sit down to finish. You type Set-WBPolicyPolicy $secretPolicy and hit enter. You wait for the cmdlet to execute and then you pick up your phone, dial your boss’s extension, and as soon as he picks up, you whisper “The eagle has landed” and hang up. You sit back down amid the strange stares from your coworkers and wish you had a normal boss. The steps for creating a complete policy using PowerShell are very straightforward. Here are the steps needed.

1.
Create the policy object with the New-WBPolicy cmdlet.

2.
Create all the specifications about what to backup and what to exclude with a WBFileSpec object for each one using New-WBFileSpec cmdlet.

3.
Add the WBFileSpec objects you created to the policy using the Add-WBFileSpec cmdlet.

4.
Create a WBBackupTarget object to indicate where to backup to using the New-WBBackupTarget cmdlet.

5.
Add the WBBackupTarget object you created to your policy using the Add-WBBackupTarget cmdlet.

6.
The final step is to take the policy you created, which now has all the information you specified, and set it as the active backup policy using the Set-WBPolicy cmdlet.

Using the PowerShell Windows Backup cmdlets is easy and straightforward. You can accomplish everything with a few intuitive easy-to-remember cmdlets. Keep in mind the pattern that there are only three kinds of objects to create in the reference of Windows Backups. There are Policies, BackupTargets, and FileSpecs. All the other cmdlets are there to manipulate these objects or to actually run the backups themselves. You can force a backup to run at anytime using the Start-WBBackup cmdlet and you can make it run with a policy that you just created without setting it as the backup policy. This is useful for one-time backup runs with a specific policy instead of the standard backup policy that is set in place.

Other  
  •  Windows Server 2008 R2 : PowerShell V2 feature focus - Installing Powershell, Introduction to Powershell Scripting
  •  Windows Server 2008 R2 : PowerShell V2 feature focus - Introduction to Powershell
  •  Installing Windows 8 on startup VHD files (part 3) - Starting the system from the VHD, Removing VHD installations
  •  Installing Windows 8 on startup VHD files (part 2) - Creating the VHD during the installation by using DiskPart
  •  Installing Windows 8 on startup VHD files (part 1) - Creating a VHD from an existing installation
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 4) - Migrating user data
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 3) - Using an external hard disk or USB flash drive, Using the User State Migration Tool
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 2) - Using removable media, Using a network connection
  •  Windows 8 : Upgrading or migrating from a previous version of Windows (part 1) - Running the Setup Wizard , Configuring your account
  •  Installing Windows 8 on a new or formatted system (part 3) - Installing Windows 8 with Windows To Go
  •  
    Top 10
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    Java Tutorials : Nested For Loop (part 2) - Program to create a Two-Dimensional Array
    Java Tutorials : Nested For Loop (part 1)
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS