Microsoft Virtualization Discussions

snapdrive snapshot retention

Hi guys,

we schedule snapdrive snapshots with a ps1 script:


$date=(Get-Date -Format dd-MM-yyyy_HH-mm)

sdcli snap create -s $date -D e


I'm after a script that will delete any snapdrive snapshots older than 5 days

note: we don't use snapmanager or DFM



Re: snapdrive snapshot retention

Try something like this:

function Remove-Snapshots()
    [Parameter(Mandatory=$true,Valuefrompipeline=$true)] $Volume,
    [string] $SnapName = "*",
    [int] $DaysOld = 5


    foreach ( $vol in $Volume )
      $volObj = $vol
      if ( $vol -is [string] )
        #  If user provided a volume name as a string
        $volObl = Get-NaVol -Name $vol
      $vol | Get-NaSnapshot | Where-Object -FilterScript { $_.Name -ilike $SnapName -and $_.Name -inotmatch "\.\d+?$" -and (New-TimeSpan -Start $_.AccesstimeDt).totalDays -gt $DaysOld } | Remove-NaSnapshot

Import-Module dataontap

Connect-NaController controller1 -rpc

Get-NaVol | Remove-Snapshots
"vol1" | Remove-Snapshots

Re: snapdrive snapshot retention

Thank you

I saw this article - can this be implemented in my case?

let's say that I call the snapshots yyyyMMddHHmm - this will give me something like 201307050935 and then somehow check the difference between the current date and the snapshot name and if greater than 5 days, remove the snapshot


Re: snapdrive snapshot retention

cracked it:

Get-NaVol  vol_test | Get-NaSnapshot | where-object {$_.Created -lt (Get-Date).AddDays(-5)} | remove-nasnapshot

View solution in original post

Re: snapdrive snapshot retention

Glad you figured it out.  Looks remarkably similar to what I posted above 

Cloud Volumes ONTAP
Review Banner
All Community Forums