Data Protection

Best way to script ONTAP CLI commands -- to change Protection Policy

JCampbell_DOI
286 Views

I am changing the Protection Policy from 'MirrorAllSnapshots'  to  'MirrorAndVault' for 200+ volumes.  I am using System Manager, so it is a slow process.

 

I would much rather use ONTAP CLI with some scripting like SSH, Ansible, REST API, or the older NMSDK.  Please let me know if there's an easy scripting method to accomplish this or other repetitive tasks.  An example would be great.

 Thanks again for your assistance. 

 

DOI BSEE TIMS Infrastructure Team

US Department of The Interior

1 ACCEPTED SOLUTION

donny_lang
251 Views

Using the PowerShell Toolkit (PSTK): 

 

1. Install NetApp.ONTAP module from PowerShell Gallery
2. Import module into your PowerShell session
3. Connect to destination cluster

Connect-NcController <destination cluster>

 

If you can easily enumerate the SnapMirror relationships (all within a single SVM for example, or all matching a specific naming scheme), you could gather them with Get-NcSnapMirror and then pipe that to Set-NcSnapmirror to change the policy as desired. More complicated ForEach-Object loops may be needed based on how the SnapMirror relationships are laid out. For example:

 

Get-NcSnapmirror -DestinationVserver <SVM name> | ForEach-Object { Set-NcSnapmirror -Destination $_.DestinationLocation -Policy MirrorAllSnapshots }

 

If you prefer Ansible, I'd use the netapp.ontap.na_ontap_snapmirror module. You would likely want to loop through a variable that contains a list of the volumes that you want to set policies for, perhaps collecting the information dynamically using the netapp.ontap.na_ontap_info module.

 

Honestly I'd probably just use the PSTK for this one though since so few lines of code would be required (unless you want to manage the SnapMirror relationships themselves with Ansible, which could be a value-add). 

View solution in original post

1 REPLY 1

donny_lang
252 Views

Using the PowerShell Toolkit (PSTK): 

 

1. Install NetApp.ONTAP module from PowerShell Gallery
2. Import module into your PowerShell session
3. Connect to destination cluster

Connect-NcController <destination cluster>

 

If you can easily enumerate the SnapMirror relationships (all within a single SVM for example, or all matching a specific naming scheme), you could gather them with Get-NcSnapMirror and then pipe that to Set-NcSnapmirror to change the policy as desired. More complicated ForEach-Object loops may be needed based on how the SnapMirror relationships are laid out. For example:

 

Get-NcSnapmirror -DestinationVserver <SVM name> | ForEach-Object { Set-NcSnapmirror -Destination $_.DestinationLocation -Policy MirrorAllSnapshots }

 

If you prefer Ansible, I'd use the netapp.ontap.na_ontap_snapmirror module. You would likely want to loop through a variable that contains a list of the volumes that you want to set policies for, perhaps collecting the information dynamically using the netapp.ontap.na_ontap_info module.

 

Honestly I'd probably just use the PSTK for this one though since so few lines of code would be required (unless you want to manage the SnapMirror relationships themselves with Ansible, which could be a value-add). 

Public