-
-
Save donaldsteele/6bf6403a554ae8c2ac5c9cb7624059c4 to your computer and use it in GitHub Desktop.
Backup Running VirtualBox VMs
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 | |
BASEFOLDER=/home/vbox/backups | |
for VMNAME in $(VBoxManage list runningvms | cut -d ' ' -f1 | sed 's/"//g;') | |
do | |
echo "" | |
VBoxManage controlvm "$VMNAME" acpipowerbutton | |
echo "Waiting for VM "$VMNAME" to poweroff..." | |
until $(VBoxManage showvminfo --machinereadable "$VMNAME" | grep -q ^VMState=.poweroff.) | |
do | |
sleep 1 | |
done | |
echo "Exporting VM to $BASEFOLDER/$VMNAME-temp.ova..." | |
VBoxManage export "$VMNAME" -o "$BASEFOLDER/$VMNAME-temp.ova" --ovf20; | |
rm -rf "$BASEFOLDER/$VMNAME.ova" | |
mv "$BASEFOLDER/$VMNAME-temp.ova" "$BASEFOLDER/$VMNAME.ova" | |
echo "Restarting VirtualBox VM..." | |
VBoxManage startvm "$VMNAME" --type headless | |
echo "" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment