Skip to content

Commit a89b33e

Browse files
alanbchristiea.b.christie
andauthored
Use of no-comments and exclude-database (pg_dumpall) (#8)
* fix: Fix recovery (s3 fuse) * fix: Fix "current user cannot be dropped" on recovery * fix: Fix recovery typo * fix: Fix for IF EXISTS * fix: Fix filter command * fix: Remove sql.out on success * fix: Backup now uses --no-comments and --exclude-database= --------- Co-authored-by: a.b.christie <alan.christie@matildapeak.com>
1 parent 1e44f03 commit a89b33e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

sql-backup/backup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,16 @@
389389
# Backup commands (for all databases) for the various database flavours...
390390
BACKUP_COMMANDS = {
391391
FLAVOUR_POSTGRESQL: 'pg_dumpall --username=%s --no-password --clean --if-exists'
392+
' --no-comments'
393+
' --exclude-database=template1'
394+
' --exclude-database=postgres'
392395
' | gzip > %s' % (PGUSER, BACKUP)
393396
}
394397
# Backup commands (for a single database).
395398
# Check comments above in case they're relevant here.
396399
BACKUP_COMMANDS_ONE_DB = {
397-
FLAVOUR_POSTGRESQL: 'pg_dump --username=%s --no-password --clean --if-exists %s'
398-
' | gzip > %s' % (PGUSER, DATABASE, BACKUP)
400+
FLAVOUR_POSTGRESQL: 'pg_dump --username=%s --no-password --clean --if-exists'
401+
' --no-comments %s | gzip > %s' % (PGUSER, DATABASE, BACKUP)
399402
}
400403

401404
# What 'flavour' of database do we expect to be backing up?

sql-recovery/recovery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,16 @@ def error(error_no):
631631
# Remove any files we may have created.
632632
RECOVERY_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_RECOVERY_NAME)
633633
FILTERED_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_FILTERED_NAME)
634+
OUTPUT_FILE = "%s/sql.out" % RECOVERY_ROOT_DIR
634635
if os.path.isfile(RECOVERY_FILE):
635636
print('--] Removing %s' % RECOVERY_FILE)
636637
os.remove(RECOVERY_FILE)
637638
if os.path.isfile(FILTERED_FILE):
638639
print('--] Removing %s' % FILTERED_FILE)
639640
os.remove(FILTERED_FILE)
641+
if os.path.isfile(OUTPUT_FILE):
642+
print('--] Removing %s' % OUTPUT_FILE)
643+
os.remove(OUTPUT_FILE)
640644

641645
# Success if we get here
642646
write_termination_message()

0 commit comments

Comments
 (0)