Backup running vm
bakvbox.sh
#!/bin/bash # name: bakvbox.sh # backup to where _BAKPATH="/backup/vm-backup" # cmd to show running vm: # "vboxmanage list runningvms" _VMNAME="elastix-25" # Find Disk image location: # "vboxmanage showvminfo elastix-25 | grep vdi" _IMAGE="/home/bizamin/VirtualBox VMs/elastix-25/elastix-25.vdi" # Find configure file # vboxmanage showvminfo elastix-25 | grep '.vbox' _CONFIG="/home/bizamin/VirtualBox VMs/elastix-25/elastix-25.vbox" #### Code #### date cd $_BAKPATH echo "Saving state..." # pause 時是不能 clone 的 vboxmanage controlvm $_VMNAME savestate echo "backup the VM..." # bak config cp "$_CONFIG" ./ # export 係唔 work 的, 會有 error 1 #vboxmanage export $_VMNAME --output $_VMNAME-export.ova &> export.log # shrink happens automatically vboxmanage clonehd "$_IMAGE" $_BAKPATH/${_VMNAME}-export.vdi echo "Resuming previous state..." vboxmanage startvm $_VMNAME --type headless # show disk info vboxmanage showmediuminfo $_BAKPATH/${_VMNAME}-export.vdi date
==============
error 1
VBoxManage: error: The machine 'elastix-25' is already locked by a session (or being locked or unlocked) VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports VBoxManage: error: Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 589 of file VBoxManageMisc.cpp'