Import/Export configuration SRM [Script]

On April 17, VMware announced the release of its new version vSphere 6.7 and SRM 8.1. Among the many improvements that both bring, I stayed with the SRM 8.1, which already has an Import/Export tool of the SRM configuration (Protection Group, Recovery Plan, Mappings, etc.). Now, the problem is the next, if you  want to migrate 5.5 to a 6.X, the Import / Export that SRM 8.1 offers does not work. I think we have found this problem more than one ;).

In this post we are going to learn how to export and import SRM configuration. If you have had to upgrade your virtual infrastructure, you will have encountered this problem. For example, if we had to do a new SRM installation, we should do a backup/restore of our Protection Groups, Recovery Plans, etc. This tool doesn’t exist, but it exists as a limited API. Right now, I found this problem and I decided to build a script for export and import.

First, like we already spoke in another post, we must have the “Meadowcroft.SRM” Module installed, in order to attack the SRM API. We can download the module through the following link Meadowcroft.SRM

srm2

Once we have installed the module, we can start to test the SRM API. Like, we spoke in others post, to use the API, we must run the next:

srm1

 

 

 

 

Let’s Go!!!! First, we should know, what do we need?. Right, we need export a lists of Protection Groups and Recovery Plans that we have configured in our SRM Server. After, we will try to import these lists in a new SRM installation.

It’s important to know what information we will need and it’s kind of information, it’s important because we will use this information to create de new PG or RP in the new SRM installation.

Here I leave the following script to Export Protection Groups Configuration:

############################################################################################################################# www.cloudvm.es #############################################
#############################################################################################
######                                                                                #######
###### Script Name : export_config_SRM_PG.ps1                                         #######
###### Version : 1.0                                                                  #######
###### Author: Mario Gómez (CloudVM)                                                  #######
###### Twitter : @mariogg85                                                           #######
###### Mail : mariogomezgallego85@gmail.com                                           #######
###### Objective: Make a Export of Protection Groups configuration in our SRM Server  #######
###### Example: export_config_SRM_PG.ps1                                              #######
######                                                                                #######
#############################################################################################
#############################################################################################

# START SCRIPT

# Functions

# Save the path of our script. In this path we save the csv file with the exported configuration.
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path

# Credentials with permissions in Virtual Center and SRM Server.
 
$USER = 'cloudvm'
$PASS = 'script'

# Connection Info

$EXPORT_VCENTER = 'FQDN_vCenter_Activo'
$EXPORT_VCENTER2 = 'FQDN_vCenter_Pasivo'
$SRMSERVER = 'FQDN_SRM_Activo'

# Vars declaration

$Protection_Group_List = @()
$Protection_Group_List += 'Name' + "," + 'Type'+ "," + 'Datastores' + "," + 'State'

# *************** CONNECTION PRE-EXPORT ********************************************************************

# Connection to Primary and Secondary Site.

Write-Host "Connect Virtual Center : $EXPORT_VCENTER ..." -fo Green
Connect-VIServer -Server $EXPORT_VCENTER -User $USER -Password $PASS -WarningAction 0 | Out-Null
Write-Host "Connect Virtual Center : $EXPORT_VCENTER2 ..." -fo Green
Connect-VIServer -Server $EXPORT_VCENTER2 -User $USER -Password $PASS -WarningAction 0 | Out-Null

# SRM Server Connection

Write-Host "Connect SRM Server..." -fo Green
$Srm = Connect-SrmServer -Server $EXPORT_VCENTER -User $USER -Password $PASS -WarningAction 0

# Load the SRM API

$SrmApi = $Srm.ExtensionData

# Get a List of Protection Groups

$List_PG = $SrmApi.Protection.ListProtectionGroups()

# For each Protection Group in the list previously getted, we are going to get the information necessary

foreach ($PG in $List_PG)
{

 # Get the Protection Group Name and the Type (ABR (Array Based Replication)/VR (vSphere Replicator))

 $Name_PGroup = ($PG.GetInfo()).Name
 $Type_PGroup = ($PG.GetInfo()).Type
 

 # Get the list of Datastores Protected by Protection Group
 # In this point, we need to know if we are going to migrate the Virtual Center Server or we are going
 # to install a new Virtual Center Instance. 
 # Case 1 : If we are going to migrate the Virtual Center instance the Object-ID of the Datastores keep it. 
 
 $DDS_PGroup = ($PG.ListProtectedDatastores()).Moref
 
 # Case 2 : If we are going to install a new Virtual Center instance the Object-ID of the Datastores, not it 
 # will be the sames, then we will need to get the names of Datastores and saves it.
 
 $DDS_PGroup = (Get-Datastore -Id ($PG.ListProtectedDatastores().MoRef)).Name

 # Get the state of Protection Group (Shadowing or Ready)

 $State_PGroup = ($PG.GetPeer()).State
 
 ###############################################################################################################
 
 Write-Host "Exporting the PG: $Name_PGroup" -ForegroundColor Yellow

 # We are going to include the information in a string array list.
 
 $Array_PG = $Name_PGroup + ',' + $Type_PGroup + ',' + $DDS_PGroup + ',' + $State_PGroup
 $Protection_Group_List += $Array_PG

}
# Export the content of Array List in a csv file
$Protection_Group_List | Out-File -FilePath "$ScriptDir\export_pg_$EXPORT_VCENTER.csv"
Write-Host "Protection Groups exported to file with name export_pg_$EXPORT_VCENTER.csv" -ForegroundColor Magenta

# *************** DISCONNECT POST-EXPORT ********************************************************************

# Disconnect SRM Server

Write-Host "Disconnect SRM Server" -fo Red
Disconnect-SrmServer -Server $SRMSERVER -Confirm:$false

# Disconnect Virtual Center Server

Write-Host "Disconnect Virtual Center : $EXPORT_VCENTER" -fo Red
Disconnect-VIServer -Server $EXPORT_VCENTER -Confirm:$false
Write-Host "Disconnect Virtual Center : $EXPORT_VCENTER" -fo Red
Disconnect-VIServer -Server $EXPORT_VCENTER2 -Confirm:$false

I also include the script to export Recovery Plans configuration

</pre>
<pre>############################################################################################################################# www.cloudvm.es #############################################
#############################################################################################
######                                                                                #######
###### Script Name : export_config_SRM_RP.ps1                                         #######
###### Version : 1.0                                                                  #######
###### Author: Mario Gómez (CloudVM)                                                  #######
###### Twitter : @mariogg85                                                           #######
###### Mail : mariogomezgallego85@gmail.com                                           #######
###### Objective: Make a Export of Recovery Plans configuration in our SRM Server     #######
###### Example: export_config_SRM_PG.ps1                                              #######
######                                                                                #######
#############################################################################################
#############################################################################################

# START SCRIPT

# Functions

# Save the path of our script. In this path we save the csv file with the exported configuration.
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path

# Credentials with permissions in Virtual Center and SRM Server.
 
$USER = 'cloudvm'
$PASS = 'script'

# Connection Info

$EXPORT_VCENTER = 'FQDN_vCenter_Activo'
$EXPORT_VCENTER2 = 'FQDN_vCenter_Pasivo'
$SRMSERVER = 'FQDN_SRM_Activo'

# Vars declaration

$Recovery_Plan_List = @()
$Recovery_Plan_List += 'Name' + "," + 'ProtectionGroups'+ "," + 'State'

# *************** CONNECTION PRE-EXPORT ********************************************************************

# Connection to Primary and Secondary Site.

Write-Host "Connect Virtual Center : $EXPORT_VCENTER ..." -fo Green
Connect-VIServer -Server $EXPORT_VCENTER -User $USER -Password $PASS -WarningAction 0 | Out-Null
Write-Host "Connect Virtual Center : $EXPORT_VCENTER2 ..." -fo Green
Connect-VIServer -Server $EXPORT_VCENTER2 -User $USER -Password $PASS -WarningAction 0 | Out-Null

# SRM Server Connection

Write-Host "Connect SRM Server..." -fo Green
$Srm = Connect-SrmServer -Server $EXPORT_VCENTER -User $USER -Password $PASS -WarningAction 0

# Load the SRM API

$SrmApi = $Srm.ExtensionData

# Get a list of Recovery Plans

$List_RP = $SrmApi.Recovery.ListPlans()

# Run the List of Recovery Plans, and for each RP we are going to export the information necessary.

foreach ($RP in $List_RP)
{

 # Get the Recovery Plan name

 $Name_RP = ($RP.GetInfo()).Name
 

 # Get the list of Protection Groups included in the Recovery Plan
 
 $PGroup = $RP.GetInfo().ProtectionGroups.MoRef

 # Get the Recovery Plan state.
 # Protecting - Source
 # Ready - Target

 $State_RP = ($RP.GetInfo()).State
 
 # Write a output with the name of recovery plan exported
 
 Write-Host "Exportando el Recovery Plan: $Name_RP" -ForegroundColor Yellow

 # We add a new line in the Array List.

 $List_RP = $Name_RP + ',' + $PGroup + ',' + $State_RP
 $Recovery_Plan_List += $List_RP

}
# Make a export of the information in a csv file
$Recovery_Plan_List | Out-File -FilePath "$ScriptDir\export_rp_$EXPORT_VCENTER.csv"
Write-Host "Recovery Plans exported to file with name export_rp_$EXPORT_VCENTER.csv" -ForegroundColor Magenta

# *************** DESCONEXIÓN POST-EXPORT *******************************

# Desconexión SRM Server

Write-Host "Disconnect SRM Server" -fo Red
Disconnect-SrmServer -Server $SRMSERVER -Confirm:$false

# Desconexión Virtual Center Server

Write-Host "Disconnect Virtual Center : $EXPORT_VCENTER" -fo Red
Disconnect-VIServer -Server $EXPORT_VCENTER -Confirm:$false
Write-Host "Disconnect Virtual Center : $EXPORT_VCENTER" -fo Red
Disconnect-VIServer -Server $EXPORT_VCENTER2 -Confirm:$false

I hope this has been useful;).

Now the most important thing would be missing, the scripts to import the configuration of the Protection Groups and Recovery Plan. If you want to get the scripts to import the configuration you will have to make a donation of 60 € to the blog. Remember that this script is difficult to implement and has taken a long time, so I think it deserves a contribution. To do this, click on the following button and remember to leave the email to send you the scripts that are fully documented. Thank you very much 😉

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *