Note: This article is based on Hyper-V 2.0, and might not apply to Hyper-V 3.0 (Server 2012) Applies to: DPM 2010 (Beta)
This information was originally provided by Angad Pal Singh on the Data Protection Manager blog:
In any virtualized environment, adding new VMs is a frequent operation. If your backup strategy is to protect at the virtualization host level, then you must ensure the protection group is updated manually to include the new virtual machines that have come up on the Hyper-V host.
This article shows how to automate this task using Windows PowerShell scripts. These scripts are expected to work with DPM 2010 Beta. By using the information in this blog post, you should be able to quickly put together a script that can enable the auto protection of your hyper-v hosts.
Download Scripts : AddNewClusteredVM.ps1 and AddNewStandAloneVM.ps1
Note: These scripts work on an existing protection group and do not create a fresh protection group.
The attached scripts automate the task of adding any new virtual machines recognized in the Hyper-V hosts protected by the DPM server into existing protection groups. There are different scripts for Hyper-V clusters (AddNewClusteredVM.ps1) and standalone Hyper-V hosts (AddNewStandAloneVM.ps1). You would still use the script for standalone servers to automatically protect the non-clustered virtual machines of any Hyper-V host that is part of a cluster.
Let us now walk through the scenario and the scripts...
Protecting standalone Hyper-V hosts
The script for standalone servers (AddNewStandAloneVM.ps1) takes as input the following two values in order:
The script performs the following tasks:
1. Takes FQDN of protected server and name of protection group as input. 2. Searches for the protected server and the protection group. 3. Runs inquiry on the Hyper-V host and obtains the list of unprotected virtual machines. 4. Adds the obtained list of virtual machines to the protection group. 5. Saves the changes to the protection group and exits.
1. Takes FQDN of protected server and name of protection group as input.
2. Searches for the protected server and the protection group.
3. Runs inquiry on the Hyper-V host and obtains the list of unprotected virtual machines.
4. Adds the obtained list of virtual machines to the protection group.
5. Saves the changes to the protection group and exits.
Example usage:
This example takes the following values as inputs:
hyperv01.contoso.com – replace this with the name of your Hyper-V host dpm-server01.contoso.com – replace this with the name of your DPM server PS C:\Program Files\Microsoft DPM\DPM\bin> .\AddNewStandAloneVM.ps1 hyperv01.contoso.com "Protection Group 3" Name Domain ---- ------ dpm-server01.contoso.com CONTOSO.COM Running Inquiry on hyperv01.contoso.com Adding data source Backup Using Child Partition Snapshot\StandaloneVM to Protection Group 3 Adding new Hyper-V data sources to Protection Group 3 Exiting from script
hyperv01.contoso.com – replace this with the name of your Hyper-V host
dpm-server01.contoso.com – replace this with the name of your DPM server
PS C:\Program Files\Microsoft DPM\DPM\bin> .\AddNewStandAloneVM.ps1 hyperv01.contoso.com "Protection Group 3"
Name Domain
---- ------
dpm-server01.contoso.com CONTOSO.COM
Running Inquiry on hyperv01.contoso.com
Adding data source Backup Using Child Partition Snapshot\StandaloneVM to Protection Group 3
Adding new Hyper-V data sources to Protection Group 3
Exiting from script
Protecting Hyper-V clusters
The script for clustered servers (AddNewClusteredVM.ps1) takes as input the following two values in order:
1. Takes FQDN of protected cluster and name of protection group as input. 2. Searches for the protected cluster and the protection group. 3. Runs inquiry on the cluster to get the list of resource groups. 4. Runs parallel inquiry for each resource group and obtains the list of unprotected virtual machines under them. 5. Adds the unprotected virtual machines to the protection group. 6. Saves the changes to the protection group and exits.
1. Takes FQDN of protected cluster and name of protection group as input.
2. Searches for the protected cluster and the protection group.
3. Runs inquiry on the cluster to get the list of resource groups.
4. Runs parallel inquiry for each resource group and obtains the list of unprotected virtual machines under them.
5. Adds the unprotected virtual machines to the protection group.
6. Saves the changes to the protection group and exits.
The difference in this script is in Step 3 & 4 in AddNewClusteredVM.ps1 where we run inquiry on the cluster to get the list of resource groups, followed by inquiry on the resource groups. Also, inquiry on resource groups is run in parallel unlike what we do for standalone servers. We run inquiry in parallel for the cluster to avoid a performance overhead. Such an overhead is not seen for standalone servers.
This example takes the following values as input:
csv01.contoso.com – replace this with the name of your Hyper-V cluster
PS C:\Program Files\Microsoft DPM\DPM\bin> .\AddNewCLusteredVM.ps1 csv01.contoso.com "Protection Group 2" Name Domain ---- ------ dpm-server01.contoso.com CONTOSO.COM Running Inquiry on csv01.contoso.com Running Inquiry on Cluster Group Running Inquiry on Available Storage Running Inquiry on SQLLoadVM Running Inquiry on SharepointLoadVM Running Inquiry on Win7VM Waiting for inquiry to complete 0 item(s) obtained... . Waiting for inquiry to complete 1 item(s) obtained... . . Waiting for inquiry to complete 5 item(s) obtained... Inquiry listed 5 item(s)... Adding data source Backup Using Child Partition Snapshot\Win7VM to Protection Group 2 Adding new Hyper-V data sources to Protection Group 2 Exiting from script
PS C:\Program Files\Microsoft DPM\DPM\bin> .\AddNewCLusteredVM.ps1 csv01.contoso.com "Protection Group 2"
Running Inquiry on csv01.contoso.com
Running Inquiry on Cluster Group
Running Inquiry on Available Storage
Running Inquiry on SQLLoadVM
Running Inquiry on SharepointLoadVM
Running Inquiry on Win7VM
Waiting for inquiry to complete 0 item(s) obtained...
.
Waiting for inquiry to complete 1 item(s) obtained...
Waiting for inquiry to complete 5 item(s) obtained...
Inquiry listed 5 item(s)...
Adding data source Backup Using Child Partition Snapshot\Win7VM to Protection Group 2
Adding new Hyper-V data sources to Protection Group 2
You can now write a batch file to call the above scripts one after the other and schedule it using the Windows Task Scheduler to run as frequently as needed.
Important:
· Shared disks that may be listed under the resource groups of your Hyper-V cluster are not Hyper-V data sources, and are not considered for automatic addition using this script.
· Any new virtual machines that are finally added to a protection group are scheduled for immediate replica creation, overriding any existing protection group behavior. You may modify the respective script to change this after referring the specific cmdlet help option.
Danny van Dam edited Revision 5. Comment: added note about that this might not apply to Hyper-V 3.0
Danny van Dam edited Revision 4. Comment: added hyper-v version to title
Carsten Siemens edited Revision 3. Comment: Fixed misspelling
Tony Soper_MSFT edited Original. Comment: moved source ref to top and small rewrite to intro for clarity