Introduce a 'backup_datadir' configuration variable to
authorMartin Pihlak <martin.pihlak@gmail.com>
Tue, 27 Jul 2010 07:54:24 +0000 (10:54 +0300)
committerMartin Pihlak <martin.pihlak@gmail.com>
Tue, 27 Jul 2010 07:57:22 +0000 (10:57 +0300)
control whether the slave data directory is kept or
overwritten during restore. Patch from Steve Singer.

doc/walmgr.txt
python/conf/wal-slave.ini
python/walmgr.py

index c1390d7543aa61aaa6a39d0b4cceae8cddd3d3a2..62d263af42c25fb4900fc7ff988107582edfed58 100644 (file)
@@ -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
index 7f60ce6fe83e6042d3bd38821d775db69c70d0bf..9e6b333710e827a252f893bfd5805572aa8a6871 100644 (file)
@@ -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 =
index d880ef8770067666e1786102242ed2a2542a7a58..81a2e0b1720176064f17ec6af8b8d2dd0f68d14d 100755 (executable)
@@ -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