Skip to content

Instantly share code, notes, and snippets.

@mkouhei
Created August 23, 2017 22:18
Show Gist options
  • Save mkouhei/19ee7e4a3db6838c2db159de619f4ea4 to your computer and use it in GitHub Desktop.
Save mkouhei/19ee7e4a3db6838c2db159de619f4ea4 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
vmname=$1
VBoxManage showvminfo $vmname | grep State: | grep -q 'powered off' || ( echo "VM: $vmname is not powered off." ; exit 1 )
VBoxManage snapshot $vmname take $(date +%Y%m%d-%H%M)
if [ $(VBoxManage snapshot $vmname list | wc -l) -lt 4 ]; then
exit 0
fi
VBoxManage snapshot $vmname delete $(VBoxManage snapshot $vmname list | head -1 | awk '{print $2}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment