set -e
set -u
-CONFFILE=/etc/nagios/dsa-check-backuppg.conf
-ROOTDIR=$(perl -MYAML -e "print YAML::LoadFile('$CONFFILE')->{'rootdir'}")
-if [ -z "$ROOTDIR" ]; then
- echo >&2 "Could not learn rootdir from $CONFFILE"
- exit 1
-fi
-
if [ -t 0 ]; then
verbose=1
else
verbose=0
fi
-if [ "$verbose" -gt 0 ]; then
- console="--progress --verbose"
-else
- console=""
-fi
-
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
echo "Usage: $0 [<host>:<port>]"
exit 0
forcehostport=""
fi
-export PGSSLMODE=verify-full
-export PGSSLROOTCERT=/etc/ssl/debian/certs/ca.crt
-
-date=$(date "+%Y%m%d-%H%M%S")
-thishost=$(hostname -f)
-
while read host port username cluster version; do
[ "${host#\#}" = "$host" ] || continue
[ -z "$host" ] && continue
continue
fi
- label="$thishost-$date-$host-$cluster-$version-backup"
- [ "$verbose" -gt 0 ] && echo "Doing $host:$port $version/$cluster: $label"
-
- target="$cluster.BASE.$label.tar.gz"
- tmp=$(tempfile -d "$ROOTDIR" -p "BASE-$host:$port-" -s ".tar.gz")
- trap "rm -f '$tmp'" EXIT
-
- /usr/lib/postgresql/"$version"/bin/pg_basebackup --format=tar --pgdata=- --label="$label" --host="$host" --port="$port" --username="$username" --no-password $console | pigz > "$tmp"
- if ! [ "${PIPESTATUS[0]}" -eq 0 ]; then
- echo >&2 "pg_basebackup failed with exit code ${PIPESTATUS[0]}"
- exit 1
- fi
- mv "$tmp" "$ROOTDIR/${host%%.*}/$target"
+ /usr/local/bin/postgres-make-one-base-backup "$host" "$port" "$username" "$cluster" "$version"
done << EOF
seger.debian.org 5432 debian-backup dak 9.6
bmdb1.debian.org 5435 debian-backup main 9.6