pg_backup_and_purge: Fix buggy recovery status parsing.

This was converted to Python 3 incorrectly, in a way that actually
completely broke the script (the .decode() that this adds is critical,
since 'f' != b'f').

We fix this, and also add an assert that makes the parsing code
safer against future refactors.
This commit is contained in:
Tim Abbott 2018-08-09 11:46:19 -07:00
parent 49528a98eb
commit db1f706d09
1 changed files with 5 additions and 2 deletions

View File

@ -30,8 +30,11 @@ def run(args, dry_run=False):
sys.exit(1) sys.exit(1)
return stdout return stdout
# Only run if we're the master recovery_val = run(['psql', '-t', '-c', 'select pg_is_in_recovery()']).strip().decode()
if run(['psql', '-t', '-c', 'select pg_is_in_recovery()']).strip() != 'f': # Assertion to check that we're extracting the value correctly.
assert recovery_val in ['t', 'f']
if recovery_val == 't':
# Only run if we're the master
sys.exit(0) sys.exit(0)
pg_data_paths = glob.glob('/var/lib/postgresql/*/main') pg_data_paths = glob.glob('/var/lib/postgresql/*/main')