On Fri, 26 Nov 2010 09:02:49 +0100 Helmut Jarausch <jarau...@igpm.rwth-aachen.de> wrote: > On 11/25/10 22:51:36, Renat Golubchyk wrote: > > The man page is actually pretty clear on this issue. Quote: > > > > if the pattern starts with a / then it is anchored to a particular > > spot in the hierarchy of files, otherwise it is matched against > > the > > end of the pathname. This is similar to a leading ^ in regular > > expressions. Thus "/foo" would match a name of "foo" at either > > the "root of the transfer" (for a global rule) or in the > > merge-file’s directory (for a per-directory rule). An > > unqualified "foo" would > > match a name of "foo" anywhere in the tree because the > > algorithm is > > applied recursively from the top down; it behaves as if each path > > component gets a turn at being the end of the filename. Even the > > unanchored "sub/foo" would match at any point in the > > hierarchy where a "foo" was found within a directory named "sub". > > > > "Root of the transfer" is the directory you want to sync. Thus, if > > you > > run e.g. "rsync /var/log/ /mnt/backups/ --exclude=/portage/" then > > root > > of the transfer is /var/log, and therefore the directory > > /var/log/portage will be excluded. If on the other hand you write > > --exclude=portage/ then a directory named portage anywhere in the > > tree > > under /var/log will be excluded. Without the trailing slash, i.e. > > just > > --exclude=portage any file (regular file, directory, link, whatever) > > named portage anywhere in the tree gets excluded. And finally > > --exclude=/portage would exclude a file only at the top of the tree > > that > > is going to be synchronsed. > > > > Let me add some caveat which has trapped me recently. > > I had (in your terms) > rsync /var/log/ /mnt/backups/ --delete --exclude=/portage/ > > and /var/log/portage was just a symlink to some other directory > while /mnt/backups/portage was a real directory. > In that case rsync deletes /mnt/backups/portage ! > It looks as if the "directory property" is check in the source tree > only. Quite an unpleasant surprise.
The behavior is logical and consistent with the command you provided. If you tell rsync to synchronise two directories and delete everything in the destination that is not in the source then rsync does just that. And a symbolic link is not a directory. One might think that exclude rule applies to both source and destination, but it doesn't. That's a common pitfall. But the documentation is clear on that too. It says, "This option allows you to add rules to selectively exclude certain files from the list of files to be transferred." Since destination directory is not going to be transferred it is clear that this option doesn't apply there. In order to avoid the problem of files being accidentally deleted I just never run rsync without running it with --dry-run first if I specify a --delete option. Thus I have an opportunity to review the file list before anything unpleasant is done. Cheers, Renat -- Probleme kann man niemals mit derselben Denkweise loesen, durch die sie entstanden sind. (Einstein)
signature.asc
Description: PGP signature