From 0d5f2f20d9da1b932020bf17f84ad4cd542cc86a Mon Sep 17 00:00:00 2001 From: Sven Hoexter Date: Mon, 17 Jan 2011 17:45:02 +0100 Subject: [PATCH] Import hetzner backup scripts --- hetzner/hetznerbackup.sh | 75 ++++++++++++++++++++++++++++++++++++++ hetzner/hetznerbackupv2.sh | 71 ++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 hetzner/hetznerbackup.sh create mode 100755 hetzner/hetznerbackupv2.sh diff --git a/hetzner/hetznerbackup.sh b/hetzner/hetznerbackup.sh new file mode 100755 index 0000000..e7bae64 --- /dev/null +++ b/hetzner/hetznerbackup.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +### Halt on errors +set -e + +### Debug +#set -x + +### General settings +export PASSPHRASE=s +export FTP_PASSWORD=s +FTP_USER=u +FTP_HOST=h +LOCKFILE="/var/lock/backup/hetznerbackup" + +## Backup job for the dom0 main +job_main() { + echo "Backing up main/etc" + duplicity $BMODE /etc ftp://$FTP_USER@$FTP_HOST/main/etc + duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/main/etc +} + +### Backup job for the domU void +job_void() { + ### mount all domU partitions + mount -o ro /dev/vg0/void-root /mnt/backup/void-root + mount -o ro /dev/vg0/void-home /mnt/backup/void-home + mount -o ro /dev/vg0/void-var /mnt/backup/void-var + + if [ -e /mnt/backup/void-var/lib/automysqlbackup/backupdone ]; then + MYSQLOK="--include /mnt/backup/void-var/lib/automysqlbackup/backupdone" + else + echo "WARNING: It seems that the last mysql backup in the domU void is still runing" + echo "Skipping mysql backup - please re-schedule" + fi + + echo "Backing up void" + duplicity $BMODE \ + --exclude /mnt/backup/void-home/tcm \ + --include /mnt/backup/void-root/etc \ + --include /mnt/backup/void-home \ + $MYSQLOK \ + --exclude /mnt/backup \ + /mnt/backup ftp://$FTP_USER@$FTP_HOST/void/ + duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/void/ + + + ### umount all domU partitions + umount /mnt/backup/void-root /mnt/backup/void-home /mnt/backup/void-var +} + +### check for other runing instances of this script +if [ -e $LOCKFILE ]; then + echo "Lockfile $LOCKFILE found - aborting" + echo "This is a typical result of a failed backup run, please contact your admin" + exit 5 +else + touch $LOCKFILE +fi + +### Set the duplicity backup mode we would like to use +if [[ $(LANG=C; date +%A) =~ Sunday ]]; then + echo "Runing in full mode" + BMODE="full" +else + echo "Runing in incr mode" + BMODE="incr" +fi + +### Start the backup jobs +job_main +job_void + +### remove the lockfile +rm $LOCKFILE diff --git a/hetzner/hetznerbackupv2.sh b/hetzner/hetznerbackupv2.sh new file mode 100755 index 0000000..86c7ede --- /dev/null +++ b/hetzner/hetznerbackupv2.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +### Halt on errors +set -e + +### Do not inherit the following variables +# Safety net just in case some calls this +# script in a bogus way. +unset $dry + +### Debug +#set -x +#set dry="--dry-run" + +### General settings +export PASSPHRASE=s +export FTP_PASSWORD=s +FTP_USER=uxxx +FTP_HOST=uxxx.your-backup.de +LOCKFILE="/var/lock/backup/hetznerbackup" +PROTO=ssh + +## Backup job for main +job_main() { + echo "Backing up main" + + echo "Going for /etc" + duplicity $BMODE $dry /etc $PROTO://$FTP_USER@$FTP_HOST/main/etc + duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/etc + + echo "Going for /home" + duplicity $BMODE $dry /home $PROTO://$FTP_USER@$FTP_HOST/main/home + duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/home + + echo "Going for /var/www" + duplicity $BMODE $dry /var/www $PROTO://$FTP_USER@$FTP_HOST/main/var/www + duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/var/www + + echo "Going for /var/lib/automysqlbackup" + if [ -e /var/lib/automysqlbackup/backupdone ]; then + duplicity $BMODE $dry /var/lib/automysqlbackup $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup + duplicity remove-all-but-n-full 5 --force $dry $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup + else + echo "WARNING: It seems that the last mysql backup is still runing" + echo "Skipping mysql backup - please re-schedule" + fi +} + +### check for other runing instances of this script +if [ -e $LOCKFILE ]; then + echo "Lockfile $LOCKFILE found - aborting" + echo "This is a typical result of a failed backup run, please contact your admin" + exit 5 +else + touch $LOCKFILE +fi + +### Set the duplicity backup mode we would like to use +if [[ $(LANG=C; date +%A) =~ Sunday ]]; then + echo "Runing in full mode" + BMODE="full" +else + echo "Runing in incr mode" + BMODE="incr" +fi + +### Start the backup jobs +job_main + +### remove the lockfile +rm $LOCKFILE -- 2.39.5