PowerShell Script for managing SnapVault backups, updates, archiving and restoring.

by on ‎2012-02-28 03:41 PM

We recently had to implement SnapVault in our environment without using Protection Manager (since we use JAMS Enterprise Scheduling tool). Requirements were simple:

- Keep 6 monthly snapshots on SnapVault Secondary

- Do not use Protection Manager

- Make sure consistent snapshots (created by SnapManager for SQL) were used for SnapVault backups

I put together PowerShell script which can perform these tasks and decided to share it in case anybody else needs help doing similar thing.

Steps 1-2: Create SnapVault relationship and monthly schedule.

Steps 3-4: Select the last SnapManager for SQL (consistent) snapshot and perform SnapVault update (screenshot below).
Steps 5-6: Time loop until SnapVault update completes before creating snapshot on Secondary. You can run this from scheduling tool (Windows Task Scheduler, etc.)

Step 7: SnapVault incremental restore to the original location. You can experiment doing baseline or restore to a different location.

############################################################################################
###

### PowerShell Script for managing SnapVault backups, updates, archiving and restoring.

###

### Script below requires installation of DataONTAP PowerShell Toolkit available for
### download at URL below. I used version 1.7. You will need PowerShell 2.0 installed on

### your workstation/server and DoT version 7.3+ on the filer to support all cmdlts.

###                                                                                   
### https://communities.netapp.com/community/products_and_solutions/microsoft/powershell
###                                                                                     

############################################################################################

# 1 - Creates SnapVault relationship on Secondary.
Connect-NaController SECONDARY_FILER
New-NaSnapvault /vol/snapvault_secondary/qtree PRIMARY_FILER /vol/snapvault_primary/qtree

# 2 - Create the SnapVault sv_monthly schedule on Secondary (snapvault_secondary volume).
#     This Schedule will keep 6 monthly snapshots in rotation and prune any older. Using dash '-' means no automatic snapshots will be created.
#     You can create another daily schedule to capture 1-2 daily snapshots in case there's a catastrophic failure on Primary (using same approach).
Connect-NaController SECONDARY_FILER
Set-NaSnapvaultSecSnapshotSchedule snapvault_secondary sv_monthly -AutoUpdate $false -RetentionCount 6 -DaysOfWeek "-" -HoursOfDay "0"

# 3 - Pulls the last SnapManager for SQL snapshot (using "sqlsnap" key word) from the snapvault_primary volume on the Primary.
Connect-NaController PRIMARY_FILER
$LastSnapshot = get-nasnapshot snapvault_primary | ? { $_.Name -imatch "sqlsnap" } | Sort-Object AccessTimeDT -Descending | Select-Object -first 1

# 4 - Initiates SnapVault transfer (update) from Secondary using last SnapManager for SQL snapshot.
Connect-NaController SECONDARY_FILER
Start-NaSnapVaultSecTransfer /vol/snapvault_secondary/qtree -PrimarySnapshot $LastSnapshot.Name

# 5 - Simple time loop that will wait until SV update on Secondary (snapvault_secondary volume) is done, before creating snapshot (Step 6).
#     This script loops every 5 seconds until SnapVault status shows “Idle”. Steps 5 & 6 should run once a month against Secondary.
Connect-NaController SECONDARY_FILER
$var = $null
while (!$var -or ($var.status -ine "idle"))
{
  $var = Get-NaSnapvaultSecStatus -Path "/vol/snapvault_secondary/qtree"
  start-sleep -seconds 5
}

# 6 - This archives (creates snapshot) on Secondary using ‘sv_monthly’ schedule.
Connect-NaController SECONDARY_FILER
Start-NaSnapvaultSecSnapshot -VolumeName snapvault_secondary -ScheduleName sv_monthly

# 7 - Incremental restore from the original location on Primary using specific (sv_monthly.0) snapshot from Secondary.
#     Executed against Primary. Make sure you detach databse/unmount LUN before invoking this step.
Connect-NaController PRIMARY_FILER
Start-NaSnapvaultpriRestoreTransfer /vol/snapvault_primary/qtree SECONDARY_FILER /vol/snapvault_secondary/qtree -Incremental -SecondarySnapshot sv_monthly.0

Comments
nicholaj Former NetApp Employee

Thanks This has saved me allot of time!

I'm happy to hear that Nick. I put out another script (How to replicate snapshots using Qtree SnapMirror and PowerShell?) based on the code above. It leverages Qtree SnapMirror to replicate volume snapshots between filers with different DoT version. I found myself in situation where I had to upgrade DoT on the source filer before I could upgrade destination. Running higher version of DoT on source breaks Volume SnapMirror.

Cool Ivan!

Henry

Frequent Contributor

Great Stuff!

Thanks,

Yaron

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.