help.rst.inc 20 KB

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