borg-patterns.1 8.9 KB

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