Virtualbox snapshot manager
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"
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