From 68cb99a934a229b8be0b85f6ef72c8212df623aa Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Wed, 31 Jan 2024 12:35:44 +0100 Subject: [PATCH] Run generate.py --- 10/backup.py | 10 +++++++++- 10/restore.py | 2 +- 11/backup.py | 10 +++++++++- 11/restore.py | 2 +- 12/backup.py | 10 +++++++++- 12/restore.py | 2 +- 13/backup.py | 10 +++++++++- 13/restore.py | 2 +- 14/backup.py | 10 +++++++++- 14/restore.py | 2 +- 15/backup.py | 10 +++++++++- 15/restore.py | 2 +- 16/backup.py | 10 +++++++++- 16/restore.py | 2 +- template/restore.py | 2 +- 15 files changed, 71 insertions(+), 15 deletions(-) diff --git a/10/backup.py b/10/backup.py index 598b7bd..c4bf67c 100644 --- a/10/backup.py +++ b/10/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/10/restore.py b/10/restore.py index ed5eadb..4ce1d26 100644 --- a/10/restore.py +++ b/10/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/11/backup.py b/11/backup.py index 598b7bd..c4bf67c 100644 --- a/11/backup.py +++ b/11/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/11/restore.py b/11/restore.py index ed5eadb..4ce1d26 100644 --- a/11/restore.py +++ b/11/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/12/backup.py b/12/backup.py index 598b7bd..c4bf67c 100644 --- a/12/backup.py +++ b/12/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/12/restore.py b/12/restore.py index ed5eadb..4ce1d26 100644 --- a/12/restore.py +++ b/12/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/13/backup.py b/13/backup.py index 598b7bd..c4bf67c 100644 --- a/13/backup.py +++ b/13/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/13/restore.py b/13/restore.py index ed5eadb..4ce1d26 100644 --- a/13/restore.py +++ b/13/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/14/backup.py b/14/backup.py index 598b7bd..c4bf67c 100644 --- a/14/backup.py +++ b/14/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/14/restore.py b/14/restore.py index ed5eadb..4ce1d26 100644 --- a/14/restore.py +++ b/14/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/15/backup.py b/15/backup.py index 598b7bd..c4bf67c 100644 --- a/15/backup.py +++ b/15/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/15/restore.py b/15/restore.py index ed5eadb..4ce1d26 100644 --- a/15/restore.py +++ b/15/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/16/backup.py b/16/backup.py index 598b7bd..c4bf67c 100644 --- a/16/backup.py +++ b/16/backup.py @@ -33,6 +33,7 @@ WEBHOOK_CURL_OPTIONS = os.environ.get("WEBHOOK_CURL_OPTIONS") or "" KEEP_BACKUP_DAYS = int(os.environ.get("KEEP_BACKUP_DAYS", 7)) FILENAME = os.environ.get("FILENAME", DB_NAME + "_%Y-%m-%d") +PG_DUMP_EXTRA_OPTIONS = os.environ.get("PG_DUMP_EXTRA_OPTIONS") or "" file_name = dt.strftime(FILENAME) backup_file = os.path.join(BACKUP_DIR, file_name) @@ -69,7 +70,14 @@ def take_backup(): env.update({'PGPASSWORD': DB_PASS, 'PGHOST': DB_HOST, 'PGUSER': DB_USER, 'PGDATABASE': DB_NAME, 'PGPORT': DB_PORT}) # trigger postgres-backup - cmd("pg_dump -Fc > %s" % backup_file, env=env) + command = [ + "pg_dump", + "-Fc", + ] + if PG_DUMP_EXTRA_OPTIONS: + command.append(PG_DUMP_EXTRA_OPTIONS) + command.append("> %s" % backup_file) + cmd(" ".join(command), env=env) def upload_backup(): opts = "--storage-class=%s %s" % (S3_STORAGE_CLASS, S3_EXTRA_OPTIONS) diff --git a/16/restore.py b/16/restore.py index ed5eadb..4ce1d26 100644 --- a/16/restore.py +++ b/16/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output, + e.output.decode(), "-"*80, "" ])) diff --git a/template/restore.py b/template/restore.py index aca53b6..4ce1d26 100644 --- a/template/restore.py +++ b/template/restore.py @@ -35,7 +35,7 @@ def cmd(command, **kwargs): sys.stderr.write("\n".join([ "Command execution failed. Output:", "-"*80, - e.output.decode("utf-8"), + e.output.decode(), "-"*80, "" ]))