Using rsync with libguestfs

Since libguestfs 1.20 it has been possible to use rsync to upload or download files to a disk image incrementally. This is one way to do backups, but note that it won’t work on live guests unless you take a snapshot.

rsync involves using a network connection into or out of the appliance, and is therefore a lot more involved to set up. The script below shows one way to do this, by running an rsync daemon on the host, and letting the libguestfs appliance connect to it.

The script runs rsync inside the appliance, copying /home from the attached disk image out to /tmp/backup on the host. If the operation is repeated, then only incrementally changed files will be copied out. (To incrementally delete files on the target, add the deletedest:true flag).

Note you will need to open port 2999 on your host’s firewall for this to work.

#!/bin/bash -

set -x

# The target directory.
mkdir -p /tmp/backup

# Create the daemon.
rm -f /tmp/

cat <<EOF > /tmp/rsyncd.conf
port = 2999
pid file = /tmp/

  path = /tmp/backup
  use chroot = false
  read only = false

rsync --daemon --config=/tmp/rsyncd.conf

# Run guestfish and attach to the guest.
guestfish --ro --network -a /dev/fedora/f19rawhidex32 -i <<EOF
trace on
rsync-out /home rsync://rjones@ archive:true

# Kill the rsync daemon.
kill `cat /tmp/`
About these ads


Filed under Uncategorized

2 responses to “Using rsync with libguestfs

  1. This is pretty cool, however I think it makes a lot more sense to have the host rsync in, to keep the logical flow of security… Eg: more secure things log into less secure things, and not vice versa.

    • rich

      Unfortunately the crappy qemu user networking that we have to use doesn’t allow incoming connections. To allow those would mean we have to run the appliance as root (not very sensible) or have some “fun” interactions with libvirt.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s