]> code.delx.au - monosys/commitdiff
Initial commit
authorJames Bunton <jamesbunton@delx.net.au>
Fri, 1 May 2015 23:20:20 +0000 (09:20 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Fri, 1 May 2015 23:20:20 +0000 (09:20 +1000)
backup-all [new file with mode: 0755]
common [new file with mode: 0644]
etc-cron.d-backup [new file with mode: 0644]
template-rdiff-backup [new file with mode: 0755]
template-rsync [new file with mode: 0755]

diff --git a/backup-all b/backup-all
new file mode 100755 (executable)
index 0000000..f11cf93
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+for script in /backup/scripts/*; do
+    if ! grep -q '^function run_backup' "$script"; then
+        continue
+    fi
+    if [ ! -x "$script" ]; then
+        echo "Skipping $script because it is not executable"
+        continue
+    fi
+    output="$("$script" 2>&1)"
+    if [ "$?" -ne 0 ]; then
+        echo "Failed to run: $script"
+        echo "$output"
+    fi
+done
+
diff --git a/common b/common
new file mode 100644 (file)
index 0000000..ef5972c
--- /dev/null
+++ b/common
@@ -0,0 +1,18 @@
+#! bash
+
+set -e
+ionice -c 3 -p $$
+renice -n 19 -p $$ > /dev/null
+
+script="$(basename "${BASH_SOURCE[1]}" .sh)"
+
+(
+if ! flock -n -x 200; then
+    echo "Failed to get a lock!"
+    exit 1
+fi
+
+run_backup
+
+) 200>"/run/lock/backup-${script}"
+
diff --git a/etc-cron.d-backup b/etc-cron.d-backup
new file mode 100644 (file)
index 0000000..1eea8a6
--- /dev/null
@@ -0,0 +1,6 @@
+SHELL=/bin/bash
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO=root
+
+# m    h  dom mon dow   user    command
+  0    2   *   *   *    root    /backup/scripts/backup-all
diff --git a/template-rdiff-backup b/template-rdiff-backup
new file mode 100755 (executable)
index 0000000..4ca35d4
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+function run_backup {
+    rdiff-backup \
+        --preserve-numerical-ids \
+        --exclude-sockets \
+        --exclude '/home/*/tmp' \
+        --include '/home' \
+        --exclude '/var/cache' \
+        --exclude '/var/log' \
+        --exclude '/var/tmp' \
+        --exclude '/tmp' \
+        --include '/var' \
+        --exclude-other-filesystems \
+        my-host.example.com::/ /backup/my-host
+
+    rdiff-backup -v1 --force --remove-older-than 365D /backup/my-host
+}
+
+. /backup/scripts/common
+
diff --git a/template-rsync b/template-rsync
new file mode 100755 (executable)
index 0000000..6ba2077
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+function run_backup {
+    rsync -a --numeric-ids --delete my-host.example.com:/backup/my-host/ /backup/my-host/
+}
+
+. /backup/scripts/common
+