From d8d9da12ffb3cea645010c1df4d1f709b2f5c976 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Tue, 19 May 2015 14:33:13 +0200 Subject: [PATCH] save/restore both postgresql.conf and pg_hba.conf for WAL-e backup. --- helpers/postgresql.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/helpers/postgresql.py b/helpers/postgresql.py index a2528ca6..0a837640 100644 --- a/helpers/postgresql.py +++ b/helpers/postgresql.py @@ -45,7 +45,7 @@ class Postgresql: self.superuser = config['superuser'] self.admin = config['admin'] self.recovery_conf = os.path.join(self.data_dir, 'recovery.conf') - self.postgresql_conf = os.path.join(self.data_dir, 'postgresql.conf') + self.configuration_to_save = (os.path.join(self.data_dir, 'pg_hba.conf'), os.path.join(self.data_dir, 'postgresql.conf')) self._pg_ctl = 'pg_ctl -w -D ' + self.data_dir self._wal_e = 'envdir {} wal-e --aws-instance-profile '.format(os.environ.get('WALE_ENV_DIR', '/home/postgres/etc/wal-e.d/env')) @@ -126,8 +126,7 @@ class Postgresql: def create_replica_with_s3(self): ret = os.system(self._wal_e + ' backup-fetch {} LATEST'.format(self.data_dir)) - self.restore_postgresql_conf() - self.write_pg_hba() + self.restore_configuration_files() return ret @@ -209,7 +208,7 @@ class Postgresql: ret = os.system(self._pg_ctl + ' start -o "{}"'.format(self.server_options())) == 0 ret and self.load_replication_slots() - self.save_postgresql_conf() + self.save_configuration_files() return ret def stop(self): @@ -308,19 +307,21 @@ primary_conninfo = '{}' self.write_recovery_conf(leader) self.restart() - def save_postgresql_conf(self): + def save_configuration_files(self): """ copy postgresql.conf to postgresql.conf.backup to preserve it in the WAL-e backup. see http://comments.gmane.org/gmane.comp.db.postgresql.wal-e/239 """ - shutil.copy(self.postgresql_conf, self.postgresql_conf+'.backup') + for f in self.configuration_to_save: + shutil.copy(f, f+'.backup') - def restore_postgresql_conf(self): + def restore_configuration_files(self): """ restore a previously saved postgresql.conf """ try: - shutil.copy(self.postgresql_conf+'.backup', self.postgresql_conf) + for f in self.configuration_to_save: + shutil.copy(f+'.backup', f) except Exception as e: - logger.error("unable to restore postgresql.conf from WAL-E backup: {}".format(e)) + logger.error("unable to restore configuration from WAL-E backup: {}".format(e)) def promote(self): return os.system(self._pg_ctl + ' promote') == 0