help.rst.inc 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .. _borg_patterns:
  2. borg help patterns
  3. ~~~~~~~~~~~~~~~~~~
  4. ::
  5. Exclusion patterns support four separate styles, fnmatch, shell, regular
  6. expressions and path prefixes. If followed by a colon (':') the first two
  7. characters of a pattern are used as a style selector. Explicit style
  8. selection is necessary when a non-default style is desired or when the
  9. desired pattern starts with two alphanumeric characters followed by a colon
  10. (i.e. `aa:something/*`).
  11. `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
  12. These patterns use a variant of shell pattern syntax, with '*' matching
  13. any number of characters, '?' matching any single character, '[...]'
  14. matching any single character specified, including ranges, and '[!...]'
  15. matching any character not specified. For the purpose of these patterns,
  16. the path separator ('\' for Windows and '/' on other systems) is not
  17. treated specially. Wrap meta-characters in brackets for a literal match
  18. (i.e. `[?]` to match the literal character `?`). For a path to match
  19. a pattern, it must completely match from start to end, or must match from
  20. the start to just before a path separator. Except for the root path,
  21. paths will never end in the path separator when matching is attempted.
  22. Thus, if a given pattern ends in a path separator, a '*' is appended
  23. before matching is attempted.
  24. Shell-style patterns, selector `sh:`
  25. Like fnmatch patterns these are similar to shell patterns. The difference
  26. is that the pattern may include `**/` for matching zero or more directory
  27. levels, `*` for matching zero or more arbitrary characters with the
  28. exception of any path separator.
  29. Regular expressions, selector `re:`
  30. Regular expressions similar to those found in Perl are supported. Unlike
  31. shell patterns regular expressions are not required to match the complete
  32. path and any substring match is sufficient. It is strongly recommended to
  33. anchor patterns to the start ('^'), to the end ('$') or both. Path
  34. separators ('\' for Windows and '/' on other systems) in paths are
  35. always normalized to a forward slash ('/') before applying a pattern. The
  36. regular expression syntax is described in the `Python documentation for
  37. the re module <https://docs.python.org/3/library/re.html>`_.
  38. Prefix path, selector `pp:`
  39. This pattern style is useful to match whole sub-directories. The pattern
  40. `pp:/data/bar` matches `/data/bar` and everything therein.
  41. Exclusions can be passed via the command line option `--exclude`. When used
  42. from within a shell the patterns should be quoted to protect them from
  43. expansion.
  44. The `--exclude-from` option permits loading exclusion patterns from a text
  45. file with one pattern per line. Lines empty or starting with the number sign
  46. ('#') after removing whitespace on both ends are ignored. The optional style
  47. selector prefix is also supported for patterns loaded from a file. Due to
  48. whitespace removal paths with whitespace at the beginning or end can only be
  49. excluded using regular expressions.
  50. Examples:
  51. # Exclude '/home/user/file.o' but not '/home/user/file.odt':
  52. $ borg create -e '*.o' backup /
  53. # Exclude '/home/user/junk' and '/home/user/subdir/junk' but
  54. # not '/home/user/importantjunk' or '/etc/junk':
  55. $ borg create -e '/home/*/junk' backup /
  56. # Exclude the contents of '/home/user/cache' but not the directory itself:
  57. $ borg create -e /home/user/cache/ backup /
  58. # The file '/home/user/cache/important' is *not* backed up:
  59. $ borg create -e /home/user/cache/ backup / /home/user/cache/important
  60. # The contents of directories in '/home' are not backed up when their name
  61. # ends in '.tmp'
  62. $ borg create --exclude 're:^/home/[^/]+\.tmp/' backup /
  63. # Load exclusions from file
  64. $ cat >exclude.txt <<EOF
  65. # Comment line
  66. /home/*/junk
  67. *.tmp
  68. fm:aa:something/*
  69. re:^/home/[^/]\.tmp/
  70. sh:/home/*/.thumbnails
  71. EOF
  72. $ borg create --exclude-from exclude.txt backup /