Sunday, October 14, 2018

Backup running VirtualBox machine (with only a tiny interupt)!

There is a lot to be said about backups. I won't even try to cover all bases. I'll just show you what I'm using, that works for me. Yes.

In a nutshel this is what happens
  • some sanity checks and destination creation.
  • copy xml-config for chosen VM.
  • create snapshot for chosen VM so that original vdi-file is released.
    • will pause running VM for 1-2s. There is a --live switch for the snapshot command but I have not tested this.
  • copy original vdi-file to backup destination.
  • remove snapshot thus "merging" the changes back into the running vdi.
  • ???
  • profit!

Input is name of VM-machine and index of backup.
Output is a backup of your machine ... who'da thunk it.

The usage of rsync is mostly cause of access to --progress but this could be substituted for simple "cp" or similar.

Update 1: Now using --live switch for the snapshot command. Without it one guest with USB attached kept getting Aborted when snapshot was taken. With --live it's working again.
Update 2: The --live switch was not the issue :(. Apparently snapshots does not work with anything lower than the USB 3.0 controller. This controller does however lose the attached devices when you snapshot the guest instead. Bah. Workaround is a detach and re-attach of the device to the affected guest. In my case this is not a problem but if you are attaching a disk drive or something that the guest is using constantly this might lead to bad stuff. Take care.
Update 3: So the UUID changes with every boot and every physical reattach of the device, how very practical. Well, let's fix that.

That's it. It works for me, ymmw. :)