How to make a live snapshot properly - sheepdog/sheepdog GitHub Wiki

What is the issue in taking snapshots?

If you write some data on your guest and take a snapshot right after, you might not have this data saved in the snapshot as you may expect. The reason is because data is cached in guest memory. What you probably want is:

  1. all cached data to be flushed before the snapshot is taken;
  2. hold any other write request

Mind that sheepdog has no control on the guest and it can't force it to sync its data to disk before taking the snapshot.

How to solve?

Manually: by running 'sync' command inside the guest to flush data and/or 'fsfreeze' to hold new write requests. This method is interactive so you can't script it.

Using qemu-ga: this is an agent that allow us to send some kind of requests from the host to the guest.

Requirements

The guest must be running qemu-ga.
It's possible to run it also on windows guests.
The host must use qemu 0.16 or higher.
Install socat on the host.

Procedure

Host side:

run qemu with these options:

-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0

Guest side

qemu-ga -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0 &

Host side

echo '{"execute":"guest-fsfreeze-freeze"}' | socat unix-connect:/tmp/qga.sock -
dog vdi snapshot yourvdi
echo '{"execute":"guest-fsfreeze-thaw"}' | socat unix-connect:/tmp/qga.sock -

You can check the status any time by

echo '{"execute":"guest-fsfreeze-status"}' | socat unix-connect:/tmp/qga.sock -

References

http://wiki.qemu.org/Features/Snapshots#Snapshot_command_flow
http://wiki.qemu.org/Features/QAPI/GuestAgent

⚠️ **GitHub.com Fallback** ⚠️