Mailinglist Archive: opensuse (3100 mails)
| < Previous | Next > |
Re: [SLE] exclude folder to backup with rsync
- From: "david rankin" <drankin@xxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 20:21:37 -0600
- Message-id: <004401c653a0$ac9d4aa0$5906a8c0@rankinp35>
----- Original Message -----
From: "Marc Collin" <collinm@xxxxxxxxxxxxxxxx>
See man rsync:
INCLUDE/EXCLUDE PATTERN RULES
You can include and exclude files by specifying patterns using the "+", "-", etc. filter rules (as introduced in the FILTER RULES
section above). The include/exclude rules each specify a pattern that is matched against the names of the files that are going
to be transferred. These patterns can take several forms:
o 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 file
called "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-direcâ
tory rule). An unqualified "foo" would match any file or directory named "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 file
name. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory
named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that
matches at the root of the transfer.
o if the pattern ends with a / then it will only match a directory, not a file, link, or device.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
o if the pattern contains a wildcard character from the set *?[ then expression matching is applied using the shell filename
matching rules. Otherwise a simple string match is used.
o the double asterisk pattern "**" will match slashes while a single asterisk pattern "*" will stop at slashes.
o if the pattern contains a / (not counting a trailing /) or a "**" then it is matched against the full pathname, including
any leading directories. If the pattern doesn't contain a / or a "**", then it is matched only against the final component
of the filename. (Remember that the algorithm is applied recursively so "full filename" can actually be any portion of a
path from the starting directory on down.)
Note that, when using the --recursive (-r) option (which is implied by -a), every subcomponent of every path is visited from the
top down, so include/exclude patterns get applied recursively to each subcomponent's full name (e.g. to include "/foo/bar/baz"
the subcomponents "/foo" and "/foo/bar" must not be excluded). The exclude patterns actually short-circuit the directory traverâ
sal stage when rsync finds the files to send. If a pattern excludes a particular parent directory, it can render a deeper
include pattern ineffectual because rsync did not descend through that excluded section of the hierarchy. This is particularly
important when using a trailing '*' rule. For instance, this won't work:
+ /some/path/this-file-will-not-be-found
+ /file-is-included
- *
This fails because the parent directory "some" is excluded by the '*' rule, so rsync never visits any of the files in the "some"
or "some/path" directories. One solution is to ask for all directories in the hierarchy to be included by using a single rule:
"+ */" (put it somewhere before the "- *" rule). Another solution is to add specific include rules for all the parent dirs that
need to be visited. For instance, this set of rules works fine:
+ /some/
+ /some/path/
+ /some/path/this-file-is-found
+ /file-also-included
- *
Here are some examples of exclude/include matching:
o "- *.o" would exclude all filenames matching *.o
o "- /foo" would exclude a file called foo in the transfer-root directory
o "- foo/" would exclude any directory called foo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
o "- /foo/*/bar" would exclude any file called bar two levels below a directory called foo in the transfer-root directory
o "- /foo/**/bar" would exclude any file called bar two or more levels below a directory called foo in the transfer-root
directory
o The combination of "+ */", "+ *.c", and "- *" would include all directories and C source files but nothing else.
o The combination of "+ foo/", "+ foo/bar.c", and "- *" would include only the foo directory and foo/bar.c (the foo direcâ
tory must be explicitly included or it would be excluded by the "*")
Hope that helps......
--
David C. Rankin, J.D., P.E.
RANKIN LAW FIRM, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
(936) 715-9333
(936) 715-9339 fax
www.rankinlawfirm.com
--
i try to exclude some folde and all sub-directory...
in my exclude.txt i have
+ /home/collinm/mp3
+ /home/collinm/Download
when i run the script, rsync copy all file .... it copy mp3 and Download
folder..... but i don't want that....
tried to replace + by - and nothing..... get the same result....
any idea?
thanks
See man rsync:
INCLUDE/EXCLUDE PATTERN RULES
You can include and exclude files by specifying patterns using the "+", "-", etc. filter rules (as introduced in the FILTER RULES
section above). The include/exclude rules each specify a pattern that is matched against the names of the files that are going
to be transferred. These patterns can take several forms:
o 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 file
called "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-direcâ
tory rule). An unqualified "foo" would match any file or directory named "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 file
name. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory
named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that
matches at the root of the transfer.
o if the pattern ends with a / then it will only match a directory, not a file, link, or device.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
o if the pattern contains a wildcard character from the set *?[ then expression matching is applied using the shell filename
matching rules. Otherwise a simple string match is used.
o the double asterisk pattern "**" will match slashes while a single asterisk pattern "*" will stop at slashes.
o if the pattern contains a / (not counting a trailing /) or a "**" then it is matched against the full pathname, including
any leading directories. If the pattern doesn't contain a / or a "**", then it is matched only against the final component
of the filename. (Remember that the algorithm is applied recursively so "full filename" can actually be any portion of a
path from the starting directory on down.)
Note that, when using the --recursive (-r) option (which is implied by -a), every subcomponent of every path is visited from the
top down, so include/exclude patterns get applied recursively to each subcomponent's full name (e.g. to include "/foo/bar/baz"
the subcomponents "/foo" and "/foo/bar" must not be excluded). The exclude patterns actually short-circuit the directory traverâ
sal stage when rsync finds the files to send. If a pattern excludes a particular parent directory, it can render a deeper
include pattern ineffectual because rsync did not descend through that excluded section of the hierarchy. This is particularly
important when using a trailing '*' rule. For instance, this won't work:
+ /some/path/this-file-will-not-be-found
+ /file-is-included
- *
This fails because the parent directory "some" is excluded by the '*' rule, so rsync never visits any of the files in the "some"
or "some/path" directories. One solution is to ask for all directories in the hierarchy to be included by using a single rule:
"+ */" (put it somewhere before the "- *" rule). Another solution is to add specific include rules for all the parent dirs that
need to be visited. For instance, this set of rules works fine:
+ /some/
+ /some/path/
+ /some/path/this-file-is-found
+ /file-also-included
- *
Here are some examples of exclude/include matching:
o "- *.o" would exclude all filenames matching *.o
o "- /foo" would exclude a file called foo in the transfer-root directory
o "- foo/" would exclude any directory called foo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
o "- /foo/*/bar" would exclude any file called bar two levels below a directory called foo in the transfer-root directory
o "- /foo/**/bar" would exclude any file called bar two or more levels below a directory called foo in the transfer-root
directory
o The combination of "+ */", "+ *.c", and "- *" would include all directories and C source files but nothing else.
o The combination of "+ foo/", "+ foo/bar.c", and "- *" would include only the foo directory and foo/bar.c (the foo direcâ
tory must be explicitly included or it would be excluded by the "*")
Hope that helps......
--
David C. Rankin, J.D., P.E.
RANKIN LAW FIRM, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
(936) 715-9333
(936) 715-9339 fax
www.rankinlawfirm.com
--
| < Previous | Next > |