help.rst.inc 18 KB

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