[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exclude patterns in tarsnaprc



NOOOOOOOO!

If you remove the leading '/' off your exclude pattern, it will exclude
any match of that directory in the tree. Even excludes of 2 or more
directory levels, e.g. "--exclude usr/src" would match usr/users/jamie/usr/src

To exclude reliably, you have to 'anchor' the path to root by preceding
it with '/' - You must also specify your backup path preceeding with '/'
for anchoring to work at all.

Don't forget you can test this using the '--dry-run' parameter.

I include a test script, and it's output to demonstrate.

Here's how it works:

Exclude patterns are applied *before* any leading '/' is potentially stripped or not.

The format you use therefore depends upon whether you use a relative or absolute backup path.

So, for example, to exclude /usr/src would be done in different ways depending on how you call it:

1) tarsnap cf --exclude /usr/src blah.tar /

or:

2) cd / && tarsnap cf --exclude ./usr/src blah.tar  .

or:

3) cd / && tarsnap cf --exclude usr/src blah.tar usr

4) cd /usr && tarsnap cf --exclude ./src blah.tar .

NOTE: The *only* way to reliably specify a path is if you use absolute pathnames throughout.
(Remember, leading '/' stripping happens after pattern-matching)

I.E. --exclude usr/src  would also exclude usr/users/jamie/usr/src/important-stuff

Check the sample script and output below. Note how 'important-stuff-to-backup' is
excluded in every scenario.

cheers, jamie

jamie has logged on pts/4 from tabbycat6.dyslexicfish.net
10:57 [2] (1) "jamie" root@lapcat# cat tarsnaptest

#!/bin/sh
# -----------------------------------------
do_cmd()
  {
    echo
    echo "$@"
    echo '--------------------------'
    "$@"
  }
# -----------------------------------------

tmpdir="$(mktemp -d)" || exit 1
cd "$tmpdir" || exit 1

mkdir -p usr/src/bin
mkdir -p usr/src/devel/usr/src
mkdir -p usr/src/devel/usr/bin
mkdir -p usr/local/etc/rc.d
mkdir -p usr/lib
mkdir -p usr/include/sys
mkdir -p usr/users/jamie/bin
mkdir -p usr/users/jamie/myproject/src/2014
mkdir -p usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-1
mkdir -p usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-2
mkdir -p usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-3/out
mkdir -p /etc/ssl
mkdir -p var/db/tarsnap
mkdir -p var/log

find . -type d -exec touch {}/dummyfile \;

do_cmd find . -print
do_cmd tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude ./usr/src  .
do_cmd tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude usr/src usr
do_cmd tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude ./src .

rm -rf "$tmpdir"

10:57 [2] (2) "jamie" root@lapcat# sh tarsnaptest

find . -print
--------------------------
.
./dummyfile
./var
./var/log
./var/log/dummyfile
./var/dummyfile
./var/db
./var/db/tarsnap
./var/db/tarsnap/dummyfile
./var/db/dummyfile
./usr
./usr/include
./usr/include/dummyfile
./usr/include/sys
./usr/include/sys/dummyfile
./usr/users
./usr/users/jamie
./usr/users/jamie/myproject
./usr/users/jamie/myproject/dummyfile
./usr/users/jamie/myproject/src
./usr/users/jamie/myproject/src/2014
./usr/users/jamie/myproject/src/2014/dummyfile
./usr/users/jamie/myproject/src/dummyfile
./usr/users/jamie/bin
./usr/users/jamie/bin/dummyfile
./usr/users/jamie/devel
./usr/users/jamie/devel/temp
./usr/users/jamie/devel/temp/dummyfile
./usr/users/jamie/devel/temp/usr
./usr/users/jamie/devel/temp/usr/dummyfile
./usr/users/jamie/devel/temp/usr/src
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-3
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-3/dummyfile
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-3/out
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-3/out/dummyfile
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-2
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-2/dummyfile
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-1
./usr/users/jamie/devel/temp/usr/src/important-stuff-to-backup-1/dummyfile
./usr/users/jamie/devel/temp/usr/src/dummyfile
./usr/users/jamie/devel/dummyfile
./usr/users/jamie/dummyfile
./usr/users/dummyfile
./usr/lib
./usr/lib/dummyfile
./usr/dummyfile
./usr/src
./usr/src/bin
./usr/src/bin/dummyfile
./usr/src/devel
./usr/src/devel/dummyfile
./usr/src/devel/usr
./usr/src/devel/usr/bin
./usr/src/devel/usr/bin/dummyfile
./usr/src/devel/usr/dummyfile
./usr/src/devel/usr/src
./usr/src/devel/usr/src/dummyfile
./usr/src/dummyfile
./usr/local
./usr/local/dummyfile
./usr/local/etc
./usr/local/etc/dummyfile
./usr/local/etc/rc.d
./usr/local/etc/rc.d/dummyfile

tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude ./usr/src .
--------------------------
a .
a ./dummyfile
a ./var
a ./usr
a ./usr/include
a ./usr/users
a ./usr/lib
a ./usr/dummyfile
a ./usr/local
a ./usr/local/dummyfile
a ./usr/local/etc
a ./usr/local/etc/dummyfile
a ./usr/local/etc/rc.d
a ./usr/local/etc/rc.d/dummyfile
a ./usr/lib/dummyfile
a ./usr/users/jamie
a ./usr/users/dummyfile
a ./usr/users/jamie/myproject
a ./usr/users/jamie/bin
a ./usr/users/jamie/devel
a ./usr/users/jamie/dummyfile
a ./usr/users/jamie/devel/temp
a ./usr/users/jamie/devel/dummyfile
a ./usr/users/jamie/devel/temp/dummyfile
a ./usr/users/jamie/devel/temp/usr
a ./usr/users/jamie/devel/temp/usr/dummyfile
a ./usr/users/jamie/bin/dummyfile
a ./usr/users/jamie/myproject/dummyfile
a ./usr/users/jamie/myproject/src
a ./usr/users/jamie/myproject/src/2014
a ./usr/users/jamie/myproject/src/dummyfile
a ./usr/users/jamie/myproject/src/2014/dummyfile
a ./usr/include/dummyfile
a ./usr/include/sys
a ./usr/include/sys/dummyfile
a ./var/log
a ./var/dummyfile
a ./var/db
a ./var/db/tarsnap
a ./var/db/dummyfile
a ./var/db/tarsnap/dummyfile
a ./var/log/dummyfile

tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude usr/src usr
--------------------------
a usr
a usr/include
a usr/users
a usr/lib
a usr/dummyfile
a usr/local
a usr/local/dummyfile
a usr/local/etc
a usr/local/etc/dummyfile
a usr/local/etc/rc.d
a usr/local/etc/rc.d/dummyfile
a usr/lib/dummyfile
a usr/users/jamie
a usr/users/dummyfile
a usr/users/jamie/myproject
a usr/users/jamie/bin
a usr/users/jamie/devel
a usr/users/jamie/dummyfile
a usr/users/jamie/devel/temp
a usr/users/jamie/devel/dummyfile
a usr/users/jamie/devel/temp/dummyfile
a usr/users/jamie/devel/temp/usr
a usr/users/jamie/devel/temp/usr/dummyfile
a usr/users/jamie/bin/dummyfile
a usr/users/jamie/myproject/dummyfile
a usr/users/jamie/myproject/src
a usr/users/jamie/myproject/src/2014
a usr/users/jamie/myproject/src/dummyfile
a usr/users/jamie/myproject/src/2014/dummyfile
a usr/include/dummyfile
a usr/include/sys
a usr/include/sys/dummyfile

tarsnap cvf dummy.tar --dry-run --no-print-stats --exclude ./src .
--------------------------
a .
a ./dummyfile
a ./var
a ./usr
a ./usr/include
a ./usr/users
a ./usr/lib
a ./usr/dummyfile
a ./usr/local
a ./usr/local/dummyfile
a ./usr/local/etc
a ./usr/local/etc/dummyfile
a ./usr/local/etc/rc.d
a ./usr/local/etc/rc.d/dummyfile
a ./usr/lib/dummyfile
a ./usr/users/jamie
a ./usr/users/dummyfile
a ./usr/users/jamie/myproject
a ./usr/users/jamie/bin
a ./usr/users/jamie/devel
a ./usr/users/jamie/dummyfile
a ./usr/users/jamie/devel/temp
a ./usr/users/jamie/devel/dummyfile
a ./usr/users/jamie/devel/temp/dummyfile
a ./usr/users/jamie/devel/temp/usr
a ./usr/users/jamie/devel/temp/usr/dummyfile
a ./usr/users/jamie/bin/dummyfile
a ./usr/users/jamie/myproject/dummyfile
a ./usr/include/dummyfile
a ./usr/include/sys
a ./usr/include/sys/dummyfile
a ./var/log
a ./var/dummyfile
a ./var/db
a ./var/db/tarsnap
a ./var/db/dummyfile
a ./var/db/tarsnap/dummyfile
a ./var/log/dummyfile

10:57 [2] (3) "jamie" root@lapcat#


Script done on Tue Jun 10 10:57:29 2014