mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		@@ -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",
 | 
			
		||||
                ]
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        # 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")])
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user