Skip to content

Commit 6aa0ba1

Browse files
alanbchristiea.b.christie
andauthored
Use of IF EXISTS (#6)
* fix: Fix recovery (s3 fuse) * fix: Fix "current user cannot be dropped" on recovery * fix: Fix recovery typo * fix: Fix for IF EXISTS --------- Co-authored-by: a.b.christie <alan.christie@matildapeak.com>
1 parent a6b0f1d commit 6aa0ba1

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

sql-recovery/recovery.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python
22

33
"""A simple module to recover a backup created with pg_dumpall (or pg_dump)
4-
(as performed by our sql-backup container).
4+
(as performed by our sql-backup container). Importantly,
5+
any pg_dumpall backup is expected to have been created with
6+
"--clean" and "-if-exists" options.
57
68
The backup directory (BACKUP_ROOT_DIR) is expected to have
79
been mounted as a volume in the container image.
@@ -550,7 +552,7 @@ def error(error_no):
550552
# We only need to do this if the recovery is from a dumpall.
551553
if not DATABASE:
552554
TARGET_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_RECOVERY_NAME)
553-
FILTER_PG_CMD = "egrep -v '^(CREATE|DROP) ROLE %s;' %s > filtered.sql ; mv filtered.sql %s" % (RECOVERY_DATABASE_ROOT_USER, TARGET_FILE, TARGET_FILE)
555+
FILTER_PG_CMD = "egrep -v '^(CREATE|DROP) ROLE IF EXISTS %s;' %s > filtered.sql ; mv filtered.sql %s" % (RECOVERY_DATABASE_ROOT_USER, TARGET_FILE, TARGET_FILE)
554556
print(" $", FILTER_PG_CMD)
555557
COMPLETED_PROCESS = subprocess.run(FILTER_PG_CMD,
556558
shell=True,

0 commit comments

Comments
 (0)