VMware Cloud Community
Bruticusmaximus
Enthusiast
Enthusiast

Automated snapshot deletion after x number of days

Is there a way to automatically delete a scheduled snapshot after x number of days.  There's a VM that has issues and, we're constantly restoring it from backup.  I can schedule a daily snapshot of the VM but, I have to also remember to delete it every single day. Sure, i could do a power CLI script and schedule it to run with some scheduler but, I'd still have to check it every once in a while to make sure it's still running.

I've put in a feature request to add "Delete snapshot after x days" when you schedule a snapshot.

Way back, maybe 10 years ago when Vmware owned Shavlik for patching, you could apply Windows updates through Vmware Update Manager.  It worked great.  You could schedule it to take a snapshot of the VM before applying patches then, automatically delete the snapshot x number of days later.  We usually did it 2 days later. So I know the hooks are in there somewhere to do this.  Am I just missing something?

Reply
0 Kudos
3 Replies
scott28tt
VMware Employee
VMware Employee

Why not do a daily backup rather than take a daily snapshot that you then have to remember to delete?

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
Bruticusmaximus
Enthusiast
Enthusiast

This VM is 2TB. It would be down all day trying to restore it from backup if we needed to.

Reply
0 Kudos
dafyre2010
Contributor
Contributor

I have a powershell script that I've cobbled together from various sources.

https://gitlab.com/dafyre/powershell-utils/-/blob/master/VMware/snapshotCleanup.ps1

It will clean up snapshots based on a daily/weekly time phrase if the snapshot description matches "Daily Snapshot" or "Weekly Snapshot"

or you can pass in a parameter of what you want to match on.

This does require the VMware PowerCLI to work.  You must also be connected to the vCenter Instance(s) that you want to manage.  If you use the -daily or -weekly switches, create a file daily-list.txt or weekly-list.txt and enter one VM per line.

The script won't actually do anything if you don't run it with the -live parameter.

It's not completely automated, but it's better than having to sit and baby sit it.  If there's any questions, let me know.