| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# `pg_dumpall|psql` pipeline called from `pg_upgradecluster -m dump` |
| 4 |
|
| 5 |
set -eu |
| 6 |
set -o pipefail # needs dash >= 0.5.12-7 |
| 7 |
|
| 8 |
# all these options are mandatory |
| 9 |
while getopts "A:h:H:p:P:Q:U:" opt ; do |
| 10 |
case $opt in |
| 11 |
A) PG_DUMPALL="$OPTARG" ;; |
| 12 |
h) OLDHOST="$OPTARG" ;; |
| 13 |
H) NEWHOST="$OPTARG" ;; |
| 14 |
p) OLDPORT="$OPTARG" ;; |
| 15 |
P) NEWPORT="$OPTARG" ;; |
| 16 |
Q) PSQL="$OPTARG" ;; |
| 17 |
U) NEWUSER="$OPTARG" ;; |
| 18 |
*) exit 5 ;; |
| 19 |
esac |
| 20 |
done |
| 21 |
|
| 22 |
"$PG_DUMPALL" --quote-all-identifiers -h "$OLDHOST" -p "$OLDPORT" | |
| 23 |
LC_ALL=C grep --text -v "^CREATE ROLE \"$NEWUSER\";$" | # force text mode; avoid error on existing role |
| 24 |
"$PSQL" --no-psqlrc --echo-queries --output /dev/null -vON_ERROR_STOP=on -h "$NEWHOST" -p "$NEWPORT" postgres | |
| 25 |
cut -c 1-${COLUMNS:-80} # avoid overly long output (lowrite) |