ONTAP Discussions

What is the easiest way to update the snapshot policy for hundreds of volumes?

Northman
708 Views

I am thinking to look for a powercli command that does this and then prepare a long list of the command for each volume, using Excel and notepad. And then copy the commands in 10 at the time? 

 

also need to delete hundreds of old snapshots in those volumes. How can I do this? Is there a time switch I can use with a powershell command that lets me delete all snapshots older than 4 weeks for instance?

6 REPLIES 6

TMACMD
693 Views

If there’s lots of similarity, use an extended query

 

 vol modify {-vserver xxx -snapshot-policy old_policy} -snapshot-policy new_policy

 

 find all volumes in svm xxx with snapshot policy old_policy and replace it with new_policy

ok, do you know how to delete lots of snapshots according to age?

Hey Northman,

 

You will need to compare the snapshot creation date to the current date to calculate the snapshot age. Here's a script that will calculate the snapshot age based on a retention variable in days and display the commands that you "would" run if you wanted to delete the snapshots. I'd advise you thoroughly check the results "before" you delete any snapshots. Note that this explicitly filters out any snapshots used for SnapMirror baseline transfers.

 

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The number of Days to retain the snapshots")]
   [Int]$RetentionDays,
   [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to ONTAP")]
   [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
Try{
   Connect-NcController -Name $Cluster -Credential $Credential | Out-Null
}Catch{
   Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
   Exit -1
}
#'------------------------------------------------------------------------------
#'Enumerate all Snapshots.
#'------------------------------------------------------------------------------
Try{
   $snaps = Get-NcSnapshot -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed Enumerating Snapshots on Cluster ""$Cluster"". Error " + $_.Exception.Message)
   Exit -1
}
#'------------------------------------------------------------------------------
#'Filter out any snapshots with dependancies for SnapMirror etc.
#'------------------------------------------------------------------------------
$snapshots   = $snaps | Where-Object {$_.Dependency -eq $Null}
$currentDate = Get-Date
$retention   = $($RetentionDays * (60 * 60 * 24))
#'------------------------------------------------------------------------------
#'Display the command to delete the snapshot.
#'------------------------------------------------------------------------------
ForEach($snapshot In $snapshots){
   $created = Get-Date -Date $snapshot.Created
   $age     = New-TimeSpan -Start $created -End $currentDate
   If($age.TotalSeconds -ge $retention -And $snapshot.Name -notlike "snapmirror.*"){
      Write-Host $("snapshot delete -vserver " + $snapshot.Vserver + " -volume " + $snapshot.Volume + " -snapshot " + $snapshot.Name)
   }
}
#'------------------------------------------------------------------------------

 

 

Usage:

 

 

PS C:\Scripts\PowerShell\Projects\DeleteAgedSnapshots> $Credentials = Get-Credential
PS C:\Scripts\PowerShell\Projects\DeleteAgedSnapshots> .\DeleteAgedSnapshots.ps1 -Cluster cluster1.testlab.local -RetentionDays 7 -Credential $Credentials

 

 

Hope that gives you some ideas. It wouldn't be much effort to add the code to delete the snapshots

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

something like

::>volume snapshot delete {-vserver * - volume * -create-time <10d} -force true
this command will delete ALL snapshots within the cluster older that 10 days without asking for confirmation
Please be careful with that
basically inside the brackets is
volume snapshot show -vserver * -volume * -create-time<10d

So before deleting  anything try first to create a correct command to show needed age snapshots for specific vserver\volume
Also don't use -force true option in deleting - then for every snapshot to be deleted cli will require you to hit yes
In a scenario where you are not sure better to not use -force
In a scenario you are planning to delete thousands of snapshots it might be painful to hit yes thousands of times

explanation of how extended queries work
https://docs.netapp.com/us-en/ontap/system-admin/methods-extended-queries-concept.html

Also very nice article - it is quite old but still usefull!!!

 

https://whyistheinternetbroken.wordpress.com/2015/02/16/techbecome-a-clustered-data-ontap-cli-ninja/

 


Ho do you run an extended query for this? I thought an extended query was of the form: volume show -fields volume, size -query 'size >= 100GB && size <= 1TB'

TMACMD
77 Views
Public