Italiano English
Modifica History Actions

XENBackup

Script per backuppare una macchina xen, comprimere le cartelle "importanti" e mandarle in rsync "furbo" su una macchina remota.


LVNAME=ale #logica volume name
VGNAME=birra #virtual group name
HOST=www.myhost-I-want-to-backup.org #name of the host machine to backup
BACKUP_HOST=backup.machine.it #name of the machine where we want to upload the backup
BACKUP_USER=lorenzo
BACKUP_DIR=/home/lorenzo/ale #backup dir where we put tar.gz files
DIRS="home var" #dirs to backup
MYSQLPASS=mypass
#--------------------------------------------------#
mkdir -p /backup

ssh root@$HOST "mkdir -p /root/backup/; mysqldump -p$MYSQLPASS --all-databases | bzip2 -c > /root/backup/norimberga-alldb-`date -I`.sql.bz2"

# svn, hg backup here


# create a snapshot

lvcreate -L20G -s -n $LVNAME\_snap  /dev/$VGNAME/$LVNAME
mkdir -p /mnt/$LVNAME\_backup
mkdir -p /backup/$LVNAME
mount /dev/$VGNAME/$LVNAME\_snap /mnt/$LVNAME\_backup


# we use a rsync friendly gzip
# more details to http://svana.org/kleptog/rgzip.html
cd /mnt/$LVNAME\_backup
tar c --use-compress-program /usr/local/bin/rgzip -vf /backup/$LVNAME/$LVNAME`date -I`.tar.gz2 $DIRS

#rsync with the backup machine

rsync -avz -e ssh /backup/$LVNAME/$LVNAME`date -I`.tar.gz2 $BACKUP_USER@$BACKUP_HOST:$BACKUP_DIR

#umount and destroy snapshot

umount /mnt/$LVNAME\_backup
lvremove /dev/$VGNAME/$LVNAME\_snap