NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

Microsoft Virtualization Discussions

snapdrive snapshot retention

JSHACHER11
9,737 Views

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

Thanks

1 ACCEPTED SOLUTION

JSHACHER11
9,737 Views

cracked it:

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

View solution in original post

4 REPLIES 4

bsti
9,737 Views

Try something like this:

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

  begin
  {}


  process
  {
    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

JSHACHER11
9,737 Views

Thank you

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

http://blogs.technet.com/b/heyscriptingguy/archive/2007/10/31/hey-scripting-guy-how-can-i-use-windows-powershell-to-delete-all-the-files-in-a-folder-o...

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

Cheers

JSHACHER11
9,738 Views

cracked it:

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

bsti
9,737 Views

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

Public