Skip to content

Instantly share code, notes, and snippets.

Created Apr 12, 2013
What would you like to do?
SHahara. Shell script sandbox for VirtualBox. Basically just a wrapper for VBoxManage snapshot.
# SHahara
# Inspired by:
# Sandbox for virtualbox for shell scripts
# Wrapper for VBoxManage and snapshots
removeSnapshot() {
local VM_NAME="$1"
VM_KEY=`VBoxManage list vms | grep $VM_NAME | awk '{print $2}'`
$VBOX snapshot $VM_KEY delete "$SH_TEST_SNAPSHOT" &> /dev/null
takeSnapshot() {
local VM_NAME="$1"
VM_KEY=`VBoxManage list vms | grep $VM_NAME | awk '{print $2}'`
local ALREADY_ON=`VBoxManage showvminfo --machinereadable $VM_KEY | grep SnapshotName | grep $SH_TEST_SNAPSHOT`
if [ -z "$ALREADY_ON" ]; then
$VBOX snapshot $VM_KEY take "$SH_TEST_SNAPSHOT"
$VBOX controlvm $VM_KEY resume
restoreSnapshot() {
$VBOX controlvm $VM_KEY poweroff
$VBOX snapshot $VM_KEY restore "$SH_TEST_SNAPSHOT"
$VBOX startvm --type headless $VM_KEY
commitSnapshot() {
local VM_NAME="$1"
$VBOX controlvm $VM_KEY poweroff
$VBOX snapshot $VM_KEY delete "$SH_TEST_SNAPSHOT"
takeSnapshot $VM_NAME && $VBOX startvm --type headless $VM_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment