Gentoo Archives: gentoo-user

From: Helmut Jarausch <jarausch@××××××××××××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How to exclude a directory from rsync
Date: Fri, 26 Nov 2010 08:05:38
Message-Id: 1290758569.8281.0@numa-i
In Reply to: Re: [gentoo-user] How to exclude a directory from rsync by Renat Golubchyk
1 On 11/25/10 22:51:36, Renat Golubchyk wrote:
2 > On Tue, 16 Nov 2010 23:01:51 +0000 Mick <michaelkintzios@×××××.com>
3 > wrote:
4 > > On Tuesday 16 November 2010 22:26:28 Stefan G. Weichinger wrote:
5 > > > Am 2010-11-16 22:24, schrieb Alan McKinnon:
6 > > > > Apparently, though unproven, at 23:12 on Tuesday 16 November
7 > > > > 2010, Mick did
8 > > > >
9 > > > > opine thusly:
10 > > > >> Excellent, it worked! :-)
11 > > > >
12 > > > > Glad to hear it.
13 > > > >
14 > > > > I could help because part of my job is running a rather big
15 > > > > public ftp mirror that management graciously pay for. And I
16 > went
17 > > > > down this rsync road a long time ago myself.
18 > > > >
19 > > > > You have no idea how many brain cells died in agony to figure
20 > out
21 > > > > this specific piece of rsync behaviour :-)
22 > > >
23 > > > ;-)
24 > > >
25 > > > I would like to know if my suggestion also works ;-)
26 > > >
27 > > > Yeah, include/exclude-patterns are rather hard to figure out
28 > > > sometimes ... nearly like regexes -> write once, read never ....
29 > >
30 > > Ha, ha! True!
31 > >
32 > > Stefan, I tried escaping the spaces (even tried \\ double and \\\
33 > > triple escapes in case it makes a difference because of using ssh)
34 > > but still did not work. In my head I couldn't see how the full
35 > path
36 > > would not work, but the relative path would, but I tried it out all
37 > > the same.
38 > >
39 > > I still don't understand why Alan's recommendation works ;-)
40 >
41 > I'm probably late with my reply, but I'll post it so it will be in
42 > the
43 > archives for future reference.
44 >
45 > The man page is actually pretty clear on this issue. Quote:
46 >
47 > if the pattern starts with a / then it is anchored to a particular
48 > spot in the hierarchy of files, otherwise it is matched against
49 > the
50 > end of the pathname. This is similar to a leading ^ in regular
51 > expressions. Thus "/foo" would match a name of "foo" at either the
52 > "root of the transfer" (for a global rule) or in the merge-file’s
53 > directory (for a per-directory rule). An unqualified "foo"
54 > would
55 > match a name of "foo" anywhere in the tree because the algorithm
56 > is
57 > applied recursively from the top down; it behaves as if each path
58 > component gets a turn at being the end of the filename. Even the
59 > unanchored "sub/foo" would match at any point in the hierarchy
60 > where a "foo" was found within a directory named "sub".
61 >
62 > "Root of the transfer" is the directory you want to sync. Thus, if
63 > you
64 > run e.g. "rsync /var/log/ /mnt/backups/ --exclude=/portage/" then
65 > root
66 > of the transfer is /var/log, and therefore the directory
67 > /var/log/portage will be excluded. If on the other hand you write
68 > --exclude=portage/ then a directory named portage anywhere in the
69 > tree
70 > under /var/log will be excluded. Without the trailing slash, i.e.
71 > just
72 > --exclude=portage any file (regular file, directory, link, whatever)
73 > named portage anywhere in the tree gets excluded. And finally
74 > --exclude=/portage would exclude a file only at the top of the tree
75 > that
76 > is going to be synchronsed.
77 >
78
79 Let me add some caveat which has trapped me recently.
80
81 I had (in your terms)
82 rsync /var/log/ /mnt/backups/ --delete --exclude=/portage/
83
84 and /var/log/portage was just a symlink to some other directory
85 while /mnt/backups/portage was a real directory.
86 In that case rsync deletes /mnt/backups/portage !
87 It looks as if the "directory property" is check in the source tree
88 only. Quite an unpleasant surprise.
89
90 Helmut.

Replies

Subject Author
Re: [gentoo-user] How to exclude a directory from rsync Renat Golubchyk <ragermany@×××.net>