backup: Set cwd while running pg_dump.

This avoids a spurious permission error inside the Postgres
`resolve_symlinks` function if we don’t have access to the current
working directory (e.g. we’re running with cwd /root inside `su
zulip`).

While we’re here, add a defensive `--` argument.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2019-02-28 21:48:41 +00:00 committed by Tim Abbott
parent bc3b864754
commit c6e60ebf0e
1 changed files with 4 additions and 1 deletions

View File

@ -64,7 +64,10 @@ class Command(ZulipBaseCommand):
db_name = settings.DATABASES["default"]["NAME"]
db_dir = os.path.join(tmp, "zulip-backup", "database")
run(["pg_dump", "--format=directory", db_name, "--file", db_dir])
run(
["pg_dump", "--format=directory", "--file", db_dir, "--", db_name],
cwd=tmp,
)
members.append("zulip-backup/database")
if settings.LOCAL_UPLOADS_DIR is not None and os.path.exists(