backup: Only pass --host and --port if non-empty.

This works around the `/usr/bin/pg_dump` failure described in the
previous commit.  Since we are now calling the appropriately-versioned
`pg_dump` binary directly, it is no longer "necessary", but is added
as a defense-in-depth.
This commit is contained in:
Alex Vandiver
2023-10-10 20:53:53 +00:00
committed by Tim Abbott
parent 9167b3efd7
commit a7b8e4795d

View File

@@ -72,12 +72,15 @@ class Command(ZulipBaseCommand):
f"/usr/lib/postgresql/{major_pg_version}/bin/pg_dump",
"--format=directory",
"--file=" + os.path.join(tmp, "zulip-backup", "database"),
"--host=" + settings.DATABASES["default"]["HOST"],
"--port=" + settings.DATABASES["default"]["PORT"],
"--username=" + settings.DATABASES["default"]["USER"],
"--dbname=" + settings.DATABASES["default"]["NAME"],
"--no-password",
]
if settings.DATABASES["default"]["HOST"] != "":
pg_dump_command += ["--host=" + settings.DATABASES["default"]["HOST"]]
if settings.DATABASES["default"]["PORT"] != "":
pg_dump_command += ["--port=" + settings.DATABASES["default"]["PORT"]]
os.environ["PGPASSWORD"] = settings.DATABASES["default"]["PASSWORD"]
run(