mirror of https://github.com/zulip/zulip.git
restore-backup: Run zulip-puppet-apply before pg_restore.
This should ensure that we apply any special configuration for the database system (e.g. installing `pgroonga`) before we try to restore the database contents from the archive. For pgroonga in particular, this is important so that we can preserve the configuration of the extension in the `pg_restore` process. Fixes #12345.
This commit is contained in:
parent
d1d06af2c6
commit
3c4030a421
|
@ -78,7 +78,8 @@ def restore_backup(tarball_file):
|
||||||
tarball_file.seek(0, 0)
|
tarball_file.seek(0, 0)
|
||||||
run(["tar", "-C", tmp] + transform_args + ["-xPz"], stdin=tarball_file)
|
run(["tar", "-C", tmp] + transform_args + ["-xPz"], stdin=tarball_file)
|
||||||
|
|
||||||
# Now, restore the the database backup using pg_restore.
|
# Now, extract the the database backup, destroy the old
|
||||||
|
# database, and create a new, empty database.
|
||||||
db_name = settings.DATABASES["default"]["NAME"]
|
db_name = settings.DATABASES["default"]["NAME"]
|
||||||
assert isinstance(db_name, str)
|
assert isinstance(db_name, str)
|
||||||
db_dir = os.path.join(tmp, "zulip-backup", "database")
|
db_dir = os.path.join(tmp, "zulip-backup", "database")
|
||||||
|
@ -97,22 +98,26 @@ def restore_backup(tarball_file):
|
||||||
as_postgres = ["su", "-s", "/usr/bin/env", "-", "--", POSTGRES_USER]
|
as_postgres = ["su", "-s", "/usr/bin/env", "-", "--", POSTGRES_USER]
|
||||||
run(as_postgres + ["dropdb", "--if-exists", "--", db_name])
|
run(as_postgres + ["dropdb", "--if-exists", "--", db_name])
|
||||||
run(as_postgres + ["createdb", "-O", "zulip", "-T", "template0", "--", db_name])
|
run(as_postgres + ["createdb", "-O", "zulip", "-T", "template0", "--", db_name])
|
||||||
run(as_postgres + ["pg_restore", "-d", db_name, "--", db_dir])
|
|
||||||
run(["chown", "-R", str(uid), "--", tmp])
|
|
||||||
os.setresuid(uid, uid, 0)
|
|
||||||
|
|
||||||
# In production, we also need to do a `zulip-puppet-apply` in
|
# In production, we also need to do a `zulip-puppet-apply` in
|
||||||
# order to adjust any configuration from /etc/zulip/zulip.conf
|
# order to adjust any configuration from /etc/zulip/zulip.conf
|
||||||
# to this system.
|
# to this system.
|
||||||
if settings.PRODUCTION:
|
if settings.PRODUCTION:
|
||||||
os.setresuid(0, 0, 0)
|
|
||||||
run(
|
run(
|
||||||
[
|
[
|
||||||
os.path.join(settings.DEPLOY_ROOT, "scripts", "zulip-puppet-apply"),
|
os.path.join(settings.DEPLOY_ROOT, "scripts", "zulip-puppet-apply"),
|
||||||
"-f",
|
"-f",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Now, restore the the database backup using pg_restore. This
|
||||||
|
# needs to run after zulip-puppet-apply to ensure full-text
|
||||||
|
# search extensions are available and installed.
|
||||||
|
run(as_postgres + ["pg_restore", "-d", db_name, "--", db_dir])
|
||||||
|
run(["chown", "-R", str(uid), "--", tmp])
|
||||||
os.setresuid(uid, uid, 0)
|
os.setresuid(uid, uid, 0)
|
||||||
|
|
||||||
|
if settings.PRODUCTION:
|
||||||
run(["supervisorctl", "restart", "all"])
|
run(["supervisorctl", "restart", "all"])
|
||||||
|
|
||||||
run([os.path.join(settings.DEPLOY_ROOT, "scripts", "setup", "flush-memcached")])
|
run([os.path.join(settings.DEPLOY_ROOT, "scripts", "setup", "flush-memcached")])
|
||||||
|
|
Loading…
Reference in New Issue