backup and restore

The “” script from Daniel Berteaud.

# wget
# chmod +x

# nano -w
     # lvcreate path
     - $opts{lvcreate} = '/usr/sbin/lvcreate -c 512';
     + $opts{lvcreate} = '/sbin/lvcreate -c 512';
     # lvremove path
     - $opts{lvremove} = '/usr/sbin/lvremove';
     + $opts{lvremove} = '/sbin/lvremove';

# apt-get install libxml-simple-perl libsys-virt-perl libfile-which-perl

Prepare partition for backup

# lvcreate -l 3000 -n backup iscsi2
# mkfs.ext4 /dev/iscsi2/backup
# mount /dev/mapper/iscsi2-backup /var/lib/libvirt/backup

To mount iscsi partition at boot:

# blkid
    /dev/mapper/iscsi2-backup: UUID="0a413f6c-50cd-45c7-ba1c-0a413f6c1ac6" TYPE="ext4"

# nano -w /etc/fstab

    + UUID=0a413f6c-50cd-45c7-ba1c-0a413f6c1ac6  /var/lib/libvirt/backup    ext4    defaults,auto,_netdev   0       0

Live backup of LVM virtual machine by snapshot

# ./ --dump --vm=tubu1-clone --state --debug

Connecting to libvirt daemon using qemu:///system as URI

Checking tubu1-clone status

Running dump routine for tubu1-clone

Locking tubu1-clone

Saving XML description for tubu1-clone to /var/lib/libvirt/backup/tubu1-clone/tubu1-clone.xml
tubu1-clone is running, saving state....
tubu1-clone state saved as /var/lib/libvirt/backup/tubu1-clone/tubu1-clone.state

Analysing disk /dev/iscsi2/tubu1-clone connected on tubu1-clone as vda

Running: /sbin/lvcreate -c 512 -p r -s -n /dev/iscsi2/tubu1-clone_1344612236 -L 5G /dev/iscsi2/tubu1-clone > /dev/null 2>&1
/dev/iscsi2/tubu1-clone seems to be a valid logical volume (LVM), a snapshot has been taken as /dev/iscsi2/tubu1-clone_1344612236
Adding /dev/iscsi2/tubu1-clone_1344612236 to the list of disks to be backed up

The following disks will be dumped:

Source: /dev/iscsi2/tubu1-clone_1344612236	Dest: /var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img

We can run a live backup

Trying to restore tubu1-clone from /var/lib/libvirt/backup/tubu1-clone/tubu1-clone.state
Waiting for restoration to complete

Starting dump of /dev/iscsi2/tubu1-clone_1344612236 to /var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img

32000+0 records in
32000+0 records out
8388608000 bytes (8.4 GB) copied, 244.731 s, 34.3 MB/s
Removing snapshot /dev/iscsi2/tubu1-clone_1344612236

Cannot start domain restoration, tubu1-clone is running (maybe already restored after a live backup ?)
Removing lock file for tubu1-clone


# ls -l /var/lib/libvirt/backup/tubu1-clone

-rw------- 1 root root  284363322 Aug 10 17:23 tubu1-clone.state
-rw-r--r-- 1 root root 8388608000 Aug 10 17:28 tubu1-clone_vda.img
-rw-r--r-- 1 root root       2453 Aug 10 17:23 tubu1-clone.xml

Restore to same virtual machine (LVM)

# virsh shutdown tubu1-clone
# dd if=/var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img | pv -s 8G | dd of=/dev/iscsi2/tubu1-clone
# virsh restore tubu1-clone.state

Restore to different name/UUID (LVM)

Check original disk size

# qemu-img info /var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img

image: /var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img
file format: raw
virtual size: 7.8G (8388608000 bytes)
disk size: 7.8G

Create new volume same size as original

lvcreate -L 8388608000B -n tubu1-restore kvm2

Restore disk

# dd if=/var/lib/libvirt/backup/tubu1-clone/tubu1-clone_vda.img | pv -s 8G | dd of=/dev/kvm2/tubu1-restore

Edit metadata with new name and UUID

# cp /var/lib/libvirt/backup/tubu1-clone/tubu1-clone.xml ./tubu1r.xml

# uuidgen

# nano -w tubu1r.xml

# diff tubu1r.xml /var/lib/libvirt/backup/tubu1-clone/tubu1-clone.xml
< <domain type='kvm' id='107'>
<   <name>tubu1r</name>
<   <uuid>6702d0ee-0775-4ff9-bb75-d4a62ebc82b7</uuid>
> <domain type='kvm' id='7'>
>   <name>tubu1-clone</name>
>   <uuid>4d9fad50-7206-3117-18f3-dd620c402b9b</uuid>
<       <source dev='/dev/kvm2/tubu1-restore'/>
>       <source dev='/dev/iscsi2/tubu1-clone'/>

Define new virtual machine from metadata

# virsh define tubu1r.xml

VM clone

hypervisor/virtbackup.txt · Last modified: 2012/09/24 11:37 by giancarlo

Developers: CNR IRCrES IT Office and Library
Giancarlo Birello (giancarlo.birello _@_ and Anna Perin (anna.perin _@_
DigiBess is licensed under: Creative Commons License
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Drupal Garland Theme for Dokuwiki