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"
link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

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
link|improve this answer
Should indeed work! Good idea! – jverdeyen Apr 13 '11 at 8:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.