1

I have an ubuntu 10.04 server running my VMs on kvm/qemu. I've been manually pausing my VMs (using virt-manager gui) and then copying the /var/lib/libvirt folder to an external usb drive at /mnt/usbexterno This obviously is far from ideal. I need a solution to run a backup everynight.

I thougt about using a cron job with a script to pause the VMs and copy the files to the drive. I've read on a forum that I could use virsh to save the VM state to a file, but I dont think thats what I need, since I want a full backup of everything in case the server goes boom!

So, short version. I need something to run a daily backup of my VMs to an external usb drive, the VMs can be paused during the night. Theres no GUI available on the server.

Any suggestions ?

1
  • It would be a plus if the solution could erase older backups when the usb disk gets full or has no space to run the backup.
    – Fernando
    Dec 19, 2011 at 13:44

4 Answers 4

1

If your VM is named "FooVM", then you can create a snapshot using:

VBoxManage snapshot FooVM take FooVM_Snapshot1

Via command line you can configure where to store the snapshots:

VBoxManage configvm FooVM --snapshotfolder /media/foostick/foofolder

However, take care that the UBS hard drive is available all the time.

You can automate the backups using cron jobs. And there is no need to poweroff the VMs.

4
  • 1
    older backups could as well be deleted automatically: howtogeek.com/howto/ubuntu/…
    – Michael K
    Dec 19, 2011 at 14:35
  • 2
    But he is not running Virtualbox
    – Panther
    Dec 19, 2011 at 16:45
  • I think I saw some similar functions while reading about virsh, I will test it and lets see :)
    – Fernando
    Dec 20, 2011 at 19:42
  • oops :-D sorry - but maybe it helps someone else
    – Michael K
    Jan 3, 2012 at 8:19
1

Took me a while to get back to this, sorry to everyone that gave me tips. Here's the solution I ended up with.

Since I still didnt really grasp the snapshot/restore snapshot concept (yes I am kinda thick headed), I made a script to delete old files, starting from the link that Michael K provided, then proceeded to making a folder with todays date on the usb drive, pausing all active VMs (absolutely no need for 100% uptime here, company runs 9am-6pm), and copying all of /var/lib/libvirt in there, and then resume VMs and be happy.

Here is the script.

#!/bin/bash

find /mnt/usbexterno/backup* -maxdepth 0 -type d -mtime +15 -exec rm -rf {} \;

virsh list | sed '1,2d' | cut -d' ' -f3>/tmp/vmlist

VMLIST=$(cat /tmp/vmlist)
set -- $VMLIST
for i in $VMLIST
do
    /usr/bin/virsh suspend $1
shift
done

mkdir /mnt/usbexterno/`date +backup-%Y-%m-%d`
cp -Rv /var/lib/libvirt /mnt/usbexterno/`date +backup-%Y-%m-%d`

set -- $VMLIST
for i in $VMLIST
do
    /usr/bin/virsh resume $1
shift
done
rm /tmp/vmlist

If anybody has any tips on how I could improve this please be my guest :D

1

I would consider compressing the VM before sending it off but this is exactly what I have been doing.

Oh, you might want to consider saving the xml file too (/etc/libvert/qemu/).

0

I would tend to agree, although your backup strategy is working, it may not be the best.

IMO there is not much that is necessarily unique to a Virtual Machine and there are several backup strategies available to you.

See Ubuntu Server Guide - Backups

The backup strategy varies depending on what servers you are running. In general, on a server, I back up data (such as /var/www and databases), any configuration files I manually edit (I keep a copy of the original file and the edited file in /root ), and a list of all installed packages (you can restore from a list of packages if needed).

As you can guess from some of my posts, I am a fan of rsync ;)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .