From: Tim Riemenschneider Date: Thu, 21 Mar 2013 00:16:42 +0000 (+0100) Subject: new option "--exclude-if-present" for bup-index X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=c2f1d13c98ae16384aa8b720922020e36a135ee4;p=packages%2Fb%2Fbup.git new option "--exclude-if-present" for bup-index Excludes all directories that contain a file with the specified name. So you can use "touch .do-not-backup-me" to exclude a directory from backup, when you run bup index with "--exclude-if-present .do-not-backup-me" Signed-off-by: Tim Riemenschneider --- diff --git a/Documentation/bup-index.md b/Documentation/bup-index.md index d85d179..75506a2 100644 --- a/Documentation/bup-index.md +++ b/Documentation/bup-index.md @@ -11,7 +11,8 @@ bup-index - print and/or update the bup filesystem index bup index \<-p|-m|-s|-u|\--clear|\--check\> [-H] [-l] [-x] [\--fake-valid] [\--no-check-device] [\--fake-invalid] [-f *indexfile*] [\--exclude *path*] [\--exclude-from *filename*] [\--exclude-rx *pattern*] -[\--exclude-rx-from *filename*] [-v] \ +[\--exclude-rx-from *filename*] [\--exclude-if-present *filename*] +[-v] \ # DESCRIPTION @@ -182,6 +183,11 @@ does, due to the accommodations described above. : read --exclude-rx patterns from *filename*, one pattern per-line (may be repeated). Ignore completely empty lines. +\--exclude-if-present=*filename* +: exclude all directories that contain the specified file. + So you can "touch .do-not-backup-me" to exclude a directory + from backup. + \--no-check-device : don't mark a an entry invalid if the device number (stat(2) st_dev) changes. This can be useful when indexing remote, diff --git a/Makefile b/Makefile index 988a9cc..521fed0 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,7 @@ cmdline_tests := \ t/test-ls.sh \ t/test-meta.sh \ t/test-on.sh \ + t/test-index-excludes.sh \ t/test-restore-map-owner.sh \ t/test-restore-single-file.sh \ t/test-rm-between-index-and-save.sh \ diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index 6f2adf4..4354eec 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -84,7 +84,8 @@ def update_index(top, excluded_paths, exclude_rxs): for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev, bup_dir=bup_dir, excluded_paths=excluded_paths, - exclude_rxs=exclude_rxs): + exclude_rxs=exclude_rxs, + exclude_if_present=opt['exclude-if-present']): if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)): sys.stdout.write('%s\n' % path) sys.stdout.flush() @@ -205,6 +206,7 @@ exclude= a path to exclude from the backup (may be repeated) exclude-from= skip --exclude paths in file (may be repeated) exclude-rx= skip paths matching the unanchored regex (may be repeated) exclude-rx-from= skip --exclude-rx patterns in file (may be repeated) +exclude-if-present= exclude directory if the given file is present v,verbose increase log output (can be used more than once) x,xdev,one-file-system don't cross filesystem boundaries """ diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py index 6be7fa2..61da2c5 100644 --- a/lib/bup/drecurse.py +++ b/lib/bup/drecurse.py @@ -51,7 +51,8 @@ def _dirlist(): def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None, - exclude_rxs=None): + exclude_rxs=None, + exclude_if_present=None): for (name,pst) in _dirlist(): path = prepend + name if excluded_paths: @@ -61,6 +62,9 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, if exclude_rxs and should_rx_exclude_path(path, exclude_rxs): continue if name.endswith('/'): + if exclude_if_present != None and os.path.exists(prepend+name+exclude_if_present): + debug1('Skipping %r: exclude-file present.\n' % (prepend+name)) + continue if bup_dir != None: if os.path.normpath(path) == bup_dir: debug1('Skipping BUP_DIR.\n') @@ -76,14 +80,16 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev, bup_dir=bup_dir, excluded_paths=excluded_paths, - exclude_rxs=exclude_rxs): + exclude_rxs=exclude_rxs, + exclude_if_present=exclude_if_present): yield i os.chdir('..') yield (path, pst) def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None, - exclude_rxs=None): + exclude_rxs=None, + exclude_if_present=None): startdir = OsFile('.') try: assert(type(paths) != type('')) @@ -112,7 +118,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None, for i in _recursive_dirlist(prepend=prepend, xdev=xdev, bup_dir=bup_dir, excluded_paths=excluded_paths, - exclude_rxs=exclude_rxs): + exclude_rxs=exclude_rxs, + exclude_if_present=exclude_if_present): yield i startdir.fchdir() else: diff --git a/t/test-index-excludes.sh b/t/test-index-excludes.sh new file mode 100755 index 0000000..5b89d2e --- /dev/null +++ b/t/test-index-excludes.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +. ./wvtest-bup.sh +. t/lib.sh + +top="$(pwd)" +bup() { "$top/bup" "$@"; } + +WVSTART "exclude-if-present" +( + set -e -o pipefail + D="$(wvmktempdir)" + export BUP_DIR="$D/.bup" + force-delete $D + mkdir $D + WVPASS bup init + touch $D/a + WVPASS bup random 128k >$D/b + mkdir $D/d $D/d/e + WVPASS bup random 512 >$D/f + touch $D/d/exclude-file + WVPASS bup index -ux --exclude-if-present exclude-file $D + bup save -n exclude $D + WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a +b +f" + rm -rf "$D" +) || WVFAIL