ExcludeIfPresent

From RdiffBackupWiki

Jump to: navigation, search

Overview

This patch adds the --exclude-if-present option to allow users to specify that a directory should not be backed up. It has been tested with 1.0.4 and 1.0.5.

Example

$ ls -a /tmp/test1/
.  ..  file1  test2  test4
$ ls -a /tmp/test1/test2
.  ..  file1  .NOBACKUP  test3
$ rdiff-backup --exclude-if-present .NOBACKUP /tmp/test1 /tmp/backup_test
$ ls -a /tmp/backup_test/
file1              rdiff-backup-data/ test4/

Patch

rdiff-backup-presence.diff

Only in ./: build
diff -r -u ../rdiff-backup-1.0.5-orig/rdiff_backup/Main.py ./rdiff_backup/Main.py
--- ../rdiff-backup-1.0.5-orig/rdiff_backup/Main.py	2006-11-12 01:32:01.000000000 -0600
+++ ./rdiff_backup/Main.py	2007-03-13 11:06:34.000000000 -0500
@@ -62,7 +62,7 @@
 		  "exclude-symbolic-links", "exclude-sockets",
 		  "exclude-filelist-stdin", "exclude-globbing-filelist=",
 		  "exclude-globbing-filelist-stdin", "exclude-mirror=",
-		  "exclude-other-filesystems", "exclude-regexp=",
+		  "exclude-other-filesystems", "exclude-regexp=", "exclude-if-present=",
 		  "exclude-special-files", "force", "group-mapping-file=",
 		  "include=", "include-filelist=", "include-filelist-stdin",
 		  "include-globbing-filelist=",
@@ -99,6 +99,7 @@
 			  opt == "--exclude-fifos" or
 			  opt == "--exclude-other-filesystems" or
 			  opt == "--exclude-regexp" or
+			  opt == "--exclude-if-present" or
 			  opt == "--exclude-special-files" or
 			  opt == "--exclude-sockets" or
 			  opt == "--exclude-symbolic-links"):
diff -r -u ../rdiff-backup-1.0.5-orig/rdiff_backup/selection.py ./rdiff_backup/selection.py
--- ../rdiff-backup-1.0.5-orig/rdiff_backup/selection.py	2006-11-12 01:32:01.000000000 -0600
+++ ./rdiff_backup/selection.py	2007-03-15 08:53:28.000000000 -0500
@@ -234,6 +234,8 @@
 			for opt, arg in argtuples:
 				if opt == "--exclude":
 					self.add_selection_func(self.glob_get_sf(arg, 0))
+				elif opt == "--exclude-if-present":
+					self.add_selection_func(self.presence_get_sf(arg, 0))
 				elif opt == "--exclude-device-files":
 					self.add_selection_func(self.devfiles_get_sf(0))
 				elif opt == "--exclude-symbolic-links":
@@ -467,6 +469,18 @@
 		sel_func.name = "Regular expression: %s" % regexp_string
 		return sel_func
 
+	def presence_get_sf(self, presence_filename, include):
+		"""Return selection function given by a file if present"""
+		assert include == 0 or include == 1
+
+		def sel_func(rp):
+			if rp.isdir() and rp.readable() and rp.append(presence_filename).isreg(): return include
+			return None
+
+		sel_func.exclude = not include
+		sel_func.name = "Presence file: %s" % presence_filename
+		return sel_func
+
 	def gen_get_sf(self, pred, include, name):
 		"""Returns a selection function that uses pred to test
 		
diff -r -u ../rdiff-backup-1.0.5-orig/rdiff-backup.1 ./rdiff-backup.1
--- ../rdiff-backup-1.0.5-orig/rdiff-backup.1	2006-11-12 01:32:01.000000000 -0600
+++ ./rdiff-backup.1	2007-03-15 17:28:11.000000000 -0500
@@ -165,6 +165,12 @@
 .B "--exclude-symbolic-links"
 Exclude all symbolic links.
 .TP
+.BI "--exclude-if-present " filename
+Exclude directories if
+.IR filename
+is present. This option needs to come before any other include or
+exclude options.
+.TP
 .B --force
 Authorize a more drastic modification of a directory than usual (for
 instance, when overwriting of a destination path, or when removing

Jeff Strunk 09:29, 16 March 2007 (EST)

Personal tools