diff --git a/scripts/setup/restore-backup b/scripts/setup/restore-backup index 03815a7a1a..8dce08b263 100755 --- a/scripts/setup/restore-backup +++ b/scripts/setup/restore-backup @@ -78,7 +78,8 @@ def restore_backup(tarball_file): tarball_file.seek(0, 0) 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"] assert isinstance(db_name, str) 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] run(as_postgres + ["dropdb", "--if-exists", "--", 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 # order to adjust any configuration from /etc/zulip/zulip.conf # to this system. if settings.PRODUCTION: - os.setresuid(0, 0, 0) run( [ os.path.join(settings.DEPLOY_ROOT, "scripts", "zulip-puppet-apply"), "-f", ] ) - os.setresuid(uid, uid, 0) + + # 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) + + if settings.PRODUCTION: run(["supervisorctl", "restart", "all"]) run([os.path.join(settings.DEPLOY_ROOT, "scripts", "setup", "flush-memcached")])