help.rst.inc 15 KB

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