What I want to be able to do is to pause a Virtualbox vm, back it up and then restart it. I want to create a cron script to do this.

I believe that these are the commands I need, but I don't know how to back up (the middle bit):

VBoxManage controlvm "Windows Server" savestate
while [ `VBoxManage list runningvms | grep "Windows Server" | wc -l` = "1" ]
    sleep 2

#here is the bit I don't know to do... 
#I need to somehow create a backup of the vm here... I'm sure its not
#that difficult, but I don't know where to start or whether what I
#would come up with would be the best way

#restart using start-stop-daemon... dunno why! This is in my init.d script
#and was the only way it worked (as far as I could work it! haha)
start-stop-daemon --background --chuid user --make-pidfile --pidfile "$PIDFILE" --start --exec /usr/bin/VBoxHeadless -- --startvm "Windows Server"

If anyone could give me a few lines of code which will backup my vm to a specific place that would be good. I've fallen at the first hurdle tbh, I'm then going to try and tar the backup and rsync it to my NAS. We shall see how easy that bit is after this! :p haha

Thanks for your help guys.

closed as too localized by Eric Carvalho, Jorge Castro, Seth, user83046, rɑːdʒɑ Apr 26 '13 at 12:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Backing up a running (paused) machine is not advisable. I usually shutdown my VM (acpi-shutdown), then I create a snapshot from the Logical Volume it runs from, then I restart the VM, then backup from the LV-snapshot. Especially when you want a file tree backup, many files will be corrupted if you do not shut down first. – jippie Apr 18 '12 at 17:14
  • I did think so. I have used "savestate" in my example code... will that be ok? Is creating a snapshot the best way to do a backup? – Thomas Clayson Apr 19 '12 at 7:14
  • I use a two way strategy. I make daily file backups, allowing me to recover single files when I corrupt them or to recover file permissions, that sort of thing. Then before doing patching or if I'm afraid the VM might not boot correctly after me fiddling with it, I make an image of the disk. LV in my case, .vdi files in yours. The catch with pausing a VM is that I don't know which files on your howst OS are important and which not. – jippie Apr 19 '12 at 7:18
  • Do you make the daily file backups within the VM itself? – Thomas Clayson Apr 19 '12 at 7:22
  • My host OS runs dirvish.org but backuppc.sourceforge.net would do equally well and is a bit easier to operate (according to my colleague). I configured dirvish to make a backup over the network. So dirvish logs on to the VM, then pulls the files that changed and those differences are stored on the host OS disk. BTW: I use a different physical disk for backups to make sure that 1 failing disk doesn't wipe out my backups too. – jippie Apr 19 '12 at 7:26