From 1cc37e1ac88c7f932fce59dbdaa8d98e1d139a59 Mon Sep 17 00:00:00 2001 From: Martin Pihlak Date: Tue, 27 Jul 2010 10:54:24 +0300 Subject: [PATCH] Introduce a 'backup_datadir' configuration variable to control whether the slave data directory is kept or overwritten during restore. Patch from Steve Singer. --- doc/walmgr.txt | 9 ++++++++- python/conf/wal-slave.ini | 1 + python/walmgr.py | 14 ++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/walmgr.txt b/doc/walmgr.txt index c1390d75..62d263af 100644 --- a/doc/walmgr.txt +++ b/doc/walmgr.txt @@ -273,6 +273,13 @@ Backups will be named data.master, data.master.0, data.master.1 etc. Script to execute before rotating away the oldest backup. If it fails backups will not be rotated. + +==== backup_datadir ==== +Set backup_datadir to 'no' to prevent walmgr.py from making a backup +of the data directory when restoring to the slave. This defaults to +'yes' + + === Sample slave.ini === [wal-slave] @@ -285,4 +292,4 @@ backups will not be rotated. partial_wals = %(slave)s/logs.partial full_backup = %(slave)s/data.master keep_backups = 5 - + backup_datadir = yes diff --git a/python/conf/wal-slave.ini b/python/conf/wal-slave.ini index 7f60ce6f..9e6b3337 100644 --- a/python/conf/wal-slave.ini +++ b/python/conf/wal-slave.ini @@ -15,5 +15,6 @@ partial_wals = %(slave)s/logs.partial full_backup = %(slave)s/data.master config_backup = %(slave)s/config.backup +backup_datadir = yes keep_backups = 0 archive_command = diff --git a/python/walmgr.py b/python/walmgr.py index d880ef87..81a2e0b1 100755 --- a/python/walmgr.py +++ b/python/walmgr.py @@ -1246,7 +1246,7 @@ STOP TIME: %(stop_time)s If setname is specified, the contents of that backup set directory are restored instead of "full_backup". Also copy is used instead of rename to - restore the directory. + restore the directory (unless a pg_xlog directory has been specified). Restore to altdst if specified. Complain if it exists. """ @@ -1305,9 +1305,15 @@ STOP TIME: %(stop_time)s # nothing to back up createbackup = False - if not setname and os.path.isdir(data_dir): - # compatibility mode - restore without a set name and data directory - # already exists. Move it out of the way. + # see if we have to make a backup of the data directory + backup_datadir = self.cf.getboolean('backup_datadir', True) + + if os.path.isdir(data_dir) and not backup_datadir: + self.log.warning('backup_datadir is disabled, deleting old data dir') + shutil.rmtree(data_dir) + + if not setname and os.path.isdir(data_dir) and backup_datadir: + # compatibility mode - restore without a set name and data directory exists self.log.warning("Data directory already exists, moving it out of the way.") createbackup = True -- 2.39.5