Friday, June 11, 2010

Linux VirtualBox VM Live Backup

I was looking for a way to backup a running VirtualBox Win2K3 VM on an Ubuntu 10.04 box.

First solution:
  1. enable ACPI shutdown in the VM, see here and here for how to do this with Win 2K3
  2. shutdown the the VM: VBoxManage controlvm acpipowerbutton
  3. copy the VM's .vdi file somewhere. To change the UUID: VBoxManage internalcommands setvdiuuid disk2.vdi
  4. start the VMagain

This gives a copy of the VM but you have to down it and it has to stay down for as long as the copy takes.

Using R1Soft's Hot Copy for Linux, you can take a snapshot of a Linux filesystem.
And it's free!!! But not open source :-(

Steps (assuming root user - otherwise, sudo is your friend):
  1. Install Hot Copy - cribbed from here.
  2. Download R1Soft's key for their apt repository:
  3. Add the key:
    apt-key add r1soft.asc
  4. Edit /etc/apt/sources.list and add the following at the end:
    # R1Soft HotCopy
    deb stable main
  5. apt-get update
  6. apt-get install r1soft-hotcopy
  7. Now you need to install their binary-only kernel driver - without giving you the source! Don't know how they do this exactly but it looks like we upload kernel headers from our machine, they compile the module and send it back to us. Weird.
    hcp-setup --get-module
    (this can take a while depending on your upload)
  8. Take a snapshot of a filesystem:
    hcp -m /mnt/t1 -c /dev/sda1 /dev/md1
  9. This creates a snapshot of /dev/md1 in /mnt/t1. The snapshot uses 'copy-on-write' which, as I understand it, works like this: Whenever there is a change to the source/original block, Hot Copy makes a backup of the original and keeps it in the snapshot. By default, these block backups are created on the source/original device but you can specify a different device if you wish - here I use /dev/sda1. Useful if there is not much space or if you don't want to be writing to your precious SSD :-)
  10. Copy your .vdi file somewhere. I'm using rsync for no particular reason...:
    rsync -a src-dir/ dest-dir/
  11. Remove the Hot Copy session:
    hcp -r /dev/hcp1
    How did I know it was /dev/hcp1? With hcp -l. Guess it's OK as long as there is not more than one Hot Copy at a time.....

The copied .vdi file worked fine for me but, YMMV.

Good luck!

No comments:

Post a Comment