help.rst.inc 16 KB

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