diff --git a/backups.sh b/backups.sh index 27bbdcf..a21742b 100755 --- a/backups.sh +++ b/backups.sh @@ -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 @@ -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 diff --git a/restore.sh b/restore.sh index 14699df..bb99dc0 100755 --- a/restore.sh +++ b/restore.sh @@ -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}