diff --git a/ROOT/DEBIAN/control b/ROOT/DEBIAN/control index 7aadd3592fa03f8a14e77f3215ed36021db8e228..8b29adb06011e6a220b38589809af149343c16e5 100644 --- a/ROOT/DEBIAN/control +++ b/ROOT/DEBIAN/control @@ -3,6 +3,6 @@ Priority: optional Section: otherosfs Maintainer: Chemistry COs <support@ch.cam.ac.uk> Architecture: all -Version: 0.9-ch82 +Version: 0.9-ch83 Depends: zfs-dkms, postgresql-13 | postgresql-9.5 | postgresql-9.4 , liblockfile-simple-perl, libdbi-perl, libjson-perl, libzfs-perl-chem, libnet-openssh-perl, libdbd-pg-perl, mbuffer, rsync, nfs-kernel-server, pv, libwww-curl-perl Description: a backup system using ZFS (repository 'backup-scheduler') diff --git a/ROOT/usr/lib/chem-zfs-backup-server/pg-dump-script b/ROOT/usr/lib/chem-zfs-backup-server/pg-dump-script new file mode 100755 index 0000000000000000000000000000000000000000..8fb9bded710ec4379cec99d4b3c98ea5d7559acf --- /dev/null +++ b/ROOT/usr/lib/chem-zfs-backup-server/pg-dump-script @@ -0,0 +1,53 @@ +#!/bin/bash +set -xv +# We want any failure to get passed back to the script +# which called us. Rather than carefully keeping track +# of return codes, we bail on error +set -e + +HOSTNAME=$1 +SRCDIR=$2 +ZFSTARGET=$3 + +CONFDIR=/etc/chem-zfs-backup-server/zfs-rsync.d + +TAG=${SRCDIR//\//.} + +# The config file must, at a minimum, define PGDUMP_DATABASE. +# It can also define PGDUMP_EXTRA_OPTIONS to be passed to the +# pg_dump command later in the script +. $CONFDIR/${HOSTNAME}_${TAG} + +if [ -z "$PGDUMP_DATABASE" ] ; then + echo PGDUMP_DATABASE is not set + exit 1 +fi + +SSHUSER=${SSHUSER:-root} + +# Script runs with set -e, so we ensure we tidy up our TEMPDIR on exit +# no matter how/when the script exits. +tidytmp() { + [ -n "$TEMPDIR" ] && ssh ${SSHUSER}@${HOSTNAME} " [ -d $TEMPDIR ] && rm -r $TEMPDIR " +} +trap tidytmp 0 + +unset PGPASSFILE +TEMPDIR=$(ssh ${SSHUSER}@${HOSTNAME} mktemp -d /tmp/pgXXXXX) + +MOUNT=$(zfs get -H -ovalue mountpoint $ZFSTARGET) +BACKUP_DEST=$MOUNT/pgdumps/pgdumps-master/ + +mkdir -p $BACKUP_DEST + +# we need this to exist for the rsync part of the backup, so the rsync returns successfully +ssh ${SSHUSER}@${HOSTNAME} mkdir -p /var/empty + +# Dump database to temporary directory. We ensure we exit 1 here on failure +# so a) the script exits due to set -e, then b) the error bubbles up to the +# script which called us. +ssh ${SSHUSER}@${HOSTNAME} pg_dump $PGDUMP_EXTRA_OPTIONS --host localhost --blobs --clean --user _pgbackup $PGDUMP_DATABASE -Fd -f $TEMPDIR/pgdump || exit 1 + +# Rsync to backup destination +rsync -av --checksum --delete --no-times ${SSHUSER}@${HOSTNAME}:$TEMPDIR/pgdump/ $BACKUP_DEST +# TEMPDIR will be removed on exit by tidytmp()