I depend a lot upon VirtualBox for my security-related research and testing. That being the case I make a lot of changes to my VirtualBox VM’s and losting a given state and not being able to rollback to last known good state would be very bad. Yes, you can take snapshots manually via the GUI or even by the means of the CLI. When you have over 20 VM’s that you manage this can be pain in the butt.
This is where scripting comes in, so I built some simple Bash scripts to automate this process and have it run hourly via Cron.
The first script simply outputs to STDOUT a list of all the VirtualBox VM’s in the system:
[bash]
vboxmanage list vms
[/bash]
Our complete guide to using facetime for laptop Apple’s advanced video conferencing software, whether you’re using iOS, an iPhone, an iPad
This will simply produce the name and registration number of each VM you have defined on the system.
Now to automate the snapshot process we simply craft something like:
[bash]
for i in `vmlist | awk ‘{print $1}’ | perl -pi.orig -e ‘s/\"//g’`
do
echo "Creating snapshot for $i"
vboxmanage snapshot $i take $i-`date +%Y%m%d%H%M%S`
done
[/bash]
This will create a snapshot for each VM with the snapshot name of each VM followed by a date/time stamp. Put this script in your crontab and your good to go.