Script to enable SnapMirror transfers with vFilers and SRM

by Frequent Contributor on ‎2013-03-28 11:24 AM

Currently there is a limitation with vFilers that is a SnapMirror snapshot on the destination side is FlexCloned this will break or suspend SnapMirror transfers until the FlexClone is destroyed. In a VMware SRM environment this means that is a user launches an extended DR test failover, he may violate the expect RPO since no SnapMirror transfers will occur during the DR test. This is only a limitation with NetApp vFilers! Physical Controller to Physical controller or Vserver to Vserver SnapMirror can update during a SRM failover test.

This Powershell script takes the source and destination SnapMirrored Volumes as well as source and destination controllers and creates matching FlexClones on the source volumes. This locks the FlexClone required snapshot on the source side and allows SnapMirror Transfers to continue. Then it detects when the Destination FlexClones have been deleted and cleans up the source side FlexClones as well.

I reused a bit of code in order to encrypt the required password in to a local file so that the whole script can be placed in VMware SRM and run with no intervention.

$SM_Source_Controller = "192.168.1.150"

$SM_Dest_Controller = "192.168.2.254"

$SM_Source_Vols = ("vfiler_source","vfiler_source2")

$SM_Dest_Vols = ("vfiler_dest","vfiler_dest2")

$Adminname = "root"

#STORED CREDENTIAL CODE

$CredsFile = "C:\NetappSRMconnect-nacontroller -PowershellCreds.txt"

$FileExists = Test-Path $CredsFile

if  ($FileExists -eq $false) {

     Write-Host 'Credential file not found. Run Credential creator Script' -ForegroundColor Red

     Exit}

          else{

                    Write-Host 'Using your stored credential file' -ForegroundColor Green

  $password = get-content $CredsFile | convertto-securestring

  $cred = new-object -typename           System.Management.Automation.PSCredential -argumentlist $Adminname, $password}

# 1 - Connect

Connect-NaController $SM_Dest_Controller -Credential $cred

# 2 - Get the snapshot name

$SMSnaps = Foreach ($Vol in $SM_Dest_Vols) { get-nasnapshot $Vol | Where-Object {$_.dependency -and $_.Busy}}

# 3 - Create the FlexClone

Connect-NaController $SM_Source_Controller -Credential $cred

$Int = 0

Foreach ($Vol in $SM_Source_Vols) {

          $SM_Temp = $SM_Source_Vols | Select-Object -index $Int

          $SM_Temp = "$($SM_Temp)SRMTemp"

          New-NaVolClone -ParentVolume $Vol  -CloneVolume $SM_Temp -ParentSnapshot ($SMSnaps | Select-Object -index $Int)  -SpaceReserve none

          $Int++}

# 4 - Simple time loop that will wait until the FlexClone on the SnapMirror target is destroyed This script loops every 15 sec until snapshot status does not show busy

$Int = 0

Foreach ($Snap in $SMSnaps) {

          Connect-NaController $SM_Dest_Controller -Credential $cred

          $SnapCheck = $Snap

          while ($SnapCheck.busy){

  $SnapCheck = Get-NaSnapshot -TargetName ($SM_Dest_Vols | Select-Object -index $Int) -SnapName $SnapCheck.name

                    start-sleep -seconds 15}

# 5 - This deletes the FlexClone on the Source Controller.

          Connect-NaController $SM_Source_Controller -Credential $cred

          $SM_Temp = $SM_Source_Vols | Select-Object -index $Int

          $SM_Temp = "$($SM_Temp)SRMTemp"

          Set-NaVol  $SM_Temp -Offline | Remove-NaVol -Confirm:$False

          $Int++}

This the borrowed and modified code to create the encrypted password file;

#This commandlet is based on code from Michael Lubinski and will create an encrypted credential file for NetApp controllers

#STORED CREDENTIAL CODE

$AdminName = Read-Host "Enter your NetApp username"

$CredsFile = "C:\NetAppSRM-PowershellCreds.txt"

$FileExists = Test-Path $CredsFile

if  ($FileExists -eq $false) {

    Write-Host 'Credential file not found. Enter your password:' -ForegroundColor Red

    Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File $CredsFile}

else

    {Write-Host 'Using your stored credential file' -ForegroundColor Green}

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.