Snapshots are one of the core features of ONTAP, and something that many, many people rely on every day to protect their data from accidental (or malicious…) deletion and corruption. The NetApp PowerShell Toolkit can help us to manage the configuration of snapshot policies, the application of those policies to volumes, and creating/deleting/reverting snapshots too.
This post will cover:
- Snapshots
- Management
- Reporting
- Snap Reserve
- Snapshot Policies
- Snapshot Autodelete
- Recovering Data
Snapshots
Managing Snapshots
- Show snaps for a volume
1Get-NcVol $volName | Get-NcSnapshot - Create a snapshot
1Get-NcVol $volName | New-NcSnapshot $snapName - Delete a snapshot
123456789# delete a specific snapshotGet-NcVol $volName | Get-NcSnapshot $snapName | Remove-NcSnapshot# delete all snapshots for a volumeGet-NcVol $volName | Get-NcSnapshot | Remove-NcSnapshot# delete all snapshots, for all volumes, which match a name pattern$pattern = "weekly"Get-NcSnapshot | ?{ $_.Name -match $pattern } | Remove-NcSnapshot
Snapshot Reporting
- Show volumes with no snapshot protection
I originally created this snippet as a response to this NetApp Communities question. It returns non-root data volumes (not data protection volumes) which have the volume optionnosnap
enabled or have a snapshot policy ofnone
.123456789101112131415Get-NcVol | ?{# get non-root volumes$_.VolumeStateAttributes.IsNodeRoot -eq $false `-and# which are rw (this will exclude SnapMirror, etc.)$_.VolumeIdAttributes.Type -eq "rw" `-and(# with "nosnap" turned on(($_ | Get-NcVolOption -Hashtable).value.nosnap -eq "on") `-or# or with snapshot policy set to none($_.VolumeSnapshotAttributes.SnapshotPolicy -eq "none"))} - Show the oldest snapshot for a volume
12Get-NcVol $volumeName| Get-NcSnapshot | `Sort-Object -Property Created | Select-Object -First 1
- Show snapshots more than X days old
1234567$daysAgo = 14Get-NcSnapshot | Where-Object {# multiply the days by -1 to go backward. if the value was# positive it would be in the future$_.Created -lt ((Get-Date).AddDays($daysAgo * -1))}
- Show the cumulative snapshot usage for one (or more) volumes
1234567# single volume(Get-NcVol $volumeName).VolumeSpaceAttributes.SizeUsedBySnapshots | `ConvertTo-FormattedNumber# total snapshot space used for all volumes for a particular SVM((Get-NcVserver $svmName | Get-NcVol).VolumeSpaceAttributes.SizeUsedBySnapshots | `Measure-Object -Sum).Sum | ConvertTo-FormattedNumber
- Show volumes with a dependent/busy snapshot
1Get-NcSnapshot | ?{ $_.Dependency -ne $null }
Snap Reserve
Snap reserve is the amount of space in the volume which has been set aside for snapshot data…i.e. the data which is changed. The size of the snapshot is “contained” in this capacity, and not deducted from the available space in the volume.
- Show snap reserve for a volume
1Get-NcVol $volName | Get-NcSnapshotReserve
- Set the snap reserve for a volume
1Get-NcVol $volName | Set-NcSnapshotReserve -Percentage 10
- Show volumes with no snap reserve
12345# using a query against volumesGet-NcVol -Query @{ VolumeSpaceAttributes = @{ SnapshotReserveSize = 0 } }# or, using the snap reserve cmdletGet-NcSnapshotReserve | ?{ $_.Percentage -eq 0 }
- Show volumes with snap reserve > X percent
12345678# the percentage threshold$percent = 5# using a queryGet-NcVol -Query @{ VolumeSpaceAttributes = @{ PercentageSnapshotReserve = ">$($percent)" } }# using the snap reserve cmdletGet-NcSnapshotReserve | ?{ $_.Percentage -gt $percent } - Show volumes with snapshots exceeding the snap reserve
123Get-NcVol | Where-Object {$_.VolumeSpaceAttributes.SizeUsedBySnapshots -gt $_.VolumeSpaceAttributes.SnapshotReserveSize}
Managing Snapshot Policies
The snapshot policy is what determines when the ONTAP system will automatically create a snapshot and how long to retain it.
- Show snapshot policy for all volumes
1Get-NcVol | Select-Object @{N="Name"; E={ $_.Name }},@{N="Snapshot Policy";E={ $_.VolumeSnapshotAttributes.SnapshotPolicy }}
- Show volumes with a particular policy
1Get-NcVol -Query @{VolumeSnapshotAttributes=@{SnapshotPolicy=$policyName}}
- Create a policy with a custom schedule
12345678910111213141516171819202122232425262728293031323334353637## create custom cron schedule(s) for the policy## snapshot every two hoursAdd-NcJobCronSchedule -Name c2hour -Hour 0,2,4,6,8,10,12,14,16,18,20,22# snapshot every day at midnightAdd-NcJobCronSchedule -Name cDaily -Day -1 -hour 0# snapshot every Sunday at midnightAdd-NcJobCronSchedule -Name cWeekly -DayOfWeek 6# snapshot every month, on the first, at midnightAdd-NcJobCronSchedule -Name cMonthly -Month -1 -Day 1# snapshot every year, January first at midnightAdd-NcJobCronSchedule -Name cYearly -Month 0 -Day 1 -Hour 0 -Minute 0## create the snapshot policy, add the first schedule, keeping twelve# bi-hourly snapshots (one day's worth)#New-NcSnapshotPolicy -Name Gold -Schedule c2hour -Count 12## add the remaining schedules to complete the policy## keep seven daily snapshotsAdd-NcSnapshotPolicySchedule -Name Gold -Schedule cDaily -Count 7# keep four weekly snapshotsAdd-NcSnapshotPolicySchedule -Name Gold -Schedule cWeekly -Count 4# keep one yearly snapshotAdd-NcSnapshotPolicySchedule -Name Gold -Schedule cYearly -Count 1
- Change the snapshot policy for a volume
1234567891011$query = @{Name = $volName}$attributes = @{VolumeSnapshotAttributes = @{SnapshotPolicy = $policyName}}Update-NcVol -Query $query -Attributes $attributes
Managing Snapshot AutoDelete
Snapshot AutoDelete is a protection mechanism, meant to prevent your volume from running out of space from oversized snapshots. There are a number of settings associated with AutoDelete. The names used for the ClusterShell and from the PowerShell toolkit are slightly different, I’ve noted the differences below.
- CLI = Enabled, PSTK = state –
true/false
(CLI) oron/off
(PSTK), this indicates whether AutoDelete is enabled for the volume. - Commitment – How aggressive should AutoDelete be when removing snapshots?
try
= only delete snapshots which are not “in use” or locked by FlexClone, SnapMirror, etc.disrupt
= will allow AutoDelete to remove data protection (SnapMirror, etc.) snapshots.destroy
= will allow AutoDelete to remove snapshots used by FlexClone. - Trigger – What causes the AutoDelete action to kick off?
volume
= when volume capacity crosses the (configurable) threshold. snap_reserve = when the snap reserve is nearly full.space_reserve
= when the reserved space in the volume is nearly full. - Target Free Space – AutoDelete will stop deleting snapshots when free space reaches this percentage.
- Delete Order –
newest_first
oroldest_first
, the order which snapshots will be deleted. Generally speaking, oldest_first will result in the most space reclaimed. - Defer Delete –
scheduled
= delete snapshots taken by the snapshot policy last.user_created
= delete user created snapshots last.prefix
= delete snapshots with the specified prefix last.none
= don’t defer any, just delete in the specified delete order. - CLI = Defer Delete Prefix, PSTK = prefix – The prefix used when the defer delete value is
prefix
. - Destroy List – This list of services which can be destroyed if the backing snapshot is removed. This is the corollary for the commitment value of
destroy
The default isnone
, which is the safest option. Refer to the documentation for specifics.
With an understanding of the options, let’s look at how to query and modify AutoDelete settings.
- Show the AutoDelete policy for a volume
1Get-NcVol $volName | Get-NcSnapshotAutodelete - Show all volumes with autodelete enabled/disabled
123# setting IsAutodeleteEnabled to $true will show volumes with autodelete enabled,# setting to $false will show volumes with autodelete disabledGet-NcVol -Query @{ VolumeSnapshotAutodeleteAttributes = @{ IsAutodeleteEnabled = $true } } - Enable/disable for a volume
12345# enableGet-NcVol $volName | Set-NcSnapshotAutodelete -Key state -value on# disableGet-NcVol $volName | Set-NcSnapshotAutodelete -Key state -value off - Set multiple options for a volume
12345678910111213141516$options = @{'commitment' = 'try';'defer_delete' = 'scheduled';'delete_order' = 'oldest_first';'state' = 'on''target_free_space' = 20;'trigger' = 'volume';}Get-NcVserver $svmName | Get-NcVol | %{$volume = $_$options.GetEnumerator() | %{$volume | Set-NcSnapshotAutodelete -Key $_.Key -Value $_.Value}}
Recovering Data
Revert a snapshot
1 2 3 |
# note that if you revert a node's root volume # it will cause the node to reboot Get-NcVol $volumeName | Restore-NcSnapshotVolume -SnapName $snapName |
Restore a file using FlexClone
I originally posted a version of this to the NetApp Communities site. This will create a FlexClone of the file from a snapshot into the current file system. Note that this is not the same thing as a single file snap restore, which uses the Restore-NcSnapshotFile
cmdlet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
$svmName = "mySVM" $volumeName = "myFavoriteDatastore" $sourceSnap = "weekly.0" $files = @("vc.vmx", "vc.vmdk", "vc.vmdk-flat") $sourceFolder = "/vc/" $destinationFolder = "/vc_restored/" $files | %{ $splat = @{ # the name of the volume which holds the file(s) 'Volume' = $volumeName; # the path to the file in the volume 'SourcePath' = "$($sourceFolder)$($_)"; # the path for the restored file 'DestinationPath' = "$($destinationFolder)$($_)"; # if false, the clone will be thin. if omitted, the # policy will be inherited from the original 'SpaceReserved' = $false; # the source snapshot 'Snapshot' = $sourceSnap; # this command must be targeted at a SVM 'VserverContext' = $svmName; } New-NcClone @splat } |
I have multiple cloned volumes on a windows clustered environment. How can i give them a unique volume id? I am using Set-NcLunSignature to change the LUN Id, but the volume id remains the same.
is it possible to generate a script to report shelf temperature for a given sensor?
Hello Gerard,
Yes! I would recommend checking out this post, which explains environment monitoring.
Hope that helps!
Andrew
Thank you so much for your Netapp PoSH tools blog…so helpful, thanks so much!