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/rsyncd.pid cat <<EOF > /tmp/rsyncd.conf port = 2999 pid file = /tmp/rsyncd.pid [backup] path = /tmp/backup use chroot = false read only = false EOF 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@192.168.122.1:2999/backup archive:true EOF # Kill the rsync daemon. kill `cat /tmp/rsyncd.pid`
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.
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.
Richard, what would the syntax be for a Windows guest? We’re trying to copy a few files continuously, as they are modified, from a live Windows guest using guestfs_rsync_out API. We have:
guestfs_rsync_out(g, “c:\\HostShared” “rsync://root@10.0.1.90:2999/HostShared”, -1)
If we combine this with your rsync daemon approach, are we on the right track? Thanks.
The second parameter should be something like
/HostShared
. See: http://libguestfs.org/guestfs.3.html#special-considerations-for-windows-guestsRich-
Thanks very much. We’ve tried combinations similar to:
guestfs_rsync_out(g, “/HostShared”, “rsync://root@10.0.1.90:2999/ShareModule/ -av”, -1)
surroundng it with APIs as in the recipe examples, for example replacing libguestfs_cat(), with no luck. Typically in the rsync daemon log we see something like:
receiving file list
sent 17 bytes received 24 bytes total size 0
but no data is transferred. We are successful using rsync from the Linux command line, and we can get libguestfs APIs like guestfs_cat() to work fine. But we’ve had zero luck with rsync_out over the last week. Unfortunately there are no actual API examples online, no “recipes” on the libguestfs.org site, etc. Do you know where there are some actual libguestfs_rsync_out() working examples?
Thanks.
-Jeff
This isn’t a place to get support. Please enable debugging as described in the FAQ and post the full debug output to an email message sent to the mailing list.
Rich-
Additional note… to match your example, the syntax we used is:
guestfs_rsync_out(g, “/HostShared”, “rsync://root@10.0.1.90:2999/backup/ -av”, -1)
where HostShared refers to a folder C:\HostShared on the Win7 guest.
-Jeff
Ok saw your reply, have subscribed to the mailing list and will post there. Thanks.