Created
April 12, 2013 16:46
-
-
Save vorce/5373385 to your computer and use it in GitHub Desktop.
SHahara. Shell script sandbox for VirtualBox. Basically just a wrapper for VBoxManage snapshot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# SHahara | |
# Inspired by: https://github.com/jedi4ever/sahara | |
# | |
# Sandbox for virtualbox for shell scripts | |
# Wrapper for VBoxManage and snapshots | |
SH_TEST_SNAPSHOT=sh_test_snapshot | |
VBOX=VBoxManage | |
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 | |
fi | |
} | |
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