Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Script to delete all but a specified number of snapshots on all vols/aggrs
2010-08-08
04:05 AM
5,513 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I tried to write a PowerShell script to connect to a filer, and delete all (from the oldest first) but a configurable number of snapshots on all the volumes and aggregates on the filer. I think it was probably too much of a task for my very first powershell scripting attempt. I tried debugging the script using powershell_ise but I am definitely missing a lot on how to use the DataOntap module/calls. Can anyone help?
- keepsnaps=5
- connect to filer
- retrieve all vols/aggr
- for every vol/aggr, delete all snapshots from the oldest leaving the most recent $keepsnaps number of snapshots from all vols and all aggregates
Thanks.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
In the meantime, I have implemented the script in bash.
I am uploading it (delete_all_but_n_snapshots.sh) in case anyone is interested.
I am still interested in a powershell script to do the same.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Something to get you started.
$max = 5
foreach ($vol in Get-navol)
{
$Snapshots = Get-NaSnapshot -Name $vol.name
$remove = $Snapshots.Count - $Max
if ($remove -ge 1)
{
$Snapshots |
Sort-Object AccessTime |
Select-Object -First $remove |
Remove-NaSnapshot
}
}
~Glenn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need a script to delete snapshots that are more than 30 days old. Our backup software is supposed to do it but it fails every now and then leaving old snapshots on our filers. As I know absolutely nothing about scripting I would really appreciate your help in coming up with a script to meet our needs.
Thanks in advance for your help.
Karon