borg-patterns.1 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "BORG-PATTERNS" 1 "2022-02-05" "" "borg backup tool"
  31. .SH NAME
  32. borg-patterns \- Details regarding patterns
  33. .SH DESCRIPTION
  34. .sp
  35. The path/filenames used as input for the pattern matching start from the
  36. currently active recursion root. You usually give the recursion root(s)
  37. when invoking borg and these can be either relative or absolute paths.
  38. .sp
  39. So, when you give \fIrelative/\fP as root, the paths going into the matcher
  40. will look like \fIrelative/.../file.ext\fP\&. When you give \fI/absolute/\fP as
  41. root, they will look like \fI/absolute/.../file.ext\fP\&.
  42. .sp
  43. File paths in Borg archives are always stored normalized and relative.
  44. This means that e.g. \fBborg create /path/to/repo ../some/path\fP will
  45. store all files as \fIsome/path/.../file.ext\fP and \fBborg create
  46. /path/to/repo /home/user\fP will store all files as
  47. \fIhome/user/.../file.ext\fP\&.
  48. .sp
  49. File patterns support these styles: fnmatch, shell, regular expressions,
  50. path prefixes and path full\-matches. By default, fnmatch is used for
  51. \fB\-\-exclude\fP patterns and shell\-style is used for the \fB\-\-pattern\fP
  52. .IP "System Message: ERROR/3 (docs/borg-patterns.rst:, line 43)"
  53. Unexpected indentation.
  54. .INDENT 0.0
  55. .INDENT 3.5
  56. option. For commands that support patterns in their \fBPATH\fP argument
  57. .UNINDENT
  58. .UNINDENT
  59. .IP "System Message: WARNING/2 (docs/borg-patterns.rst:, line 44)"
  60. Block quote ends without a blank line; unexpected unindent.
  61. .sp
  62. like (\fBborg list\fP), the default pattern is path prefix.
  63. .sp
  64. Starting with Borg 1.2, for all but regular expression pattern matching
  65. styles, all paths are treated as relative, meaning that a leading path
  66. separator is removed after normalizing and before matching. This allows
  67. you to use absolute or relative patterns arbitrarily.
  68. .sp
  69. If followed by a colon (\(aq:\(aq) the first two characters of a pattern are
  70. used as a style selector. Explicit style selection is necessary when a
  71. non\-default style is desired or when the desired pattern starts with
  72. two alphanumeric characters followed by a colon (i.e. \fIaa:something/*\fP).
  73. .INDENT 0.0
  74. .TP
  75. .B \fI\%Fnmatch\fP, selector \fIfm:\fP
  76. This is the default style for \fB\-\-exclude\fP and \fB\-\-exclude\-from\fP\&.
  77. These patterns use a variant of shell pattern syntax, with \(aq*\(aq matching
  78. any number of characters, \(aq?\(aq matching any single character, \(aq[...]\(aq
  79. matching any single character specified, including ranges, and \(aq[!...]\(aq
  80. matching any character not specified. For the purpose of these patterns,
  81. the path separator (backslash for Windows and \(aq/\(aq on other systems) is not
  82. treated specially. Wrap meta\-characters in brackets for a literal
  83. match (i.e. \fI[?]\fP to match the literal character \fI?\fP). For a path
  84. to match a pattern, the full path must match, or it must match
  85. from the start of the full path to just before a path separator. Except
  86. for the root path, paths will never end in the path separator when
  87. matching is attempted. Thus, if a given pattern ends in a path
  88. separator, a \(aq*\(aq is appended before matching is attempted. A leading
  89. path separator is always removed.
  90. .TP
  91. .B Shell\-style patterns, selector \fIsh:\fP
  92. This is the default style for \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP\&.
  93. Like fnmatch patterns these are similar to shell patterns. The difference
  94. is that the pattern may include \fI**/\fP for matching zero or more directory
  95. levels, \fI*\fP for matching zero or more arbitrary characters with the
  96. exception of any path separator. A leading path separator is always removed.
  97. .TP
  98. .B Regular expressions, selector \fIre:\fP
  99. Regular expressions similar to those found in Perl are supported. Unlike
  100. shell patterns regular expressions are not required to match the full
  101. path and any substring match is sufficient. It is strongly recommended to
  102. anchor patterns to the start (\(aq^\(aq), to the end (\(aq$\(aq) or both. Path
  103. separators (backslash for Windows and \(aq/\(aq on other systems) in paths are
  104. always normalized to a forward slash (\(aq/\(aq) before applying a pattern. The
  105. regular expression syntax is described in the \fI\%Python documentation for
  106. the re module\fP\&.
  107. .TP
  108. .B Path prefix, selector \fIpp:\fP
  109. This pattern style is useful to match whole sub\-directories. The pattern
  110. \fIpp:root/somedir\fP matches \fIroot/somedir\fP and everything therein. A leading
  111. path separator is always removed.
  112. .TP
  113. .B Path full\-match, selector \fIpf:\fP
  114. This pattern style is (only) useful to match full paths.
  115. This is kind of a pseudo pattern as it can not have any variable or
  116. unspecified parts \- the full path must be given. \fIpf:root/file.ext\fP matches
  117. \fIroot/file.ext\fP only. A leading path separator is always removed.
  118. .sp
  119. Implementation note: this is implemented via very time\-efficient O(1)
  120. hashtable lookups (this means you can have huge amounts of such patterns
  121. without impacting performance much).
  122. Due to that, this kind of pattern does not respect any context or order.
  123. If you use such a pattern to include a file, it will always be included
  124. (if the directory recursion encounters it).
  125. Other include/exclude patterns that would normally match will be ignored.
  126. Same logic applies for exclude.
  127. .UNINDENT
  128. .sp
  129. \fBNOTE:\fP
  130. .INDENT 0.0
  131. .INDENT 3.5
  132. \fIre:\fP, \fIsh:\fP and \fIfm:\fP patterns are all implemented on top of the Python SRE
  133. engine. It is very easy to formulate patterns for each of these types which
  134. requires an inordinate amount of time to match paths. If untrusted users
  135. are able to supply patterns, ensure they cannot supply \fIre:\fP patterns.
  136. Further, ensure that \fIsh:\fP and \fIfm:\fP patterns only contain a handful of
  137. wildcards at most.
  138. .UNINDENT
  139. .UNINDENT
  140. .sp
  141. Exclusions can be passed via the command line option \fB\-\-exclude\fP\&. When used
  142. from within a shell, the patterns should be quoted to protect them from
  143. expansion.
  144. .sp
  145. The \fB\-\-exclude\-from\fP option permits loading exclusion patterns from a text
  146. file with one pattern per line. Lines empty or starting with the number sign
  147. (\(aq#\(aq) after removing whitespace on both ends are ignored. The optional style
  148. selector prefix is also supported for patterns loaded from a file. Due to
  149. whitespace removal, paths with whitespace at the beginning or end can only be
  150. excluded using regular expressions.
  151. .sp
  152. To test your exclusion patterns without performing an actual backup you can
  153. run \fBborg create \-\-list \-\-dry\-run ...\fP\&.
  154. .sp
  155. Examples:
  156. .INDENT 0.0
  157. .INDENT 3.5
  158. .sp
  159. .nf
  160. .ft C
  161. # Exclude \(aq/home/user/file.o\(aq but not \(aq/home/user/file.odt\(aq:
  162. $ borg create \-e \(aq*.o\(aq backup /
  163. # Exclude \(aq/home/user/junk\(aq and \(aq/home/user/subdir/junk\(aq but
  164. # not \(aq/home/user/importantjunk\(aq or \(aq/etc/junk\(aq:
  165. $ borg create \-e \(aq/home/*/junk\(aq backup /
  166. # Exclude the contents of \(aq/home/user/cache\(aq but not the directory itself:
  167. $ borg create \-e home/user/cache/ backup /
  168. # The file \(aq/home/user/cache/important\(aq is *not* backed up:
  169. $ borg create \-e /home/user/cache/ backup / /home/user/cache/important
  170. # The contents of directories in \(aq/home\(aq are not backed up when their name
  171. # ends in \(aq.tmp\(aq
  172. $ borg create \-\-exclude \(aqre:^/home/[^/]+\e.tmp/\(aq backup /
  173. # Load exclusions from file
  174. $ cat >exclude.txt <<EOF
  175. # Comment line
  176. /home/*/junk
  177. *.tmp
  178. fm:aa:something/*
  179. re:^/home/[^/]+\e.tmp/
  180. sh:/home/*/.thumbnails
  181. # Example with spaces, no need to escape as it is processed by borg
  182. some file with spaces.txt
  183. EOF
  184. $ borg create \-\-exclude\-from exclude.txt backup /
  185. A more general and easier to use way to define filename matching patterns exists
  186. with the \(ga\(ga\-\-pattern\(ga\(ga and \(ga\(ga\-\-patterns\-from\(ga\(ga options. Using these, you may
  187. specify the backup roots (starting points) and patterns for inclusion/exclusion.
  188. A root path starts with the prefix \(gaR\(ga, followed by a path (a plain path, not a
  189. file pattern). An include rule starts with the prefix +, an exclude rule starts
  190. with the prefix \-, an exclude\-norecurse rule starts with !, all followed by a pattern.
  191. \&.. note::
  192. Via \(ga\(ga\-\-pattern\(ga\(ga or \(ga\(ga\-\-patterns\-from\(ga\(ga you can define BOTH inclusion and exclusion
  193. of files using pattern prefixes \(ga\(ga+\(ga\(ga and \(ga\(ga\-\(ga\(ga. With \(ga\(ga\-\-exclude\(ga\(ga and
  194. \(ga\(ga\-\-exclude\-from\(ga\(ga ONLY excludes are defined.
  195. Inclusion patterns are useful to include paths that are contained in an excluded
  196. path. The first matching pattern is used so if an include pattern matches before
  197. an exclude pattern, the file is backed up. If an exclude\-norecurse pattern matches
  198. a directory, it won\(aqt recurse into it and won\(aqt discover any potential matches for
  199. include rules below that directory.
  200. \&.. note::
  201. It\(aqs possible that a sub\-directory/file is matched while parent directories are not.
  202. In that case, parent directories are not backed up thus their user, group, permission,
  203. etc. can not be restored.
  204. Note that the default pattern style for \(ga\(ga\-\-pattern\(ga\(ga and \(ga\(ga\-\-patterns\-from\(ga\(ga is
  205. shell style (\(gash:\(ga), so those patterns behave similar to rsync include/exclude
  206. patterns. The pattern style can be set via the \(gaP\(ga prefix.
  207. Patterns (\(ga\(ga\-\-pattern\(ga\(ga) and excludes (\(ga\(ga\-\-exclude\(ga\(ga) from the command line are
  208. considered first (in the order of appearance). Then patterns from \(ga\(ga\-\-patterns\-from\(ga\(ga
  209. are added. Exclusion patterns from \(ga\(ga\-\-exclude\-from\(ga\(ga files are appended last.
  210. Examples::
  211. # backup pics, but not the ones from 2018, except the good ones:
  212. # note: using = is essential to avoid cmdline argument parsing issues.
  213. borg create \-\-pattern=+pics/2018/good \-\-pattern=\-pics/2018 repo::arch pics
  214. # use a file with patterns:
  215. borg create \-\-patterns\-from patterns.lst repo::arch
  216. The patterns.lst file could look like that::
  217. # "sh:" pattern style is the default, so the following line is not needed:
  218. P sh
  219. R /
  220. # can be rebuild
  221. \- /home/*/.cache
  222. # they\(aqre downloads for a reason
  223. \- /home/*/Downloads
  224. # susan is a nice person
  225. # include susans home
  226. + /home/susan
  227. # don\(aqt backup the other home directories
  228. \- /home/*
  229. # don\(aqt even look in /proc
  230. ! /proc
  231. .ft P
  232. .fi
  233. .UNINDENT
  234. .UNINDENT
  235. .SH AUTHOR
  236. The Borg Collective
  237. .\" Generated by docutils manpage writer.
  238. .