Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"`
VBoxManage snapshot vm take "$SNAPSHOT_NAME" --description "$SNAPSHOT_DESCRIPTION"
share|improve this question
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
share|improve this answer
Should indeed work! Good idea! – jverdeyen Apr 13 '11 at 8:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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