Backing up/restoring ONTAP SMB shares with PowerShell

486042-636355594290390040-16x9

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:

https://github.com/DatacenterDudes/cDOT-CIFS-share-backup-restore

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:

https://github.com/DatacenterDudes/cDOT-CIFS-share-backup-restore

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 4.0.1.1
  • 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

ps-toolkit

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:

backup-shares

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!

delete-shares

Now, run your restore.

restore-shares-acl

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.

Questions?

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!

12 thoughts on “Backing up/restoring ONTAP SMB shares with PowerShell

  1. Pingback: How to make a Metro-HA from DR? – Why do you like WAFLs?

  2. I’m using Netapp FAS2220 on Version 8.2.3P5 7-MODE and the version of Powershell module is 4.6.0

    Here is the error :

    PS C:\Users\Adminsave\desktop> .\backupSharesAcls.ps1 -server 192.168.1.120 -user lilian -password xxxxxxxxx -vserver vs2 -share * -shareFile C:\share.xml -aclFile C:\acl.xml -spit less
    Connect-NcController : Not a clustered Data ONTAP controller
    Au caractère C:\Users\Adminsave\desktop\backupSharesAcls.ps1:36 : 10
    + $nctlr = Connect-NcController $server -Credential $cred
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidResult : (192.168.1.120:NcController) [Connect-NcController], InvalidOperationException
    + FullyQualifiedErrorId : Not a clustered Data ONTAP controller,DataONTAP.C.PowerShell.SDK.ConnectNcController

    Get-NcCifsShare : Value in $global:CurrentNcController is not of type NetApp.Ontapi.Filer.C.NcController
    Au caractère C:\Users\Adminsave\desktop\backupSharesAcls.ps1:41 : 5
    + Get-NcCifsShare -Controller $nctlr -VserverContext $vserver -Share $share | …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument : (:) [Get-NcCifsShare], ArgumentException
    + FullyQualifiedErrorId : ControllerNotSpecified,DataONTAP.C.PowerShell.SDK.Cmdlets.Cifs.GetNcCifsShare

    Get-NcCifsShareAcl : Value in $global:CurrentNcController is not of type NetApp.Ontapi.Filer.C.NcController
    Au caractère C:\Users\Adminsave\desktop\backupSharesAcls.ps1:49 : 5
    + Get-NcCifsShareAcl -Controller $nctlr -VserverContext $vserver -Share $share …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument : (:) [Get-NcCifsShareAcl], ArgumentException
    + FullyQualifiedErrorId : ControllerNotSpecified,DataONTAP.C.PowerShell.SDK.Cmdlets.Cifs.GetNcCifsShareAcl

    ************************SHARES START*****************************************
    Import-Clixml : Le fichier ‘C:\share.xml’ est introuvable.
    Au caractère C:\Users\Adminsave\desktop\backupSharesAcls.ps1:64 : 9
    + Import-Clixml $shareFile
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (:) [Import-Clixml], FileNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportClixmlCommand

    ************************SHARES END*****************************************

    ************************ACLS START*****************************************
    Import-Clixml : Le fichier ‘C:\acl.xml’ est introuvable.
    Au caractère C:\Users\Adminsave\desktop\backupSharesAcls.ps1:75 : 9
    + Import-Clixml $aclFile
    + ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (:) [Import-Clixml], FileNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportClixmlCommand

    ************************ACLS END*****************************************

    Like

  3. So before you spend any time helping me can you tell me if your guide allows me to extract shares and rights on my netapp to a windows server?

    Like

    • This script won’t work for you. Set up a cifs share to vol0 on your filer and copy out the cifs_shares file. That gets loaded on boot of the controller.

      If you’re looking to migrate shares to cDOT, the 7-mode transition tool will do that for you.

      Like

  4. Hi Justin, thanks for sharing !
    Can I use these scripts in the perspective of a migration with a source svm hosted on a metrocluster and a new HA pair ?
    Chris

    Like

Leave a comment