Symptoms Following are some examples of Pre-Recovery and/or Post-Recovery scripts for use with Zerto Virtual Replication. |
Solution
Example 1 – Replace DNS A and PTR Records
The following script, c:ZertoScriptsDNS-Change.ps1, replaces multiple DNS A and PTR records for the two DNS servers, mydns1 and mydns2:
## Set DNS servers
$DNSservers= @("mydns1", "mydns2")
## Filepath to script and CSV files
$FP = "C:ZertoScripts"
CD $FP
Foreach($DNSserver in $DNSservers)
{
Import-CSV .DNS-OldA.csv | foreach {
dnscmd $DNSserver /RecordDelete $_.zone $_.hostname A $_.ip /f}
Import-CSV .DNS-NewA.csv | foreach {
dnscmd $DNSserver /RecordAdd $_.zone $_.hostname A $_.ip}
Import-CSV .DNS-OldPTR.csv | foreach {
dnscmd $DNSserver /RecordDelete $_.reversezone $_.lowip PTR $_.fqdn /f}
Import-CSV .DNS-NewPTR.csv | foreach {
dnscmd $DNSserver /RecordAdd $_.reversezone $_.lowip PTR $_.fqdn}
}
The script must be in the same folder, C:ZertoScripts, on both the local and remote Zerto Virtual Managers and this is the folder is the folder specified for the variable $FP in the script.
Update Command to run and Params fields for all the VPG definitions that you want to run the script.
Command to run – CMD:powershell.exe
Params – C:ZertoScriptsDNS-Change.ps1
This script requires that the machines running the Zerto Virtual Managers must be logged in as a member of the DNS administrators group and that all prerequisites for DNSCMD.exe are available. In addition, you require the files DNS-OldA.csv, DNS-NewA.csv, DNS-OldPTR.csv and DNS-NewPTR.csv, with the relevant A and PTR values in the same folder as the PowerShell script (C:ZertoScripts).
This example is for reference only.
Example 2 – Recording Failover Tests
The following script, c:ZertoScriptsTestedVPGs.bat, writes the VPG name and date to the TestedVPGs.txt file every time a failover test is run:
Where %1 is the first parameter in the list of parameters, %ZertoOperation%, and %2 is the second parameter in the list of parameters, %ZertoVPGName%.
Note: If the file ListOfTestedVPGs.txt does not exist it is created, as long as the folder, c:ZertoScriptsResults, exists.
Update Command to run and Params fields for all the VPG definitions that you want to run the script.
Command to run – c:ZertoScriptsTestedVPGs.bat
Params – %ZertoOperation% %ZertoVPGName%
Whenever a failover test is run on the relevant VPGs the TestedVPGs.txt file is updated with the name of the VPG and the date and time the test was run.
Example 3 – Moving Virtual Machines to a Resource Pool After a Failover
The following PowerShell script is an example of how to move virtual machines into resource pools as a post-recovery script. This script would typically be used when you want to move virtual machines into a resource pool following a failover. Note that this script is a basic example and requires some configuration, as noted in the comments of the script: