#!/bin/bash set -euo pipefail IFS=$'\n\t' trap "exit 1" INT [[ "`id -u`" -eq 0 ]] && { echo "Don't run as root!" >&2 exit 1 } person=$1 host=$2 dir=~/archive/$person mkdir "$dir" cd "$dir" # Find the newest version of pg_dumpall and use that ssh root@$host 'bash -s' <<-\OUTER | tar xzp script=/tmp/find-newest-postgres.bash cat <<-\INNER >$script for n in `seq 10 20 | tac` do p=/usr/pgsql-$n/bin [[ -x $p/pg_dumpall ]] && PATH=$p:$PATH && break done pg_dumpall > pg_dumpall.out INNER chmod 755 $script su - postgres -c $script && tar czp -C / var/lib/pgsql root home OUTER