From 6019f8f8794b74483feacd01136bc5c888991bce Mon Sep 17 00:00:00 2001 From: Valentin Vidic Date: Fri, 11 Mar 2011 15:51:01 +0100 Subject: [PATCH] Add script to dump databases prior to backup. --- db-dump | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ debian/default | 3 +++ debian/install | 1 + 3 files changed, 53 insertions(+) create mode 100755 db-dump create mode 100644 debian/default diff --git a/db-dump b/db-dump new file mode 100755 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 index 0000000..7d1eec4 --- /dev/null +++ b/debian/default @@ -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 diff --git a/debian/install b/debian/install index d4e38e6..2ea175c 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +1,3 @@ sysbackup.pem etc/bacula/ gpg var/lib/bacula-cn/ +db-dump usr/share/bacula-cn -- 1.7.10.4