I would like to have backup feature without the guest knowing about it. It should be no downtime and the backup should be able to be done on a guest running a busy mysql database or similar. I have come to a conclution that this may only be possible with lvm, but maybe its possible with kvm/qemu also.
Lets say I want to make a backup of a database running inside a guest. I don't want the guest to provide me with functionality about making this backup. All should be done with the help of virtualization and the fact that a guest hard drive is located on a server.
qemu monitor has a snapshot feature that can make this happen. Turning on the snapshot functonality and the base image will be static and it will be possible to make a exact copy of this image. I can then do whatever I want with this snapshot. Like mounting it in another guest to make backups.
So, how can I make a snapshot of a guest precise in time without the guest knowing about it?
If you have the storage for your virtual machine(s) as a logical volume within a volume group you can take a snapshot of the logical volume.
The 'real' logical volume continues to behave as normal.
The snapshot is a a snapshot of the volume as the time it was created. It uses minimal space within the volume group, as it only needs to store the blocks whose contents differ between the logical volume and the snapshot.
The only problem I'm having here is how to copy the snapshot to another disk without doing unneeded writes,
http://finalcog.com/synchronise-block-devices
Of course, as you're not telling the hosted VM's database that it is being backed up, snapshotting the VM's filesystem (s) will give you VM filesystem(s) in the same state as if the VM had been stopped uncleanly.
This may be 'good enough' for many circumstances. (Certainly better to need an fsck, rather than to have lost your data.)
rsync --sparse --inplace
There is a solution to rsync/sparse files: http://www.finalcog.com/rsync-vm-sparse-inplace-kvm-vmware
It's not really possible what you're asking. For example, MySQL keeps lots of stuff in memory, causing the files on disk to be inconsistent.
LVM snapshots work good for normal filesystems, however, they don't work for databases, which are basically filesystems in filesystems, each component not knowing about each other.
To back up a database you should set a cron job (or whatever
you use to schedule actions) to dump the database (most databases support this without stopping the server) before you schedule a backup.
For example, mysql provides mysqldump for this purpose.
Then you can backup the guest, host or whatever you can come up with, any way you wish ... lvm sounds feasible
Do you need to stop the MySQL for this kind of backup ? What if you can't stop the MySQL because it is alive and people keep writing into it 24/7 ?
Do NOT turn on the snapshot functionality. As the manual says, nothing will be written to disk. You can force it but this is not what you want. Use a qcow2 disk. With this, qemu supports taking snapshots with the snapshot command in the monitor. It will store disk state as well as ram state in the snapshot. So you have got an absolutely consistent snapshot. Recover -> exact point in time recovery!
Post new comment