In this mini-howto, I will describe how to use LVM snapshot function together with virt-clone (included in python-virtinst) to create a full image(system) backup.
Scenario:
- Our xen guest called guestsrv1
- In /etc/xen/guestsrv1 config file: disk = [ "phy:/dev/VolGroup00/guestsrv1,xvda,w" ]
- To create a full backup of/dev/VolGroup00/guestsrv1 without shuting down guestsrv1
- Create a lvm snapshot for /dev/VolGroup00/guestsrv1, snapshot size depends on disk activities during the backup time span. In our example, snapshot size is 1Gb
[root@domU ~]# lvcreate -s -L 1G -n guestsrv-snapshot /dev/VolGroup00/guestsrv
Use lvdisplay to check your new snapshot volume. Eg,
ACTIVE Original '/dev/VolGroup00/guestsrv' [10.00 GB] inherit
ACTIVE Snapshot '/dev/VolGroup00/guestsrv-snapshot' [1.00 GB] inherit - Create a snapshot xen guest config in /etc/xen
[root@domU ~]# cd /etc/xen; sed 's/guestsrv/guestsrv-snapshot/g' guestsrv > guestsrv-snapshot - Create image with virt-clone by using guestsrv-snapshot volume
[root@domU ~]# virt-clone -o guestsrv-snapshot -n guestsrv-backup -f guestsrv-backup.img
Cloning from /dev/VolGroup00/guestsrv-snapshot to /root/guestsrv-backup.img
Cloning domain... 1% | | 174 MB 04:12 ETA - Previous step will create an image with a new xen guest config in /etc/xen/guestsrv-backup with disk pointed to file /root/guestsrv-backup.img. You can boot up or roll back your backup if the original guestsrv crash. Now remove the snapshot volymn:
[root@domU ~]# lvremove /dev/VolGroup00/guestsrv-snapshot
Remove /etc/xen/guestsrv-snapshot config file:
[root@domU ~]# rm /etc/xen/guestsrv-snapshot - Copy or move your /root/guestsrv-backup.img to somewhere safe!
Those steps are scriptable and do-able on today's cheap disk storage technology. Use binary diff such as cmp to create "binary-patch" between the images may "decrease" data-size for remote backup. On other hand, rsync is not a bad choice neither. Always test your recovery and crisis management. Otherwise are backups useless!
No comments:
Post a Comment