2

I'm currently using VMware 5.1 and looking for a method to keep snapshots that users create from becoming too old. Is there any tool inside of VMware that allows you to manage snapshots (or possibly a method to script this)?

Ideally I'd like to delete any snapshots that become over a month old automatically.

Valrok
  • 330
  • 3
  • 11

2 Answers2

4

You can do this easily with powercli, as there is a 'remove-shapshot' cmdlet:

$oneMonthAgo = (Get-Date).AddDays(-30)
Get-VM | Foreach-Object {
Get-Snapshot -VM $_ | Foreach-Object {
if($_.Created -lt $oneMonthAgo) {
Remove-Snapshot $_ -Confirm -WhatIf
}}}

I put the -Confirm and -WhatIf in there because Remove-Snapshot could potentially do a lot of damage -- you want to make sure it's targeting the right snapshots before taking those parameters out.

1.618
  • 669
  • 1
  • 4
  • 17
  • 1
    Shouldn't instead of -lt it be greater than in your code snippet? Aside from that however this is exactly what I'm looking for! – Valrok Oct 11 '13 at 15:13
  • 1
    Logically you would think that, but it compares the dates numerically, so earlier = lower value. – 1.618 Oct 11 '13 at 16:18
1
$oneMonthAgo = (Get-Date).AddDays(-30)
Get-VM | Foreach-Object {
Get-Snapshot -VM $_ | Foreach-Object {
if($_.Created -lt $oneMonthAgo) {
Remove-Snapshot $_ -Confirm:$false
}}}

I guess the above script will do and yes add it to task scheduler which will still ease of the work. Recommend to delete the snapshots that are 3 days old.

chicks
  • 3,639
  • 10
  • 26
  • 36