restore-backup: Provide flags to leave settings.py and zulip.conf as-is.

This commit is contained in:
Alex Vandiver 2022-06-09 11:37:41 -07:00 committed by Tim Abbott
parent 35e9e4cd3b
commit 526a04b4e6
2 changed files with 35 additions and 3 deletions

View File

@ -106,6 +106,20 @@ Until you do, your Zulip server will think its user-facing hostname is
still `zulip.example.com` and will return HTTP `400 BAD REQUEST`
errors when trying to access it via `zuliptest.example.com`.
#### Changing database settings
If you wish to restore onto a very differently configured host (e.g. with
`REMOTE_POSTGRES_HOST` set to a different value), you can edit
`/etc/zulip/settings.py` to configure the host to suit the new host's needs,
then restore with `--keep-settings`:
```bash
/home/zulip/deployments/current/scripts/setup/restore-backup --keep-settings /path/to/backup
```
You can also pass `--keep-zulipconf` if you wish to preserve the local
`/etc/zulip/zulip.conf`.
#### Inspecting a backup tarball
If you're not sure what versions were in use when a given backup was

View File

@ -15,9 +15,15 @@ POSTGRES_PWENT = get_postgres_pwent()
parser = argparse.ArgumentParser()
parser.add_argument("tarball", help="Filename of input tarball")
parser.add_argument(
"--keep-settings", help="Do not overwrite local /etc/zulip/settings.py", action="store_true"
)
parser.add_argument(
"--keep-zulipconf", help="Do not overwrite local /etc/zulip/zulip.conf", action="store_true"
)
def restore_backup(tarball_file: IO[bytes]) -> None:
def restore_backup(tarball_file: IO[bytes], keep_settings: bool, keep_zulipconf: bool) -> None:
assert_running_as_root()
su_to_zulip(save_suid=True)
@ -31,8 +37,20 @@ def restore_backup(tarball_file: IO[bytes]) -> None:
# next). Ignore errors if zulip-backup/settings is not present
# (E.g. because this is a development backup).
tarball_file.seek(0, 0)
excludes = []
if keep_settings:
excludes += ["--exclude=settings.py"]
if keep_zulipconf:
excludes += ["--exclude=zulip.conf"]
run(
["tar", "--directory=/etc/zulip", "--strip-components=2", "-xz", "zulip-backup/settings"],
[
"tar",
"--directory=/etc/zulip",
*excludes,
"--strip-components=2",
"-xz",
"zulip-backup/settings",
],
stdin=tarball_file,
)
@ -154,4 +172,4 @@ if __name__ == "__main__":
args = parser.parse_args()
with open(args.tarball, "rb") as tarball_file:
restore_backup(tarball_file)
restore_backup(tarball_file, args.keep_settings, args.keep_zulipconf)