help.rst.inc 18 KB

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