|
205 | 205 | # The recovery root dir, where backups are unpacked. |
206 | 206 | RECOVERY_ROOT_DIR = '/recovery' |
207 | 207 | DECOMPRESSED_RECOVERY_NAME = 'recovery' |
| 208 | +DECOMPRESSED_FILTERED_NAME = 'filtered' |
208 | 209 | BACKUP_FILE_PREFIX = 'backup' |
209 | 210 |
|
210 | 211 | # Recovery commands for the various database flavours... |
@@ -551,8 +552,9 @@ def error(error_no): |
551 | 552 | # cause the recovery to fail with "current user cannot be dropped". |
552 | 553 | # We only need to do this if the recovery is from a dumpall. |
553 | 554 | if not DATABASE: |
554 | | - TARGET_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_RECOVERY_NAME) |
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) |
| 555 | + RECOVERY_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_RECOVERY_NAME) |
| 556 | + FILTERED_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_FILTERED_NAME) |
| 557 | + FILTER_PG_CMD = "egrep -v '^(CREATE ROLE|DROP ROLE IF EXISTS) %s;' %s > %s ; mv %s %s" % (RECOVERY_DATABASE_ROOT_USER, RECOVERY_FILE, FILTERED_FILE, FILTERED_FILE, RECOVERY_FILE) |
556 | 558 | print(" $", FILTER_PG_CMD) |
557 | 559 | COMPLETED_PROCESS = subprocess.run(FILTER_PG_CMD, |
558 | 560 | shell=True, |
@@ -626,6 +628,16 @@ def error(error_no): |
626 | 628 | print('--] OK - Found the expected number of databases (%s).' |
627 | 629 | % DATABASE_EXPECTED_COUNT) |
628 | 630 |
|
| 631 | +# Remove any files we may have created. |
| 632 | +RECOVERY_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_RECOVERY_NAME) |
| 633 | +FILTERED_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR, DECOMPRESSED_FILTERED_NAME) |
| 634 | +if os.path.isfile(RECOVERY_FILE): |
| 635 | + print('--] Removing %s' % RECOVERY_FILE) |
| 636 | + os.remove(RECOVERY_FILE) |
| 637 | +if os.path.isfile(FILTERED_FILE): |
| 638 | + print('--] Removing %s' % FILTERED_FILE) |
| 639 | + os.remove(FILTERED_FILE) |
| 640 | + |
629 | 641 | # Success if we get here |
630 | 642 | write_termination_message() |
631 | 643 |
|
|
0 commit comments