help.rst.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. .. IMPORTANT: this file is auto-generated from borg's built-in help, do not edit!
  2. .. _borg_patterns:
  3. borg help patterns
  4. ~~~~~~~~~~~~~~~~~~
  5. Exclusion patterns support four separate styles, fnmatch, shell, regular
  6. expressions and path prefixes. By default, fnmatch is used. If followed
  7. by a colon (':') the first two characters of a pattern are used as a
  8. style selector. Explicit style selection is necessary when a
  9. non-default style is desired or when the desired pattern starts with
  10. two alphanumeric characters followed by a colon (i.e. `aa:something/*`).
  11. `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
  12. This is the default style. These patterns use a variant of shell
  13. pattern syntax, with '*' matching any number of characters, '?'
  14. matching any single character, '[...]' matching any single
  15. character specified, including ranges, and '[!...]' matching any
  16. character not specified. For the purpose of these patterns, the
  17. path separator ('\' for Windows and '/' on other systems) is not
  18. treated specially. Wrap meta-characters in brackets for a literal
  19. match (i.e. `[?]` to match the literal character `?`). For a path
  20. to match a pattern, it must completely match from start to end, or
  21. must match from the start to just before a path separator. Except
  22. for the root path, paths will never end in the path separator when
  23. matching is attempted. Thus, if a given pattern ends in a path
  24. separator, a '*' is appended before matching is attempted.
  25. Shell-style patterns, selector `sh:`
  26. Like fnmatch patterns these are similar to shell patterns. The difference
  27. is that the pattern may include `**/` for matching zero or more directory
  28. levels, `*` for matching zero or more arbitrary characters with the
  29. exception of any path separator.
  30. Regular expressions, selector `re:`
  31. Regular expressions similar to those found in Perl are supported. Unlike
  32. shell patterns regular expressions are not required to match the complete
  33. path and any substring match is sufficient. It is strongly recommended to
  34. anchor patterns to the start ('^'), to the end ('$') or both. Path
  35. separators ('\' for Windows and '/' on other systems) in paths are
  36. always normalized to a forward slash ('/') before applying a pattern. The
  37. regular expression syntax is described in the `Python documentation for
  38. the re module <https://docs.python.org/3/library/re.html>`_.
  39. Prefix path, selector `pp:`
  40. This pattern style is useful to match whole sub-directories. The pattern
  41. `pp:/data/bar` matches `/data/bar` and everything therein.
  42. .. note::
  43. `re:`, `sh:` and `fm:` patterns are all implemented on top of the Python SRE
  44. engine. It is very easy to formulate patterns for each of these types which
  45. requires an inordinate amount of time to match paths. If untrusted users
  46. are able to supply patterns, ensure they cannot supply `re:` patterns.
  47. Further, ensure that `sh:` and `fm:` patterns only contain a handful of
  48. wildcards at most.
  49. Exclusions can be passed via the command line option `--exclude`. When used
  50. from within a shell the patterns should be quoted to protect them from
  51. expansion.
  52. The `--exclude-from` option permits loading exclusion patterns from a text
  53. file with one pattern per line. Lines empty or starting with the number sign
  54. ('#') after removing whitespace on both ends are ignored. The optional style
  55. selector prefix is also supported for patterns loaded from a file. Due to
  56. whitespace removal paths with whitespace at the beginning or end can only be
  57. excluded using regular expressions.
  58. Examples::
  59. # Exclude '/home/user/file.o' but not '/home/user/file.odt':
  60. $ borg create -e '*.o' backup /
  61. # Exclude '/home/user/junk' and '/home/user/subdir/junk' but
  62. # not '/home/user/importantjunk' or '/etc/junk':
  63. $ borg create -e '/home/*/junk' backup /
  64. # Exclude the contents of '/home/user/cache' but not the directory itself:
  65. $ borg create -e /home/user/cache/ backup /
  66. # The file '/home/user/cache/important' is *not* backed up:
  67. $ borg create -e /home/user/cache/ backup / /home/user/cache/important
  68. # The contents of directories in '/home' are not backed up when their name
  69. # ends in '.tmp'
  70. $ borg create --exclude 're:^/home/[^/]+\.tmp/' backup /
  71. # Load exclusions from file
  72. $ cat >exclude.txt <<EOF
  73. # Comment line
  74. /home/*/junk
  75. *.tmp
  76. fm:aa:something/*
  77. re:^/home/[^/]\.tmp/
  78. sh:/home/*/.thumbnails
  79. EOF
  80. $ borg create --exclude-from exclude.txt backup /
  81. .. _borg_placeholders:
  82. borg help placeholders
  83. ~~~~~~~~~~~~~~~~~~~~~~
  84. Repository (or Archive) URLs, --prefix and --remote-path values support these
  85. placeholders:
  86. {hostname}
  87. The (short) hostname of the machine.
  88. {fqdn}
  89. The full name of the machine.
  90. {now}
  91. The current local date and time.
  92. {utcnow}
  93. The current UTC date and time.
  94. {user}
  95. The user name (or UID, if no name is available) of the user running borg.
  96. {pid}
  97. The current process ID.
  98. {borgversion}
  99. The version of borg, e.g.: 1.0.8rc1
  100. {borgmajor}
  101. The version of borg, only the major version, e.g.: 1
  102. {borgminor}
  103. The version of borg, only major and minor version, e.g.: 1.0
  104. {borgpatch}
  105. The version of borg, only major, minor and patch version, e.g.: 1.0.8
  106. Examples::
  107. borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
  108. borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ...
  109. borg prune --prefix '{hostname}-' ...