help.rst.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. Starting with Borg 1.2, paths that are matched against patterns always
  9. appear relative. If you give ``/absolute/`` as root, the paths going
  10. into the matcher will start with ``absolute/``.
  11. If you give ``../../relative`` as root, the paths will be normalized
  12. as ``relative/``.
  13. A directory exclusion pattern can end either with or without a slash ('/').
  14. If it ends with a slash, such as `some/path/`, the directory will be
  15. included but not its content. If it does not end with a slash, such as
  16. `some/path`, both the directory and content will be excluded.
  17. Borg supports different pattern styles. To define a non-default
  18. style for a specific pattern, prefix it with two characters followed
  19. by a colon ':' (i.e. ``fm:path/*``, ``sh:path/**``).
  20. `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
  21. This is the default style for ``--exclude`` and ``--exclude-from``.
  22. These patterns use a variant of shell pattern syntax, with '\*' matching
  23. any number of characters, '?' matching any single character, '[...]'
  24. matching any single character specified, including ranges, and '[!...]'
  25. matching any character not specified. For the purpose of these patterns,
  26. the path separator (backslash for Windows and '/' on other systems) is not
  27. treated specially. Wrap meta-characters in brackets for a literal
  28. match (i.e. `[?]` to match the literal character `?`). For a path
  29. to match a pattern, the full path must match, or it must match
  30. from the start of the full path to just before a path separator. Except
  31. for the root path, paths will never end in the path separator when
  32. matching is attempted. Thus, if a given pattern ends in a path
  33. separator, a '\*' is appended before matching is attempted. A leading
  34. path separator is always removed.
  35. Shell-style patterns, selector `sh:`
  36. This is the default style for ``--pattern`` and ``--patterns-from``.
  37. Like fnmatch patterns these are similar to shell patterns. The difference
  38. is that the pattern may include `**/` for matching zero or more directory
  39. levels, `*` for matching zero or more arbitrary characters with the
  40. exception of any path separator. A leading path separator is always removed.
  41. Regular expressions, selector `re:`
  42. Regular expressions similar to those found in Perl are supported. Unlike
  43. shell patterns regular expressions are not required to match the full
  44. path and any substring match is sufficient. It is strongly recommended to
  45. anchor patterns to the start ('^'), to the end ('$') or both. Path
  46. separators (backslash for Windows and '/' on other systems) in paths are
  47. always normalized to a forward slash ('/') before applying a pattern. The
  48. regular expression syntax is described in the `Python documentation for
  49. the re module <https://docs.python.org/3/library/re.html>`_.
  50. Path prefix, selector `pp:`
  51. This pattern style is useful to match whole sub-directories. The pattern
  52. `pp:root/somedir` matches `root/somedir` and everything therein. A leading
  53. path separator is always removed.
  54. Path full-match, selector `pf:`
  55. This pattern style is (only) useful to match full paths.
  56. This is kind of a pseudo pattern as it can not have any variable or
  57. unspecified parts - the full path must be given. `pf:root/file.ext` matches
  58. `root/file.ext` only. A leading path separator is always removed.
  59. Implementation note: this is implemented via very time-efficient O(1)
  60. hashtable lookups (this means you can have huge amounts of such patterns
  61. without impacting performance much).
  62. Due to that, this kind of pattern does not respect any context or order.
  63. If you use such a pattern to include a file, it will always be included
  64. (if the directory recursion encounters it).
  65. Other include/exclude patterns that would normally match will be ignored.
  66. Same logic applies for exclude.
  67. .. note::
  68. `re:`, `sh:` and `fm:` patterns are all implemented on top of the Python SRE
  69. engine. It is very easy to formulate patterns for each of these types which
  70. requires an inordinate amount of time to match paths. If untrusted users
  71. are able to supply patterns, ensure they cannot supply `re:` patterns.
  72. Further, ensure that `sh:` and `fm:` patterns only contain a handful of
  73. wildcards at most.
  74. Exclusions can be passed via the command line option ``--exclude``. When used
  75. from within a shell, the patterns should be quoted to protect them from
  76. expansion.
  77. Patterns matching special characters, e.g. white space, within a shell may
  78. require adjustments, such as putting quotation marks around the arguments.
  79. Example:
  80. Using bash, the following command line option would match and exclude "item name":
  81. ``--pattern='-path/item name'``
  82. Note that when patterns are used within a pattern file directly read by borg,
  83. e.g. when using ``--exclude-from`` or ``--patterns-from``, there is no shell
  84. involved and thus no quotation marks are required.
  85. The ``--exclude-from`` option permits loading exclusion patterns from a text
  86. file with one pattern per line. Lines empty or starting with the number sign
  87. ('#') after removing whitespace on both ends are ignored. The optional style
  88. selector prefix is also supported for patterns loaded from a file. Due to
  89. whitespace removal, paths with whitespace at the beginning or end can only be
  90. excluded using regular expressions.
  91. To test your exclusion patterns without performing an actual backup you can
  92. run ``borg create --list --dry-run ...``.
  93. Examples::
  94. # Exclude '/home/user/file.o' but not '/home/user/file.odt':
  95. $ borg create -e '*.o' backup /
  96. # Exclude '/home/user/junk' and '/home/user/subdir/junk' but
  97. # not '/home/user/importantjunk' or '/etc/junk':
  98. $ borg create -e 'home/*/junk' backup /
  99. # Exclude the contents of '/home/user/cache' but not the directory itself:
  100. $ borg create -e home/user/cache/ backup /
  101. # The file '/home/user/cache/important' is *not* backed up:
  102. $ borg create -e home/user/cache/ backup / /home/user/cache/important
  103. # The contents of directories in '/home' are not backed up when their name
  104. # ends in '.tmp'
  105. $ borg create --exclude 're:^home/[^/]+\.tmp/' backup /
  106. # Load exclusions from file
  107. $ cat >exclude.txt <<EOF
  108. # Comment line
  109. home/*/junk
  110. *.tmp
  111. fm:aa:something/*
  112. re:^home/[^/]+\.tmp/
  113. sh:home/*/.thumbnails
  114. # Example with spaces, no need to escape as it is processed by borg
  115. some file with spaces.txt
  116. EOF
  117. $ borg create --exclude-from exclude.txt backup /
  118. A more general and easier to use way to define filename matching patterns
  119. exists with the ``--pattern`` and ``--patterns-from`` options. Using
  120. these, you may specify the backup roots, default pattern styles and
  121. patterns for inclusion and exclusion.
  122. Root path prefix ``R``
  123. A recursion root path starts with the prefix ``R``, followed by a path
  124. (a plain path, not a file pattern). Use this prefix to have the root
  125. paths in the patterns file rather than as command line arguments.
  126. Pattern style prefix ``P``
  127. To change the default pattern style, use the ``P`` prefix, followed by
  128. the pattern style abbreviation (``fm``, ``pf``, ``pp``, ``re``, ``sh``).
  129. All patterns following this line will use this style until another style
  130. is specified.
  131. Exclude pattern prefix ``-``
  132. Use the prefix ``-``, followed by a pattern, to define an exclusion.
  133. This has the same effect as the ``--exclude`` option.
  134. Exclude no-recurse pattern prefix ``!``
  135. Use the prefix ``!``, followed by a pattern, to define an exclusion
  136. that does not recurse into subdirectories. This saves time, but
  137. prevents include patterns to match any files in subdirectories.
  138. Include pattern prefix ``+``
  139. Use the prefix ``+``, followed by a pattern, to define inclusions.
  140. This is useful to include paths that are covered in an exclude
  141. pattern and would otherwise not be backed up.
  142. .. note::
  143. Via ``--pattern`` or ``--patterns-from`` you can define BOTH inclusion and exclusion
  144. of files using pattern prefixes ``+`` and ``-``. With ``--exclude`` and
  145. ``--exclude-from`` ONLY excludes are defined.
  146. The first matching pattern is used, so if an include pattern matches
  147. before an exclude pattern, the file is backed up. Note that a no-recurse
  148. exclude stops examination of subdirectories so that potential includes
  149. will not match - use normal excludes for such use cases.
  150. Example::
  151. # Define the recursion root
  152. R /
  153. # Exclude all iso files in any directory
  154. - **/*.iso
  155. # Explicitly include all inside etc and root
  156. + etc/**
  157. + root/**
  158. # Exclude a specific directory under each user's home directories
  159. - home/*/.cache
  160. # Explicitly include everything in /home
  161. + home/**
  162. # Explicitly exclude some directories without recursing into them
  163. ! re:^(dev|proc|run|sys|tmp)
  164. # Exclude all other files and directories
  165. # that are not specifically included earlier.
  166. - **
  167. .. note::
  168. It's possible that a sub-directory/file is matched while parent directories are not.
  169. In that case, parent directories are not backed up thus their user, group, permission,
  170. etc. can not be restored.
  171. Note that the default pattern style for ``--pattern`` and ``--patterns-from`` is
  172. shell style (`sh:`), so those patterns behave similar to rsync include/exclude
  173. patterns. The pattern style can be set via the `P` prefix.
  174. Patterns (``--pattern``) and excludes (``--exclude``) from the command line are
  175. considered first (in the order of appearance). Then patterns from ``--patterns-from``
  176. are added. Exclusion patterns from ``--exclude-from`` files are appended last.
  177. Examples::
  178. # backup pics, but not the ones from 2018, except the good ones:
  179. # note: using = is essential to avoid cmdline argument parsing issues.
  180. borg create --pattern=+pics/2018/good --pattern=-pics/2018 repo::arch pics
  181. # use a file with patterns:
  182. borg create --patterns-from patterns.lst repo::arch
  183. The patterns.lst file could look like that::
  184. # "sh:" pattern style is the default, so the following line is not needed:
  185. P sh
  186. R /
  187. # can be rebuild
  188. - home/*/.cache
  189. # they're downloads for a reason
  190. - home/*/Downloads
  191. # susan is a nice person
  192. # include susans home
  193. + home/susan
  194. # also back up this exact file
  195. + pf:home/bobby/specialfile.txt
  196. # don't backup the other home directories
  197. - home/*
  198. # don't even look in /proc
  199. ! proc
  200. You can specify recursion roots either on the command line or in a patternfile::
  201. # these two commands do the same thing
  202. borg create --exclude home/bobby/junk repo::arch /home/bobby /home/susan
  203. borg create --patterns-from patternfile.lst repo::arch
  204. The patternfile::
  205. # note that excludes use fm: by default and patternfiles use sh: by default.
  206. # therefore, we need to specify fm: to have the same exact behavior.
  207. P fm
  208. R /home/bobby
  209. R /home/susan
  210. - home/bobby/junk
  211. This allows you to share the same patterns between multiple repositories
  212. without needing to specify them on the command line.
  213. .. _borg_placeholders:
  214. borg help placeholders
  215. ~~~~~~~~~~~~~~~~~~~~~~
  216. Repository (or Archive) URLs, ``--prefix``, ``--glob-archives``, ``--comment``
  217. and ``--remote-path`` values support these placeholders:
  218. {hostname}
  219. The (short) hostname of the machine.
  220. {fqdn}
  221. The full name of the machine.
  222. {reverse-fqdn}
  223. The full name of the machine in reverse domain name notation.
  224. {now}
  225. The current local date and time, by default in ISO-8601 format.
  226. You can also supply your own `format string <https://docs.python.org/3.9/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
  227. {utcnow}
  228. The current UTC date and time, by default in ISO-8601 format.
  229. You can also supply your own `format string <https://docs.python.org/3.9/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}
  230. {user}
  231. The user name (or UID, if no name is available) of the user running borg.
  232. {pid}
  233. The current process ID.
  234. {borgversion}
  235. The version of borg, e.g.: 1.0.8rc1
  236. {borgmajor}
  237. The version of borg, only the major version, e.g.: 1
  238. {borgminor}
  239. The version of borg, only major and minor version, e.g.: 1.0
  240. {borgpatch}
  241. The version of borg, only major, minor and patch version, e.g.: 1.0.8
  242. If literal curly braces need to be used, double them for escaping::
  243. borg create /path/to/repo::{{literal_text}}
  244. Examples::
  245. borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
  246. borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ...
  247. borg prune --glob-archives '{hostname}-*' ...
  248. .. note::
  249. systemd uses a difficult, non-standard syntax for command lines in unit files (refer to
  250. the `systemd.unit(5)` manual page).
  251. When invoking borg from unit files, pay particular attention to escaping,
  252. especially when using the now/utcnow placeholders, since systemd performs its own
  253. %-based variable replacement even in quoted text. To avoid interference from systemd,
  254. double all percent signs (``{hostname}-{now:%Y-%m-%d_%H:%M:%S}``
  255. becomes ``{hostname}-{now:%%Y-%%m-%%d_%%H:%%M:%%S}``).
  256. .. _borg_compression:
  257. borg help compression
  258. ~~~~~~~~~~~~~~~~~~~~~
  259. It is no problem to mix different compression methods in one repo,
  260. deduplication is done on the source data chunks (not on the compressed
  261. or encrypted data).
  262. If some specific chunk was once compressed and stored into the repo, creating
  263. another backup that also uses this chunk will not change the stored chunk.
  264. So if you use different compression specs for the backups, whichever stores a
  265. chunk first determines its compression. See also borg recreate.
  266. Compression is lz4 by default. If you want something else, you have to specify what you want.
  267. Valid compression specifiers are:
  268. none
  269. Do not compress.
  270. lz4
  271. Use lz4 compression. Very high speed, very low compression. (default)
  272. zstd[,L]
  273. Use zstd ("zstandard") compression, a modern wide-range algorithm.
  274. If you do not explicitly give the compression level L (ranging from 1
  275. to 22), it will use level 3.
  276. Archives compressed with zstd are not compatible with borg < 1.1.4.
  277. zlib[,L]
  278. Use zlib ("gz") compression. Medium speed, medium compression.
  279. If you do not explicitly give the compression level L (ranging from 0
  280. to 9), it will use level 6.
  281. Giving level 0 (means "no compression", but still has zlib protocol
  282. overhead) is usually pointless, you better use "none" compression.
  283. lzma[,L]
  284. Use lzma ("xz") compression. Low speed, high compression.
  285. If you do not explicitly give the compression level L (ranging from 0
  286. to 9), it will use level 6.
  287. Giving levels above 6 is pointless and counterproductive because it does
  288. not compress better due to the buffer size used by borg - but it wastes
  289. lots of CPU cycles and RAM.
  290. auto,C[,L]
  291. Use a built-in heuristic to decide per chunk whether to compress or not.
  292. The heuristic tries with lz4 whether the data is compressible.
  293. For incompressible data, it will not use compression (uses "none").
  294. For compressible data, it uses the given C[,L] compression - with C[,L]
  295. being any valid compression specifier. This can be helpful for media files
  296. which often cannot be compressed much more.
  297. obfuscate,SPEC,C[,L]
  298. Use compressed-size obfuscation to make fingerprinting attacks based on
  299. the observable stored chunk size more difficult. Note:
  300. - You must combine this with encryption, or it won't make any sense.
  301. - Your repo size will be bigger, of course.
  302. - A chunk is limited by the constant ``MAX_DATA_SIZE`` (cur. ~20MiB).
  303. The SPEC value determines how the size obfuscation works:
  304. *Relative random reciprocal size variation* (multiplicative)
  305. Size will increase by a factor, relative to the compressed data size.
  306. Smaller factors are used often, larger factors rarely.
  307. Available factors::
  308. 1: 0.01 .. 100
  309. 2: 0.1 .. 1,000
  310. 3: 1 .. 10,000
  311. 4: 10 .. 100,000
  312. 5: 100 .. 1,000,000
  313. 6: 1,000 .. 10,000,000
  314. Example probabilities for SPEC ``1``::
  315. 90 % 0.01 .. 0.1
  316. 9 % 0.1 .. 1
  317. 0.9 % 1 .. 10
  318. 0.09% 10 .. 100
  319. *Randomly sized padding up to the given size* (additive)
  320. ::
  321. 110: 1kiB (2 ^ (SPEC - 100))
  322. ...
  323. 120: 1MiB
  324. ...
  325. 123: 8MiB (max.)
  326. *Padmé padding* (deterministic)
  327. ::
  328. 250: pads to sums of powers of 2, max 12% overhead
  329. Uses the Padmé algorithm to deterministically pad the compressed size to a sum of
  330. powers of 2, limiting overhead to 12%. See https://lbarman.ch/blog/padme/ for details.
  331. Examples::
  332. borg create --compression lz4 REPO::ARCHIVE data
  333. borg create --compression zstd REPO::ARCHIVE data
  334. borg create --compression zstd,10 REPO::ARCHIVE data
  335. borg create --compression zlib REPO::ARCHIVE data
  336. borg create --compression zlib,1 REPO::ARCHIVE data
  337. borg create --compression auto,lzma,6 REPO::ARCHIVE data
  338. borg create --compression auto,lzma ...
  339. borg create --compression obfuscate,110,none ...
  340. borg create --compression obfuscate,3,auto,zstd,10 ...
  341. borg create --compression obfuscate,2,zstd,6 ...
  342. borg create --compression obfuscate,250,zstd,3 ...