Add script to dump databases prior to backup.
authorValentin Vidic <Valentin.Vidic@CARNet.hr>
Fri, 11 Mar 2011 14:51:01 +0000 (15:51 +0100)
committerValentin Vidic <Valentin.Vidic@CARNet.hr>
Fri, 11 Mar 2011 14:51:01 +0000 (15:51 +0100)
db-dump [new file with mode: 0755]
debian/default [new file with mode: 0644]
debian/install

diff --git a/db-dump b/db-dump
new file mode 100755 (executable)
index 0000000..5da3811
--- /dev/null
+++ b/db-dump
@@ -0,0 +1,49 @@
+#!/bin/sh -e
+DUMP_DIR=/var/backups/bacula-cn
+CONFIG=/etc/default/bacula-cn
+
+# load user config
+[ -r $CONFIG ] && . $CONFIG
+
+# check if db dumping is disabled
+[ -z "$DUMP_DIR" ] && exit
+
+# cleanup
+MYSQL_EXCLUDE=/var/lib/mysql/.bacula_excludeme
+PG_EXCLUDE=/var/lib/postgresql/.bacula_excludeme
+rm -f $MYSQL_EXCLUDE
+rm -f $PG_EXCLUDE
+
+# prepare directory
+umask 077
+[ -e "$DUMP_DIR" ] || mkdir "$DUMP_DIR"
+if [ -e "$DUMP_DIR" -a ! -d "$DUMP_DIR" ]; then
+    echo "$DUMP_DIR not usable"
+    exit 1
+fi
+chown root:root "$DUMP_DIR"
+chmod 0700 "$DUMP_DIR"
+
+# dump mysql
+if [ -d /var/lib/mysql \
+     -a -x "`which mysqldump 2>/dev/null`" \
+     -a -r /etc/mysql/debian.cnf ]
+then
+    MYSQL_DUMP="$DUMP_DIR/mysql.dump.gz"
+    MYSQL_OPT="--defaults-extra-file=/etc/mysql/debian.cnf --all-databases"
+
+    if mysqldump $MYSQL_OPT | gzip > $MYSQL_DUMP; then
+        touch $MYSQL_EXCLUDE
+    fi
+fi
+
+# dump postgresql
+if [ -d /var/lib/postgresql \
+     -a -x "`which pg_dumpall 2>/dev/null`" ]
+then
+    PG_DUMP="$DUMP_DIR/postgresql.dump.gz"
+
+    if su postgres -c pg_dumpall | gzip > $PG_DUMP; then
+        touch $PG_EXCLUDE
+    fi
+fi
diff --git a/debian/default b/debian/default
new file mode 100644 (file)
index 0000000..7d1eec4
--- /dev/null
@@ -0,0 +1,3 @@
+# Directory for dumping databases prior to backup
+# To avoid dumping the databases set this to an empty string
+DUMP_DIR=/var/backups/bacula-cn
index d4e38e6..2ea175c 100644 (file)
@@ -1,2 +1,3 @@
 sysbackup.pem etc/bacula/
 gpg var/lib/bacula-cn/
+db-dump usr/share/bacula-cn