TMBTC Post

Create Online KVM Backups


Create Online KVM Backups

2013-04-08
Running eCommerce sites, downtime is considered a bad deal... at the same time, not having backups is even worse. Here is a simple script that I've put together to execute an online backup (not a snapshot) of a Virtual Machine managed by KVM without having to shut down the VM. Create a new file.
$vi snapshot_backup.sh
And copy and paste the following code.
#!/bin/bash
debug=1

function backup_snapshot {
  date=$1
  filename=$2
  if [ `qemu-img info $filename.qcow2 | grep  --count "file format: qcow2"` -eq 1 ] then
    echo "Backing up $filename"
    # create the snapshot
    if [ $debug -eq 1 ] then
      echo "Creating snapshot"
    fi
    qemu-img snapshot -c $date $filename.qcow2
    #copy the snapshot out
    if [ $debug -eq 1 ] then
      echo "Converting snapshot to standalone qcow2 file"
    fi
    qemu-img convert -c -f qcow2 -O qcow2 $filename.qcow2 $filename-$date.qcow2 
    #delete the old snapshot
    if [ $debug -eq 1 ] then
      echo "Deleting snapshot"
    fi
    qemu-img snapshot -d $date $filename.qcow2
  else
    echo "Snapshot backups only support qcow2 files"
 fi
}
date=`date +%d%m%Y`
filename=`echo $1 | sed s/.qcow2//`
backup_snapshot $date $filename
Exit vi, saving the script. Now make your script executable.
$chmod +x snapshot_backup.sh
To run the script pass it the name of your VM.
$./snapshot_backup.sh /path/to/your/vm/hostname.qcow2
From my experiance, the performance impact to the VM is fairly minimal. Hope this helps.

You might also like

Squeaky Steel Case Jersey Chair... Fixed!

2014-09-11

Our offices recently underwent a major renovation. Part of the change was the arrival of new Steel Case Jersey chairs for our work areas. The chairs themselves are adjustable in several areas and quite comfortable. However, by the time the newness wore off the squeaking started. The slightest movement such as leaning back or forward caused an ear piercing squeak to emit from the underside of the chair. As time progressed, you could hear squeaking throughout the entire floor. At times it was quite comical; however, most of the time it simply annoying. The fix: To stop the squeak find


Read More...

Building a Word Clock

2014-09-05

I was recently asked if I could build a Word Clock. Of course, not wanting to back down from a challenge (and a bit of research) I said "yes". One of the objectives of this build, aside from producing a quality product for our client was to document the build and share with the community. After a bit work, I present to you, the Javelin Word Clock. Check out this video a co-worker put together. I think he did a great job. Javelin's Word Clock Want one? You too can build this same clock by following my Instructables


Read More...