[PATCH 1/2] new option "--exclude-if-present" for bup-index

52 views
Skip to first unread message

t.riemen...@detco.de

unread,
Jul 8, 2012, 1:55:14 PM7/8/12
to t.riemen...@detco.de, bup-...@googlegroups.com, Tim Riemenschneider
From: Tim Riemenschneider <g...@tim-riemenschneider.de>

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 <g...@tim-riemenschneider.de>
---
Documentation/bup-index.md | 8 +++++++-
cmd/index-cmd.py | 4 +++-
lib/bup/drecurse.py | 15 +++++++++++----
t/test.sh | 17 +++++++++++++++++
4 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/Documentation/bup-index.md b/Documentation/bup-index.md
index 9591777..bedade6 100644
--- a/Documentation/bup-index.md
+++ b/Documentation/bup-index.md
@@ -10,7 +10,8 @@ bup-index - print and/or update the bup filesystem index

bup index \<-p|-m|-s|-u\> [-H] [-l] [-x] [\--fake-valid]
[\--fake-invalid] [\--check] [-f *indexfile*] [\--exclude *path*]
-[\--exclude-from *filename*] [-v] \<filenames...\>
+[\--exclude-from *filename*] [\--exclude-if-present *filename*]
+[-v] \<filenames...\>

# DESCRIPTION

@@ -114,6 +115,11 @@ need the same information).
: a file that contains exclude paths (can be used more
than once)

+\--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.
+
-v, \--verbose
: increase log output during update (can be used more
than once). With one `-v`, print each directory as it
diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py
index ff2c21f..50b8cd8 100755
--- a/cmd/index-cmd.py
+++ b/cmd/index-cmd.py
@@ -67,7 +67,8 @@ def update_index(top, excluded_paths):
bup_dir = os.path.abspath(git.repo())
for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev,
bup_dir=bup_dir,
- excluded_paths=excluded_paths):
+ excluded_paths=excluded_paths,
+ 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()
@@ -150,6 +151,7 @@ fake-invalid mark all index entries as invalid
f,indexfile= the name of the index file (normally BUP_DIR/bupindex)
exclude= a path to exclude from the backup (can be used more than once)
exclude-from= a file that contains exclude paths (can be used more than once)
+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 866045f..092f417 100644
--- a/lib/bup/drecurse.py
+++ b/lib/bup/drecurse.py
@@ -49,9 +49,13 @@ def _dirlist():
return l


-def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
+def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None,
+ exclude_if_present=None):
for (name,pst) in _dirlist():
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 xdev != None and pst.st_dev != xdev:
debug1('Skipping %r: different filesystem.\n' % (prepend+name))
continue
@@ -70,13 +74,15 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
else:
for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
bup_dir=bup_dir,
- excluded_paths=excluded_paths):
+ excluded_paths=excluded_paths,
+ exclude_if_present=exclude_if_present):
yield i
os.chdir('..')
yield (prepend + name, pst)


-def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
+def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
+ exclude_if_present=None):
startdir = OsFile('.')
try:
assert(type(paths) != type(''))
@@ -104,7 +110,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
prepend = os.path.join(path, '')
for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
bup_dir=bup_dir,
- excluded_paths=excluded_paths):
+ excluded_paths=excluded_paths,
+ exclude_if_present=exclude_if_present):
yield i
startdir.fchdir()
else:
diff --git a/t/test.sh b/t/test.sh
index 952141e..d8cafcf 100755
--- a/t/test.sh
+++ b/t/test.sh
@@ -347,6 +347,23 @@ b
f"
rm $EXCLUDE_FILE

+WVSTART "exclude-if-present"
+D=exclude-if-present.tmp
+rm -rf $D
+mkdir $D
+export BUP_DIR="$D/.bup"
+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"
+
WVSTART "strip"
D=strip.tmp
rm -rf $D
--
1.7.10.4

t.riemen...@detco.de

unread,
Jul 8, 2012, 2:01:19 PM7/8/12
to bup-...@googlegroups.com, Tim Riemenschneider

t.riemen...@detco.de

unread,
Jul 8, 2012, 2:01:20 PM7/8/12
to bup-...@googlegroups.com, Tim Riemenschneider
From: Tim Riemenschneider <g...@tim-riemenschneider.de>

Excludes all directories that contain a file CACHEDIR.TAG that begins with
"Signature: 8a477f597d28d172789f06886806bc55".

See http://www.brynosaurus.com/cachedir/ for more information about
cache-directory tagging.

Signed-off-by: Tim Riemenschneider <g...@tim-riemenschneider.de>
---
Documentation/bup-index.md | 8 +++++++-
cmd/index-cmd.py | 4 +++-
lib/bup/drecurse.py | 20 ++++++++++++++++----
t/test.sh | 17 +++++++++++++++++
4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/Documentation/bup-index.md b/Documentation/bup-index.md
index bedade6..8bfc9df 100644
--- a/Documentation/bup-index.md
+++ b/Documentation/bup-index.md
@@ -11,7 +11,7 @@ bup-index - print and/or update the bup filesystem index
bup index \<-p|-m|-s|-u\> [-H] [-l] [-x] [\--fake-valid]
[\--fake-invalid] [\--check] [-f *indexfile*] [\--exclude *path*]
[\--exclude-from *filename*] [\--exclude-if-present *filename*]
-[-v] \<filenames...\>
+[\--exclude-caches] [-v] \<filenames...\>

# DESCRIPTION

@@ -120,6 +120,12 @@ need the same information).
So you can "touch .do-not-backup-me" to exclude a directory
from backup.

+\--exclude-caches
+: exclude all directories that contain a file CACHEDIR.TAG, whose
+ content begins with "Signature: 8a477f597d28d172789f06886806bc55".
+ For more information on cachedir-tagging, see
+ http://www.brynosaurus.com/cachedir/
+
-v, \--verbose
: increase log output during update (can be used more
than once). With one `-v`, print each directory as it
diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py
index 50b8cd8..31c18b6 100755
--- a/cmd/index-cmd.py
+++ b/cmd/index-cmd.py
@@ -68,7 +68,8 @@ def update_index(top, excluded_paths):
for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev,
bup_dir=bup_dir,
excluded_paths=excluded_paths,
- exclude_if_present=opt['exclude-if-present']):
+ exclude_if_present=opt['exclude-if-present'],
+ exclude_caches=opt.exclude_caches):
if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
sys.stdout.write('%s\n' % path)
sys.stdout.flush()
@@ -152,6 +153,7 @@ f,indexfile= the name of the index file (normally BUP_DIR/bupindex)
exclude= a path to exclude from the backup (can be used more than once)
exclude-from= a file that contains exclude paths (can be used more than once)
exclude-if-present= exclude directory if the given file is present
+exclude-caches exclude CACHEDIR.TAG-directories
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 092f417..86aa95a 100644
--- a/lib/bup/drecurse.py
+++ b/lib/bup/drecurse.py
@@ -50,12 +50,22 @@ def _dirlist():


def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None,
- exclude_if_present=None):
+ exclude_if_present=None, exclude_caches=None):
for (name,pst) in _dirlist():
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 exclude_caches:
+ tag_filename = 'CACHEDIR.TAG'
+ tag_contents = 'Signature: 8a477f597d28d172789f06886806bc55'
+ if os.path.exists(prepend+name+tag_filename):
+ f = open(prepend+name+tag_filename, 'rb')
+ data = f.read(len(tag_contents))
+ f.close()
+ if data == tag_contents:
+ debug1('Skipping %r: excluding cache dir' % (prepend+name))
+ continue
if xdev != None and pst.st_dev != xdev:
debug1('Skipping %r: different filesystem.\n' % (prepend+name))
continue
@@ -75,14 +85,15 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None,
for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
bup_dir=bup_dir,
excluded_paths=excluded_paths,
- exclude_if_present=exclude_if_present):
+ exclude_if_present=exclude_if_present,
+ exclude_caches=exclude_caches):
yield i
os.chdir('..')
yield (prepend + name, pst)


def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
- exclude_if_present=None):
+ exclude_if_present=None,exclude_caches=None):
startdir = OsFile('.')
try:
assert(type(paths) != type(''))
@@ -111,7 +122,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_if_present=exclude_if_present):
+ exclude_if_present=exclude_if_present,
+ exclude_caches=exclude_caches):
yield i
startdir.fchdir()
else:
diff --git a/t/test.sh b/t/test.sh
index d8cafcf..96dd7f1 100755
--- a/t/test.sh
+++ b/t/test.sh
@@ -364,6 +364,23 @@ WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
b
f"

+WVSTART "exclude-caches"
+D=exclude-caches.tmp
+rm -rf $D
+mkdir $D
+export BUP_DIR="$D/.bup"
+WVPASS bup init
+touch $D/a
+WVPASS bup random 128k >$D/b
+mkdir $D/d $D/d/e
+WVPASS bup random 512 >$D/f
+echo 'Signature: 8a477f597d28d172789f06886806bc55' > $D/d/CACHEDIR.TAG
+WVPASS bup index -ux --exclude-caches $D
Reply all
Reply to author
Forward
0 new messages