borg-patterns.1 7.9 KB

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