Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.