A while back, I posted a SMB share backup and restore PowerShell script written by one of our SMB developers. Later, Scott Harney added some scripts for NFS exports. You can find those here:
That was back in the ONTAP 8.3.x timeframe. They’ve worked pretty well for the most part, but since then, we’re up to ONTAP 9.3 and I’ve occasionally gotten feedback that the scripts throw errors sometimes.
While the idea of an open script repository is to have other people send updates of scripts and make it a living, breathing and evolving entity, that’s not how this script has ended up. Instead, it’s gotten old and crusty and in need of an update. The inspiration was this reddit thread:
So, I’ve done that. You can find the updated versions of the script for ONTAP 9.x at the same place as before:
However, other than for testing purposes, it may not have been necessary to do anything. I actually ran the original restore script without changing anything of note (changed some comments) and it ran fine. The errors most people see either have to do with the version of the NetApp PowerShell toolkit, a syntax error in their copy/paste or their version of PowerShell. Make sure they’re all up to date, else you’ll run into errors. I used:
- Windows 2012R2
- ONTAP 9.4 (yes, I have access to early releases!)
- PowerShell 184.108.40.206
- Latest NetApp PowerShell toolkit (4.5.1 for me)
When should I use these scripts?
These were created as a way to fill the gap that SVM-DR now fills. Basically, before SVM-DR existed, there was no way to backup and restore CIFS configurations. Even with SVM-DR, these scripts offer some nice granular functionality to backup and restore specific configuration areas and can be modified to include other things like CIFS options, SAN configuration, etc.
As for how to run them…
Backing up your shares
1) Download and install the latest PowerShell toolkit from https://mysupport.netapp.com/tools/info/ECMLP2310788I.html?productID=61926
2) Import the DataONTAP module with “Import-Module DataONTAP”
(be sure that the PowerShell window is closed and re-opened after you install the toolkit; otherwise, Windows won’t find the new module to import)
3) Back up the desired shares as per the usage comments in the script. (see below)
# Usage: # Run as: .\backupSharesAcls.ps1 -server <mgmt_ip> -user <mgmt_user> -password <mgmt_user_password> -vserver <vserver name> -share <share name or * for all> -shareFile <xml file to store shares> -aclFile <xml file to store acls> -spit <none,less,more depending on info to print> # # Example # 1. If you want to save only a single share on vserver vs2. # Run as: .\backupSharesAcls.ps1 -server 10.53.33.59 -user admin -password netapp1! -vserver vs2 -share test2 -shareFile C:\share.xml -aclFile C:\acl.xml -spit more # # 2. If you want to save all the shares on vserver vs2. # Run as: .\backupSharesAcls.ps1 -server 10.53.33.59 -user admin -password netapp1! -vserver vs2 -share * -shareFile C:\share.xml -aclFile C:\acl.xml -spit less # # 3. If you want to save only shares that start with "test" and share1 on vserver vs2. # Run as: .\backupSharesAcls.ps1 -server 10.53.33.59 -user admin -password netapp1! -vserver vs2 -share "test* | share1" -shareFile C:\share.xml -aclFile C:\acl.xml -spit more # # 4. If you want to save shares and ACLs into .csv format for examination. # Run as: .\backupSharesAcls.ps1 -server 10.53.33.59 -user admin -password netapp1! -vserver vs2 -share * -shareFile C:\shares.csv -aclFile C:\acl.csv -csv true -spit more
If you use “-spit more” you’ll get verbose output:
4) Review the shares/ACLs via the XML files.
That’s it for backup. Pretty straightforward. However, our backups are only as good as our restores…
Restoring the shares using the script
I don’t recommend testing this script the first time on a production system. I’d suggest creating a test SVM, or even leveraging SVM-DR to replicate the SVM to a target location.
In my lab, however… who cares! Let’s blow it all away!
Now, run your restore.
That’s it! Happy backing up/restoring!
Tips for running the script
- Before running the script, copy and paste it into the “PowerShell ISE” to verify that the syntax is correct. From there, save the script to the local client. Syntax errors can cause problems with the script’s success.
- Use the latest available NetApp PowerShell Toolkit and ensure the PowerShell version on your client matches what is in the release notes for the toolkit.
- Test the script on a dummy SVM before running in production.
- Ensure the DataONTAP module has been imported; if import fails after installing the toolkit, close the PowerShell window and re-open it.
If you have any questions or comments, leave them here. Also, if you customize these at all, please do share with the community! Add them to the Github repository or create your own repo!