]> git.sven.stormbind.net Git - sven/scripts.git/commitdiff
Import hetzner backup scripts
authorSven Hoexter <sven@stormbind.net>
Mon, 17 Jan 2011 16:45:02 +0000 (17:45 +0100)
committerSven Hoexter <sven@stormbind.net>
Mon, 17 Jan 2011 16:45:02 +0000 (17:45 +0100)
hetzner/hetznerbackup.sh [new file with mode: 0755]
hetzner/hetznerbackupv2.sh [new file with mode: 0755]

diff --git a/hetzner/hetznerbackup.sh b/hetzner/hetznerbackup.sh
new file mode 100755 (executable)
index 0000000..e7bae64
--- /dev/null
@@ -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 (executable)
index 0000000..86c7ede
--- /dev/null
@@ -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