]> arthur.barton.de Git - bup.git/commitdiff
Adds --exclude option to bup index and bup drecurse
authorZoran Zaric <zz@zoranzaric.de>
Thu, 2 Dec 2010 06:24:11 +0000 (07:24 +0100)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 2 Dec 2010 07:30:16 +0000 (23:30 -0800)
Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
cmd/drecurse-cmd.py
cmd/index-cmd.py
lib/bup/drecurse.py
t/test.sh

index 99780af7a33bbaff35e96c6d818a89d16f95b8a3..74249c993b8be352525131faa150f6024a053e82 100755 (executable)
@@ -6,6 +6,7 @@ optspec = """
 bup drecurse <path>
 --
 x,xdev,one-file-system   don't cross filesystem boundaries
+exclude= a comma-seperated list of paths to exclude from the backup
 q,quiet  don't actually print filenames
 profile  run under the python profiler
 """
@@ -15,7 +16,12 @@ o = options.Options('bup drecurse', optspec)
 if len(extra) != 1:
     o.fatal("exactly one filename expected")
 
-it = drecurse.recursive_dirlist(extra, opt.xdev)
+if opt.exclude:
+    excluded_paths = [realpath(x) for x in opt.exclude.split(",")]
+else:
+    excluded_paths = None
+
+it = drecurse.recursive_dirlist(extra, opt.xdev, excluded_paths)
 if opt.profile:
     import cProfile
     def do_it():
index 38ffe4d4b5c954f11791477328eb788ec8aa0877..c78dc76dc152b63fcfa7570f87d560929c11a8be 100755 (executable)
@@ -54,7 +54,7 @@ def check_index(reader):
     log('check: passed.\n')
 
 
-def update_index(top):
+def update_index(top, excluded_paths):
     ri = index.Reader(indexfile)
     wi = index.Writer(indexfile)
     rig = IterHelper(ri.iter(name=top))
@@ -68,7 +68,8 @@ def update_index(top):
     total = 0
     bup_dir = os.path.abspath(git.repo())
     for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev,
-                                                 bup_dir=bup_dir):
+                                                 bup_dir=bup_dir,
+                                                 excluded_paths=excluded_paths):
         if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
             sys.stdout.write('%s\n' % path)
             sys.stdout.flush()
@@ -130,6 +131,7 @@ fake-valid mark all index entries as up-to-date even if they aren't
 fake-invalid mark all index entries as invalid
 check      carefully check index file integrity
 f,indexfile=  the name of the index file (normally BUP_DIR/bupindex)
+exclude=   a path to exclude from the backup (can be used ore than once)
 v,verbose  increase log output (can be used more than once)
 """
 o = options.Options('bup index', optspec)
@@ -151,13 +153,22 @@ if opt.check:
     log('check: starting initial check.\n')
     check_index(index.Reader(indexfile))
 
+if opt.exclude:
+    excluded_paths = []
+    for flag in flags:
+        (option, parameter) = flag
+        if option == '--exclude':
+            excluded_paths.append(realpath(parameter))
+else:
+    excluded_paths = None
+
 paths = index.reduce_paths(extra)
 
 if opt.update:
     if not extra:
         o.fatal('update (-u) requested but no paths given')
     for (rp,path) in paths:
-        update_index(rp)
+        update_index(rp, excluded_paths)
 
 if opt['print'] or opt.status or opt.modified:
     for (name, ent) in index.Reader(indexfile).filter(extra or ['']):
index d4c4d4cf00131a9b6d66988028374dad953aa9b8..879ba5a522fc64464bf43ec4d5545558c7ef362b 100644 (file)
@@ -45,7 +45,7 @@ def _dirlist():
     return l
 
 
-def _recursive_dirlist(prepend, xdev, bup_dir=None):
+def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
     for (name,pst) in _dirlist():
         if name.endswith('/'):
             if xdev != None and pst.st_dev != xdev:
@@ -55,19 +55,24 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None):
                 if os.path.normpath(prepend+name) == bup_dir:
                     log('Skipping BUP_DIR.\n')
                     continue
+            if excluded_paths:
+                if os.path.normpath(prepend+name) in excluded_paths:
+                    log('Skipping %r: excluded.\n' % (prepend+name))
+                    continue
             try:
                 OsFile(name).fchdir()
             except OSError, e:
                 add_error('%s: %s' % (prepend, e))
             else:
                 for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
-                                            bup_dir=bup_dir):
+                                            bup_dir=bup_dir,
+                                            excluded_paths=excluded_paths):
                     yield i
                 os.chdir('..')
         yield (prepend + name, pst)
 
 
-def recursive_dirlist(paths, xdev, bup_dir=None):
+def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
     startdir = OsFile('.')
     try:
         assert(type(paths) != type(''))
@@ -94,7 +99,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None):
                 pfile.fchdir()
                 prepend = os.path.join(path, '')
                 for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
-                                            bup_dir=bup_dir):
+                                            bup_dir=bup_dir,
+                                            excluded_paths=excluded_paths):
                     yield i
                 startdir.fchdir()
             else:
index cbc7f42620255027ff2bee50338198c68cd4b1e6..233e4b41cec1415b5211195bed963d581780a58b 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -244,7 +244,7 @@ else
 fi
 
 WVSTART "exclude-bupdir"
-D=exclude.tmp
+D=exclude-bupdir.tmp
 rm -rf $D
 mkdir $D
 export BUP_DIR="$D/.bup"
@@ -254,8 +254,30 @@ WVPASS bup random 128k >$D/b
 mkdir $D/d $D/d/e
 WVPASS bup random 512 >$D/f
 WVPASS bup index -ux $D
+bup save -n exclude-bupdir $D
+WVPASSEQ "$(bup ls exclude-bupdir/latest/$TOP/$D/)" "a
+b
+d/
+f"
+
+WVSTART "exclude"
+D=exclude.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
+WVPASS bup index -ux --exclude $D/d $D
+bup save -n exclude $D
+WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
+b
+f"
+mkdir $D/g $D/h
+WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h $D
 bup save -n exclude $D
 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
 b
-d/
 f"