2

I'm using Oracle Virtualbox from commandline to manage my VMs. I'm talking a daily snapshot of them in a cronjob. But after all I just want to keep the 7 newest snapshots.

Is there a way I can do this in a shell script? After running my snapshot script it should look for the snapshots older than 7 days (should actually only be 1) and merge/delete them.

This is how my cron script looks like:

NOW=`date +"%m-%d-%Y-%T"`
SNAPSHOT_NAME="snapshot_$NOW"
SNAPSHOT_DESCRIPTION="Snapshot taken on $NOW"
VBoxManage snapshot vm take "$SNAPSHOT_NAME" --description "$SNAPSHOT_DESCRIPTION"

2 Answers 2

3

I would remove the time-stamp from the name and append this.

7DAYS_AGO=`date -d "7 days ago" +"%m-%d-%Y"
vboxmanage snapshot vm delete snapshot_$7DAYS_AGO
1
  • Should indeed work! Good idea!
    – jayv
    Apr 13, 2011 at 8:43
0

A posible solution with my script

https://github.com/nktrabajo/bashbackups

Regards

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .