Skip to content

Commit

Permalink
feat: Attempt to fix recovery command for latest backup style
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Christie committed Jul 4, 2024
1 parent 7c52d34 commit fc52fdd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sql-recovery/recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,20 @@ def error(error_no):
# and then use this file in the recovery command.
print('--] Recovering from %s...' % BACKUP_FILE)

# Unpack - To avoid errors relating to changing the admin user
# remove anything that relates to creating or dropping that user.
# Unpack - To avoid errors relating to changing the PGUSER user
# remove anything that relates to creating or dropping that user
# and anything relating to dropping or creating the template1 database.
#
# Importantly, for this to work, the destination database server
# must have been started using an admin username that is the same
# as the admin user in the backup, i.e. source and destination
# database admin users must be the same.
UNPACK_CMD = "gunzip -c %s" \
" | egrep -v '^(CREATE|DROP) ROLE %s;'" \
" > %s/dumpall.sql" % (BACKUP_FILE, PGUSER, RECOVERY_ROOT_DIR)
UNPACK_CMD = "gunzip -c %s" % BACKUP_FILE
UNPACK_CMD += " | "
UNPACK_CMD += "egrep -v \"(CREATE|DROP) ROLE IF EXISTS %s;" % PGUSER
UNPACK_CMD += "|DROP DATABASE template1;"
UNPACK_CMD += "|CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'SQL_ASCII' LOCALE = 'C';\""
UNPACK_CMD += " > %s/dumpall.sql" % RECOVERY_ROOT_DIR
print(" $", UNPACK_CMD)
COMPLETED_PROCESS = subprocess.run(UNPACK_CMD, shell=True, stderr=subprocess.PIPE)

Expand Down

0 comments on commit fc52fdd

Please sign in to comment.