📜 ⬆️ ⬇️

Backup in xen4

This method works in other versions of Xen and even filed to the crowned CitrixXen.

what we have - file system XEN DomU on LVM
rack server with two Xeon® E5520 (for example)
and the need for backup means even remotely similar to automatic ones.

Since no one except phdvirtual.com has released anything for automated XEN backup, everyone backs up because of their sophistication and depth of knowledge.
Basically, all the options from Google are reduced to getting a snapshot of the specified LVM and saving it to disk.
In general, this is practically the only and most productive option, since the impression is obtained without stopping the virtual machine.
The virtual machine park on my servers is set to 20 (on a small company), backup is needed for almost everyone, so I archive the data. I use for this 7zip in multiprocessor mode.
It is also worth noting that machines with db and others. Demanding information loss services should be prepared before launching lvm snapshot. A different look at this problem can be found in the comments on this article below :)
')

So, the commands for backup of a single volume:

lvcreate -L20G -s -n 2003-mssql2-b /dev/vg/hdd
dd if=/dev/vg/hdd-b bs=1024000 | 7z a -tbzip2 -mmt=on -si /backup/xen/hdd.tar.bz
lvremove /dev/vg/hdd-b

first line - we get a lvm cast with the name 2003-mssql2-b
second line - using the dd command, copy the image into a file, archiving in 7 zip using all system processors to the full
The third command removes the lvm nugget from the system.

You can restore the system image with the following command:

7z e -tbzip2 -mmt=on -so /backup/xen/hdd.tar.bz | dd of=/dev/vg/hdd bs=1024000

And now all this needs to be automated and put to work on cron.
We divide this task into two scripts - the first with a list of lvm volumes and their size and deletion of images created more than 128 days ago, the second with the functionality of the backup itself described above.
The first file is backup-lv.sh

#!/bin/bash

DIR=/root/bin
BACKUP_CMD=alt.sh
BACKUP_ROOT=/backup/xen/

#VG=/dev/vg
LV[0]=atlassian-disk
LV[1]=hdd-disk

LV_SIZE[0]=10
LV_SIZE[1]=10

cd $DIR
COUNT=0
CAT_STR=""
while [ $COUNT -lt ${#LV[@]} ]
do
./$BACKUP_CMD -b ${LV[$COUNT]} -s ${LV_SIZE[$COUNT]}
COUNT=$(( $COUNT+1 ))
done

# delete backups older than 128 days
find $BACKUP_ROOT -type f -mtime +128 -exec rm {} \; 2>/dev/null


Second alt.sh file

#!/bin/bash
script=`basename $0`
USAGE="Usage: $script -b <lv_device> -s <lvm_size>"

MAX_TRIES=5

#variables
DATE=`date +%Y%m%d_%H_%M`
VG=/dev/vg

set -- `getopt b:s: $* 2>/dev/null`
if [ $# -eq 1 ]; then
echo $USAGE; exit 1
fi
for opt in $*
do
case "$opt" in
-b) BLOCK_DEVICE=$2; export BLOCK_DEVICE
shift 2;;
-s) SIZE=$2; export SIZE
shift 2;;
--) shift; break;;
esac
done
if [ $# -ne 0 ]; then
echo $USAGE; exit 1
fi

echo $SIZE
echo $VG
echo $BLOCK_DEVICE
echo
#LVM backup process

/sbin/lvcreate -L${SIZE}G -s -n $VG/$BLOCK_DEVICE-snap $VG/$BLOCK_DEVICE

/bin/dd if=$VG/$BLOCK_DEVICE-snap bs=1024000 | 7z a -tbzip2 -mmt=on -si /backup/xen/$BLOCK_DEVICE-$DATE.tar.bz;

/sbin/lvremove $VG/$BLOCK_DEVICE-snap -f


As a result, in the / backup / xen / directory which is a mounted NAS storage, we have backups in the last 128 days.
Now it’s enough to set the cron execution time (in our case every Saturday)

10 23 * * 6 /root/bin/backup-lv.sh &> /root/bin/log.txt

ZyZH for greater correctness of the presentation, changed the name of the lvm volume from mssql to hdd. Because the example was really not correct.

Source: https://habr.com/ru/post/116878/


All Articles