Server Backup and Rescue
This page contains useful commands, scripts and tips on doing backups of Linux servers and on rescuing or restoring them in case of emergency.
BGBM BDI staff please also see: http://ww3.bgbm.org/bdinotes/LinuxCrossbackup
create dump from logical volume, copy to remote server and restore dump
sourceVg= sourceLv= targetHost= targetWorkingDir= targetVg= targetLv= ######## # Source # grösse ermitteln sourceLvSize= # blocksize ermitteln byteSize = `tune2fs -l /dev/$sourceVg/$sourceLv` # einpacken dd if=/dev/$sourceVg/$sourceLv conv=sync,noerror bs=$byteSize | gzip -c | ssh $targetHost "cat > $targetWorkingDir/$sourceLv.gz" ######## # Target # neues lv anlegen (lv-size >= source lv) lvcreate -v -L$sourceLvSize -n $targetLv $targetVg # auspacken gunzip -c targetWorkingDir/$sourceLv.gz | dd of=/dev/$targetVg/$targetLv bs=$byteSize # <vm-config> von der source kopieren und anpassen 1. Volumes anpassen 2. Überprüfen ob kernel und initrd vorhanden # vm starten xm create -c <vm-config>
backing up logical volumes using lv snapshots
#
# backing up logical volumes using lv snapshots
#
sourceVg=/dev/guest
sourceLv-list=("edit-idp-root" "edit-production-root" "edit-production-data" "edit-develop-root")
targetHost=10.10.5.20
targetWorkingDir=/backup/edit-xen-host/
# blocksize ermitteln `tune2fs -l /dev/$sourceVg/$sourceLv`
byteSize=4096
for sourceLv in ${sourceLv-list[@]}; do
echo backup of /dev/$sourceVg/$sourceLv
# create the snapshot this can be rather small since we don't expect much changes in the filesystem during the backup process
lvcreate -L512M -s -n lvbackup /dev/$sourceVg/$sourceLv
# dd if=/dev/$sourceVg/lvbackup conv=sync,noerror bs=$byteSize | gzip -c | ssh $targetHost "cat > $targetWorkingDir/$sourceLv.gz"
# remove the snapshot
# lvremove /dev/$sourceVg/lvbackup
done
