Cloud Articles and Resources

Data ONTAP PowerShell Toolkit - Working with SnapMirror Part II (Take two, they're small)

In Working with SnapMirror Part I, we took a whirlwind tour of the Data ONTAP PowerShell Toolkit SnapMirror cmdlets.  In Part II, I will show how to work with multiple transfers in your scripts.  Without further ado, let’s get started.

From the basic setup (run the Automated Provisioning script on a pair of simulators) the first thing you need to do is enable SnapMirror.  You only need to do that once on each filer.  You can do that with the Enable-NaSnapMirror cmdlet:

Enable-nasnapmirror –Controller $SIM1

Enable-Nasnapmirror –Controller $SIM2

Next, you need to set SnapMirror.access to allow the two controllers to initiate transfers.  You only need to make changes to snapmirror.access when you want to add relationships for additional controllers.  Since I only have two simulators, and they reside in Hyper-V on my laptop, I’ll go ahead and set that to “ALL”:

Set-naoption –controller $SIM1 snapmirror.access ALL

Set-naoption –controller $SIM2 snapmirror.access ALL

Now we’re ready.  I want to restrict volumes 1-4, initialize the SnapMirror transfers, and then report the status:

Connect-nacontroller SIM2; get-navol | ? {$_.ContainingAggregate -eq "aggr1"} | set-navol -Restricted | foreach-object{$src="SIM1:"+$_.Name; $Dest="SIM2:"+$_.Name; Invoke-NaSnapMirrorInitialize -Source $Src -Destination $Dest};get-nasnapmirror

First, I connect to the destination; SIM2.  In the Data ONTAP PowerShell Toolkit, connections are transitive; once I mention one, I’ll keep working with the same controller until I mention another.  Also, as a programmatic shortcut, you can put multiple separate commands on the same line without piping them by separating them with a semicolon.

After I connect, it’s time to form my pipeline.  I get the volume collection from SIM2 and pass it to a where filter so that I am only working with the volumes in aggr1.  I then restrict the destination volumes.  I pipe the resulting object collection through a foreach-object statement, forming the source and destination parameters for the Invoke-nasnapmirrorinitialize and then invoking the command for each volume in my collection.  Last but not least, I do a get-nasnapmirror to get the status of the initializations.

Happy Scripting



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.