Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
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
Solved! See The Solution
cracked it:
Get-NaVol vol_test | Get-NaSnapshot | where-object {$_.Created -lt (Get-Date).AddDays(-5)} | remove-nasnapshot
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
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
Cheers
cracked it:
Get-NaVol vol_test | Get-NaSnapshot | where-object {$_.Created -lt (Get-Date).AddDays(-5)} | remove-nasnapshot
Glad you figured it out. Looks remarkably similar to what I posted above