#!/bin/bash # # Script to delete all snapshots # if [ "$UID" -eq 0 ] then echo "This script should NOT be run as root." exit 1 fi # if [ $# -ne 1 ]; then echo "Delete all snapshots" echo "Usage for $0 : VM Name required as argument." exit 1 fi # # Virtual Machine Name VB_VM_NAME=$1 # VB_VM_NO_SNAP_MSG="This machine does not have any snapshots" VB_VM_NO_SNAP=`VBoxManage snapshot "${VB_VM_NAME}" list|grep -c "$VB_VM_NO_SNAP_MSG"` if [ $VB_VM_NO_SNAP -eq 1 ]; then echo "VM $VB_VM_NAME does not have any snapshots." echo "Exiting ..." exit 1 fi # # List Snapshots echo "List of snapshots for '${VB_VM_NAME}' - All of them will be deleted! " VBoxManage snapshot "${VB_VM_NAME}" list echo read -p "Press [Enter] key to continue or [Ctrl-C] to break ..." # VM_RUNNING=`VBoxManage showvminfo ${VB_VM_NAME}|\ grep State|grep -c "running"` if [ $VM_RUNNING -eq 1 ]; then echo " VM $VB_VM_NAME is running ... Although snapshots can be deleted on a running vm it will take quite a while longer! Please power-down VM or save state to continue (or) Edit this script and comment out the exit! Exiting ... " exit 1 fi # VB_VM_SNAPSHOTS=`VBoxManage snapshot "${VB_VM_NAME}" list \ --machinereadable|grep ^SnapshotUUID|cut -d"\"" -f2` # for SNAPSHOT in $( echo $VB_VM_SNAPSHOTS ); do echo "Deleting snapshot: $SNAPSHOT ..." VBoxManage snapshot "${VB_VM_NAME}" delete $SNAPSHOT done # echo "Done!" exit