From 526a04b4e601c80c5b6ab69a455babf1e775773f Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 9 Jun 2022 11:37:41 -0700 Subject: [PATCH] restore-backup: Provide flags to leave settings.py and zulip.conf as-is. --- docs/production/export-and-import.md | 14 ++++++++++++++ scripts/setup/restore-backup | 24 +++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docs/production/export-and-import.md b/docs/production/export-and-import.md index c9d5a7f97c..6c0ae15e5d 100644 --- a/docs/production/export-and-import.md +++ b/docs/production/export-and-import.md @@ -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 diff --git a/scripts/setup/restore-backup b/scripts/setup/restore-backup index 0f96bea12f..ab05163820 100755 --- a/scripts/setup/restore-backup +++ b/scripts/setup/restore-backup @@ -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)