LINUXOR.SK ... open source notes ...

Xen 04 - domU - backup with LVM snapshots

category: learnz/xen · date: 2008-01-10 · source: old.linuxor.sk/VIRTUALIZATION/BASIC/BH_Debian4.0_XEN_BACKUP_domU.txt · theme: github

Xen on Debian 4 Learning · Previous: domU · Next: dom0 - the physical hardware

The Slovak original of this document: Xen 04 - domU - zálohovanie pomocou LVM snapshotov (slovensky).

asciiart
|=----------------------------------=[ XEN ]=------------------------------=|
+---------------------------------------------------------------------------+
|                                                                           |
|                               XEN - domU BACKUP                           |
|                                 Debian 4.0 Etch                           |
|                          Backing up virtual machines                      |
|                                                                           |
+---------------------------------------------------------------------------+
|=-------------------------------=[ BH 2007 ]=-----------------------------=|

Note: the virtual machine being backed up is "www.vhosts.example"

1. Backup/restore of virtual machines - LVM SNAPSHOTs

asciiart
        Requirements
        ------------
        - the domU must use LVM disks
        - enough room in the volume group to create the snapshot

        Installing the utility that administers multipath disk access
        -------------------------------------------------------------
        # apt-get install multipath-tools

        Description of the backup
        -------------------------
        - find which logical LVM partition the domU (www.vhosts.example) is on (1)
        - check that the logical partition can be reached (2)
        - create a snapshot named www.vhosts.example-snap from the logical partition 'www.vhosts.example-disk' (3)
        - find the devnode to mount (4)
        - check that the filesystem structure is sound (5)
        - mount the snapshot on /mnt/tmp (6)
        - move into /mnt/tmp and take the backup with "tar" (7)
        - unmount the snapshot (8)
        - release the devnodes that are no longer needed (9)
        - remove the snapshot (10)
        -----------------------------------------------------------------------------------------
        (1)# grep ^disk /etc/xen/www.vhosts.example.cfg
        (2)# lvs /dev/mail.client45.example/www.vhosts.example-disk
        (3)# lvcreate -s -L 2G -n www.vhosts.example-snap /dev/mail.client45.example/www.vhosts.example-disk
        (4)# kpartx -a /dev/mail.client45.example/www.vhosts.example-snap
        (5)# fsck /dev/mail.client45.example/www.vhosts.example-snap
        (6)# mount /dev/mail.client45.example/www.vhosts.example-snap /mnt/tmp
        (7)# cd /mnt/tmp && tar zcvpf /backup/www.vhosts.example.tgz ./
        (8)# umount /mnt/tmp
        (9)# kpartx -d /dev/mail.client45.example/www.vhosts.example-snap
        (10)# lvremove /dev/mail.client45.example/www.vhosts.example-snap

2. Backup/restore of virtual machines - LVM - cloning a logical partition, i.e. cloning a domU

asciiart
        Requirements
        ------------
        - the domU must use LVM disks
        - enough room in the volume group to create the snapshot
        - enough room for the cloned logical partition

        Installing the utility that administers multipath disk access
        -------------------------------------------------------------
        # apt-get install multipath-tools

        Description of the backup
        -------------------------
        - find which logical LVM partition the domU (www.vhosts.example) is on (1)
        - check that the logical partition can be reached (2)
        - create a snapshot named www.vhosts.example-snap from the logical partition 'www.vhosts.example-disk' (3)
        - find out how many LEs the original logical partition consists of [on this system LE=768](4)
        - create a new logical partition of the same size or larger, named "www.vhosts.example-disk-klon" (5)
        - make the copy [the clone] (6)
        - remove the snapshot (7)
        - find the devnodes of the partitions (8)
        - mount the clone on /mnt/tmp (9)
        - fix the network devices (10)
        - remove the devnodes (11)
        - make a copy of the virtual machine's configuration file (12)
        - modify the name, the mac address, the lvm name ... (13)
        - add the new ip address and hostname to /etc/hosts (14)
        - add the new ip address and mac address to /etc/dhcpd.conf (15)
        - start the newly created virtual machine [the clone] (16)
        -----------------------------------------------------------------------------------------
        (1)# grep ^disk /etc/xen/www.vhosts.example.cfg
        (2)# lvs /dev/mail.client45.example/www.vhosts.example-disk
        (3)# lvcreate -s -L 2G -n www.vhosts.example-snap /dev/mail.client45.example/www.vhosts.example-disk
        (4)# lvdisplay /dev/mail.client45.example/www.vhosts.example-disk
        (5)# lvcreate -l 768 -n www.vhosts.example-disk-klon mail.client45.example
        (6)# cat /dev/mail.client45.example/www.vhosts.example-snap >/dev/mail.client45.example/www.vhosts.example-disk-klon
        (7)# lvremove /dev/mail.client45.example/www.vhosts.example-snap
        (8)# kpartx -av /dev/mail.client45.example/www.vhosts.example-disk-klon
        (9)# mount /dev/mail.client45.example/www.vhosts.example-disk-klon /mnt/tmp
        (10)# for i in /mnt/tmp/etc/sysconfig/network/ifcfg-eth-id-aa*; do mv -v $i "`echo $i|sed -e 's,13,20,'`"; done
        (11)# kpartx -dv /dev/mail.client45.example/www.vhosts.example-disk-klon
        (12)# cp /etc/xen/www.vhosts.example.cfg /etc/xen/www.vhosts.example-klon.cfg
        (13)# nano /etc/xen/www.vhosts.example-klon.cfg
        (14)# nano /etc/hosts
        (15)# nano /etc/dhcpd.conf && rcdhcpd restart
        (16)# xm cr /etc/xen/www.vhosts.example-klon.cfg

3. Backup/restore of virtual machines - LVM - capturing the state of the whole domU system (domU snapshot)

asciiart
        Requirements
        ------------
        - the domU must use LVM disks

        Description of the backup/restore
        ---------------------------------
        - pause the domU (1)
        - save the state of the virtual machine to a file (2)
        - restore the state of the virtual machine from the file (3)
        - start the domU [unpause it] (4)
        ------------------------------------------------
        (1)# xm pause www.vhosts.example
        (2)# xm save www.vhosts.example /tmp/www.vhosts.example-save
        (3)# xm restore /tmp/www.vhosts.example-save
        (4)# xm unpause www.vhosts.example

Current practice (checked 2026-10)

noteThe article above is kept as it was written in 2008. This section lists what has changed since and what to do instead today.
bash
$ # cd /mnt/tmp && tar --xattrs --acls --selinux --numeric-owner -czpf /backup/www.vhosts.example.tgz ./

Sources:

← learnz/xen(EN | SK)