Microsoft Virtualization Discussions

snapdrive snapshot retention

JSHACHER11

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

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

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

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

cracked it:

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

View solution in original post

bsti

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

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public