Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Alex Vandiver526a04b4e601
diff --git a/docs/production/export-and-import.md b/docs/production/export-and-import.md
index c9d5a7f97c7..6c0ae15e5d8 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 0f96bea12f2..ab051638203 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)