help.rst.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. The path/filenames used as input for the pattern matching start from the
  6. currently active recursion root. You usually give the recursion root(s)
  7. when invoking borg and these can be either relative or absolute paths.
  8. So, when you give `relative/` as root, the paths going into the matcher
  9. will look like `relative/.../file.ext`. When you give `/absolute/` as
  10. root, they will look like `/absolute/.../file.ext`. This is meant when
  11. we talk about "full path" below.
  12. File paths in Borg archives are always stored normalized and relative.
  13. This means that e.g. ``borg create /path/to/repo ../some/path`` will
  14. store all files as `some/path/.../file.ext` and ``borg create
  15. /path/to/repo /home/user`` will store all files as
  16. `home/user/.../file.ext`. Therefore, always use relative paths in your
  17. patterns when matching archive content in commands like ``extract`` or
  18. ``mount``. Starting with Borg 1.2 this behaviour will be changed to
  19. accept both absolute and relative paths.
  20. A directory exclusion pattern can end either with or without a slash ('/').
  21. If it ends with a slash, such as `some/path/`, the directory will be
  22. included but not its content. If it does not end with a slash, such as
  23. `some/path`, both the directory and content will be excluded.
  24. File patterns support these styles: fnmatch, shell, regular expressions,
  25. path prefixes and path full-matches. By default, fnmatch is used for
  26. ``--exclude`` patterns and shell-style is used for the ``--pattern`` option.
  27. If followed by a colon (':') the first two characters of a pattern are
  28. used as a style selector. Explicit style selection is necessary when a
  29. non-default style is desired or when the desired pattern starts with
  30. two alphanumeric characters followed by a colon (i.e. `aa:something/*`).
  31. `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
  32. This is the default style for ``--exclude`` and ``--exclude-from``.
  33. These patterns use a variant of shell pattern syntax, with '\*' matching
  34. any number of characters, '?' matching any single character, '[...]'
  35. matching any single character specified, including ranges, and '[!...]'
  36. matching any character not specified. For the purpose of these patterns,
  37. the path separator (backslash for Windows and '/' on other systems) is not
  38. treated specially. Wrap meta-characters in brackets for a literal
  39. match (i.e. `[?]` to match the literal character `?`). For a path
  40. to match a pattern, the full path must match, or it must match
  41. from the start of the full path to just before a path separator. Except
  42. for the root path, paths will never end in the path separator when
  43. matching is attempted. Thus, if a given pattern ends in a path
  44. separator, a '\*' is appended before matching is attempted.
  45. Shell-style patterns, selector `sh:`
  46. This is the default style for ``--pattern`` and ``--patterns-from``.
  47. Like fnmatch patterns these are similar to shell patterns. The difference
  48. is that the pattern may include `**/` for matching zero or more directory
  49. levels, `*` for matching zero or more arbitrary characters with the
  50. exception of any path separator.
  51. Regular expressions, selector `re:`
  52. Regular expressions similar to those found in Perl are supported. Unlike
  53. shell patterns regular expressions are not required to match the full
  54. path and any substring match is sufficient. It is strongly recommended to
  55. anchor patterns to the start ('^'), to the end ('$') or both. Path
  56. separators (backslash for Windows and '/' on other systems) in paths are
  57. always normalized to a forward slash ('/') before applying a pattern. The
  58. regular expression syntax is described in the `Python documentation for
  59. the re module <https://docs.python.org/3/library/re.html>`_.
  60. Path prefix, selector `pp:`
  61. This pattern style is useful to match whole sub-directories. The pattern
  62. `pp:root/somedir` matches `root/somedir` and everything therein.
  63. Path full-match, selector `pf:`
  64. This pattern style is (only) useful to match full paths.
  65. This is kind of a pseudo pattern as it can not have any variable or
  66. unspecified parts - the full path must be given.
  67. `pf:root/file.ext` matches `root/file.ext` only.
  68. Implementation note: this is implemented via very time-efficient O(1)
  69. hashtable lookups (this means you can have huge amounts of such patterns
  70. without impacting performance much).
  71. Due to that, this kind of pattern does not respect any context or order.
  72. If you use such a pattern to include a file, it will always be included
  73. (if the directory recursion encounters it).
  74. Other include/exclude patterns that would normally match will be ignored.
  75. Same logic applies for exclude.
  76. .. note::
  77. `re:`, `sh:` and `fm:` patterns are all implemented on top of the Python SRE
  78. engine. It is very easy to formulate patterns for each of these types which
  79. requires an inordinate amount of time to match paths. If untrusted users
  80. are able to supply patterns, ensure they cannot supply `re:` patterns.
  81. Further, ensure that `sh:` and `fm:` patterns only contain a handful of
  82. wildcards at most.
  83. Exclusions can be passed via the command line option ``--exclude``. When used
  84. from within a shell, the patterns should be quoted to protect them from
  85. expansion.
  86. The ``--exclude-from`` option permits loading exclusion patterns from a text
  87. file with one pattern per line. Lines empty or starting with the number sign
  88. ('#') after removing whitespace on both ends are ignored. The optional style
  89. selector prefix is also supported for patterns loaded from a file. Due to
  90. whitespace removal, paths with whitespace at the beginning or end can only be
  91. excluded using regular expressions.
  92. To test your exclusion patterns without performing an actual backup you can
  93. run ``borg create --list --dry-run ...``.
  94. Examples::
  95. # Exclude '/home/user/file.o' but not '/home/user/file.odt':
  96. $ borg create -e '*.o' backup /
  97. # Exclude '/home/user/junk' and '/home/user/subdir/junk' but
  98. # not '/home/user/importantjunk' or '/etc/junk':
  99. $ borg create -e '/home/*/junk' backup /
  100. # Exclude the contents of '/home/user/cache' but not the directory itself:
  101. $ borg create -e /home/user/cache/ backup /
  102. # The file '/home/user/cache/important' is *not* backed up:
  103. $ borg create -e /home/user/cache/ backup / /home/user/cache/important
  104. # The contents of directories in '/home' are not backed up when their name
  105. # ends in '.tmp'
  106. $ borg create --exclude 're:^/home/[^/]+\.tmp/' backup /
  107. # Load exclusions from file
  108. $ cat >exclude.txt <<EOF
  109. # Comment line
  110. /home/*/junk
  111. *.tmp
  112. fm:aa:something/*
  113. re:^/home/[^/]+\.tmp/
  114. sh:/home/*/.thumbnails
  115. # Example with spaces, no need to escape as it is processed by borg
  116. some file with spaces.txt
  117. EOF
  118. $ borg create --exclude-from exclude.txt backup /
  119. A more general and easier to use way to define filename matching patterns exists
  120. with the ``--pattern`` and ``--patterns-from`` options. Using these, you may
  121. specify the backup roots (starting points) and patterns for inclusion/exclusion.
  122. A root path starts with the prefix `R`, followed by a path (a plain path, not a
  123. file pattern). An include rule starts with the prefix +, an exclude rule starts
  124. with the prefix -, an exclude-norecurse rule starts with !, all followed by a pattern.
  125. .. note::
  126. Via ``--pattern`` or ``--patterns-from`` you can define BOTH inclusion and exclusion
  127. of files using pattern prefixes ``+`` and ``-``. With ``--exclude`` and
  128. ``--exclude-from`` ONLY excludes are defined.
  129. Inclusion patterns are useful to include paths that are contained in an excluded
  130. path. The first matching pattern is used so if an include pattern matches before
  131. an exclude pattern, the file is backed up. If an exclude-norecurse pattern matches
  132. a directory, it won't recurse into it and won't discover any potential matches for
  133. include rules below that directory.
  134. .. note::
  135. It's possible that a sub-directory/file is matched while parent directories are not.
  136. In that case, parent directories are not backed up thus their user, group, permission,
  137. etc. can not be restored.
  138. Note that the default pattern style for ``--pattern`` and ``--patterns-from`` is
  139. shell style (`sh:`), so those patterns behave similar to rsync include/exclude
  140. patterns. The pattern style can be set via the `P` prefix.
  141. Patterns (``--pattern``) and excludes (``--exclude``) from the command line are
  142. considered first (in the order of appearance). Then patterns from ``--patterns-from``
  143. are added. Exclusion patterns from ``--exclude-from`` files are appended last.
  144. Examples::
  145. # backup pics, but not the ones from 2018, except the good ones:
  146. # note: using = is essential to avoid cmdline argument parsing issues.
  147. borg create --pattern=+pics/2018/good --pattern=-pics/2018 repo::arch pics
  148. # use a file with patterns:
  149. borg create --patterns-from patterns.lst repo::arch
  150. The patterns.lst file could look like that::
  151. # "sh:" pattern style is the default, so the following line is not needed:
  152. P sh
  153. R /
  154. # can be rebuild
  155. - /home/*/.cache
  156. # they're downloads for a reason
  157. - /home/*/Downloads
  158. # susan is a nice person
  159. # include susans home
  160. + /home/susan
  161. # also back up this exact file
  162. + pf:/home/bobby/specialfile.txt
  163. # don't backup the other home directories
  164. - /home/*
  165. # don't even look in /proc
  166. ! /proc
  167. You can specify recursion roots either on the command line or in a patternfile::
  168. # these two commands do the same thing
  169. borg create --exclude /home/bobby/junk repo::arch /home/bobby /home/susan
  170. borg create --patterns-from patternfile.lst repo::arch
  171. The patternfile::
  172. # note that excludes use fm: by default and patternfiles use sh: by default.
  173. # therefore, we need to specify fm: to have the same exact behavior.
  174. P fm
  175. R /home/bobby
  176. R /home/susan
  177. - /home/bobby/junk
  178. This allows you to share the same patterns between multiple repositories
  179. without needing to specify them on the command line.
  180. .. _borg_placeholders:
  181. borg help placeholders
  182. ~~~~~~~~~~~~~~~~~~~~~~
  183. Repository (or Archive) URLs, ``--prefix``, ``--glob-archives``, ``--comment``
  184. and ``--remote-path`` values support these placeholders:
  185. {hostname}
  186. The (short) hostname of the machine.
  187. {fqdn}
  188. The full name of the machine.
  189. {reverse-fqdn}
  190. The full name of the machine in reverse domain name notation.
  191. {now}
  192. The current local date and time, by default in ISO-8601 format.
  193. You can also supply your own `format string <https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
  194. {utcnow}
  195. The current UTC date and time, by default in ISO-8601 format.
  196. You can also supply your own `format string <https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}
  197. {user}
  198. The user name (or UID, if no name is available) of the user running borg.
  199. {pid}
  200. The current process ID.
  201. {borgversion}
  202. The version of borg, e.g.: 1.0.8rc1
  203. {borgmajor}
  204. The version of borg, only the major version, e.g.: 1
  205. {borgminor}
  206. The version of borg, only major and minor version, e.g.: 1.0
  207. {borgpatch}
  208. The version of borg, only major, minor and patch version, e.g.: 1.0.8
  209. If literal curly braces need to be used, double them for escaping::
  210. borg create /path/to/repo::{{literal_text}}
  211. Examples::
  212. borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
  213. borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ...
  214. borg prune --prefix '{hostname}-' ...
  215. .. note::
  216. systemd uses a difficult, non-standard syntax for command lines in unit files (refer to
  217. the `systemd.unit(5)` manual page).
  218. When invoking borg from unit files, pay particular attention to escaping,
  219. especially when using the now/utcnow placeholders, since systemd performs its own
  220. %-based variable replacement even in quoted text. To avoid interference from systemd,
  221. double all percent signs (``{hostname}-{now:%Y-%m-%d_%H:%M:%S}``
  222. becomes ``{hostname}-{now:%%Y-%%m-%%d_%%H:%%M:%%S}``).
  223. .. _borg_compression:
  224. borg help compression
  225. ~~~~~~~~~~~~~~~~~~~~~
  226. It is no problem to mix different compression methods in one repo,
  227. deduplication is done on the source data chunks (not on the compressed
  228. or encrypted data).
  229. If some specific chunk was once compressed and stored into the repo, creating
  230. another backup that also uses this chunk will not change the stored chunk.
  231. So if you use different compression specs for the backups, whichever stores a
  232. chunk first determines its compression. See also borg recreate.
  233. Compression is lz4 by default. If you want something else, you have to specify what you want.
  234. Valid compression specifiers are:
  235. none
  236. Do not compress.
  237. lz4
  238. Use lz4 compression. Very high speed, very low compression. (default)
  239. zstd[,L]
  240. Use zstd ("zstandard") compression, a modern wide-range algorithm.
  241. If you do not explicitely give the compression level L (ranging from 1
  242. to 22), it will use level 3.
  243. Archives compressed with zstd are not compatible with borg < 1.1.4.
  244. zlib[,L]
  245. Use zlib ("gz") compression. Medium speed, medium compression.
  246. If you do not explicitely give the compression level L (ranging from 0
  247. to 9), it will use level 6.
  248. Giving level 0 (means "no compression", but still has zlib protocol
  249. overhead) is usually pointless, you better use "none" compression.
  250. lzma[,L]
  251. Use lzma ("xz") compression. Low speed, high compression.
  252. If you do not explicitely give the compression level L (ranging from 0
  253. to 9), it will use level 6.
  254. Giving levels above 6 is pointless and counterproductive because it does
  255. not compress better due to the buffer size used by borg - but it wastes
  256. lots of CPU cycles and RAM.
  257. auto,C[,L]
  258. Use a built-in heuristic to decide per chunk whether to compress or not.
  259. The heuristic tries with lz4 whether the data is compressible.
  260. For incompressible data, it will not use compression (uses "none").
  261. For compressible data, it uses the given C[,L] compression - with C[,L]
  262. being any valid compression specifier.
  263. Examples::
  264. borg create --compression lz4 REPO::ARCHIVE data
  265. borg create --compression zstd REPO::ARCHIVE data
  266. borg create --compression zstd,10 REPO::ARCHIVE data
  267. borg create --compression zlib REPO::ARCHIVE data
  268. borg create --compression zlib,1 REPO::ARCHIVE data
  269. borg create --compression auto,lzma,6 REPO::ARCHIVE data
  270. borg create --compression auto,lzma ...