Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kartoza/docker-pg-backup
Browse files Browse the repository at this point in the history
# Conflicts:
#	Dockerfile

Add option to dump globals and restore
  • Loading branch information
NyakudyaA committed Feb 17, 2019
1 parent 250800a commit 9717c2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ echo "Backup running to $MYBACKUPDIR" >> /var/log/cron.log
#
# Loop through each pg database backing it up
#

DBLIST=`psql -l | awk '{print $1}' | grep -v "+" | grep -v "Name" | grep -v "List" | grep -v "(" | grep -v "template" | grep -v "postgres" | grep -v "|" | grep -v ":"`
DBLIST=`psql -l | awk '$1 !~ /[+(|:]|Name|List|template|postgres/ {print $1}'`
# echo "Databases to backup: ${DBLIST}" >> /var/log/cron.log
for DB in ${DBLIST}
do
Expand All @@ -29,5 +28,12 @@ do
else
FILENAME="${ARCHIVE_FILENAME}.${DB}.dmp"
fi
pg_dump -Fc -f ${FILENAME} -x -O ${DB}
if [[ -f ${MYBASEDIR}/globals.sql ]]; then
rm ${MYBASEDIR}/globals.sql
pg_dumpall --globals-only -f ${MYBASEDIR}/globals.sql
else
echo "Dump users and permisions"
pg_dumpall --globals-only -f ${MYBASEDIR}/globals.sql
fi
pg_dump -Fc -f ${FILENAME} ${DB}
done
4 changes: 3 additions & 1 deletion restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ if [ -z "${WITH_POSTGIS:-}" ]; then
createdb -O ${PGUSER} ${TARGET_DB}
else
echo "Recreate target DB with POSTGIS"
createdb -O ${PGUSER} -T template_postgis ${TARGET_DB}
createdb -O ${PGUSER} ${TARGET_DB}
psql -c 'CREATE EXTENSION IF NOT EXISTS postgis;' ${TARGET_DB}
fi

echo "Restoring dump file"
psql -f /backups/globals.sql ${TARGET_DB}
pg_restore ${TARGET_ARCHIVE} | psql -d ${TARGET_DB}

0 comments on commit 9717c2a

Please sign in to comment.