--- /dev/null
+#!/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
--- /dev/null
+# Directory for dumping databases prior to backup
+# To avoid dumping the databases set this to an empty string
+DUMP_DIR=/var/backups/bacula-cn