borg-patterns.1 7.5 KB

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