| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 | .\" Man page generated from reStructuredText....nr rst2man-indent-level 0..de1 rstReportMargin\\$1 \\n[an-margin]level \\n[rst2man-indent-level]level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]-\\n[rst2man-indent0]\\n[rst2man-indent1]\\n[rst2man-indent2]...de1 INDENT.\" .rstReportMargin pre:. RS \\$1. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]. nr rst2man-indent-level +1.\" .rstReportMargin post:...de UNINDENT. RE.\" indent \\n[an-margin].\" old: \\n[rst2man-indent\\n[rst2man-indent-level]].nr rst2man-indent-level -1.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]].in \\n[rst2man-indent\\n[rst2man-indent-level]]u...TH "BORG-PATTERNS" 1 "2024-09-09" "" "borg backup tool".SH NAMEborg-patterns \- Details regarding patterns.SH DESCRIPTION.spWhen specifying one or more file paths in a Borg command that supportspatterns for the respective option or argument, you can apply thepatterns described here to include only desired files and/or excludeunwanted ones. Patterns can be used.INDENT 0.0.IP \(bu 2for \fB\-\-exclude\fP option,.IP \(bu 2in the file given with \fB\-\-exclude\-from\fP option,.IP \(bu 2for \fB\-\-pattern\fP option,.IP \(bu 2in the file given with \fB\-\-patterns\-from\fP option and.IP \(bu 2for \fBPATH\fP arguments that explicitly support them..UNINDENT.spBorg always stores all file paths normalized and relative to thecurrent recursion root. The recursion root is also named \fBPATH\fP inBorg commands like \fIborg create\fP that do a file discovery, so do notconfuse the root with the \fBPATH\fP argument of e.g. \fIborg extract\fP\&..spStarting with Borg 1.2, paths that are matched against patterns alwaysappear relative. If you give \fB/absolute/\fP as root, the paths goinginto the matcher will start with \fBabsolute/\fP\&.If you give \fB\&../../relative\fP as root, the paths will be normalizedas \fBrelative/\fP\&..spBorg supports different pattern styles. To define a non\-defaultstyle for a specific pattern, prefix it with two characters followedby a colon \(aq:\(aq (i.e. \fBfm:path/*\fP, \fBsh:path/**\fP)..INDENT 0.0.TP.B \fI\%Fnmatch\fP, selector \fBfm:\fPThis is the default style for \fB\-\-exclude\fP and \fB\-\-exclude\-from\fP\&.These patterns use a variant of shell pattern syntax, with \(aq*\(aq matchingany number of characters, \(aq?\(aq matching any single character, \(aq[...]\(aqmatching any single character specified, including ranges, and \(aq[!...]\(aqmatching any character not specified. For the purpose of these patterns,the path separator (backslash for Windows and \(aq/\(aq on other systems) is nottreated specially. Wrap meta\-characters in brackets for a literalmatch (i.e. \fB[?]\fP to match the literal character \(aq?\(aq). For a pathto match a pattern, the full path must match, or it must matchfrom the start of the full path to just before a path separator. Exceptfor the root path, paths will never end in the path separator whenmatching is attempted.  Thus, if a given pattern ends in a pathseparator, a \(aq*\(aq is appended before matching is attempted. A leadingpath separator is always removed..TP.B Shell\-style patterns, selector \fBsh:\fPThis is the default style for \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP\&.Like fnmatch patterns these are similar to shell patterns. The differenceis that the pattern may include \fB**/\fP for matching zero or more directorylevels, \fB*\fP for matching zero or more arbitrary characters with theexception of any path separator, \fB{}\fP containing comma\-separatedalternative patterns. A leading path separator is always removed..TP.B \fI\%Regular expressions\fP, selector \fBre:\fPUnlike shell patterns, regular expressions are not required to match the fullpath and any substring match is sufficient. It is strongly recommended toanchor patterns to the start (\(aq^\(aq), to the end (\(aq$\(aq) or both. Pathseparators (backslash for Windows and \(aq/\(aq on other systems) in paths arealways normalized to a forward slash \(aq/\(aq before applying a pattern..TP.B Path prefix, selector \fBpp:\fPThis pattern style is useful to match whole sub\-directories. The pattern\fBpp:root/somedir\fP matches \fBroot/somedir\fP and everything therein.A leading path separator is always removed..TP.B Path full\-match, selector \fBpf:\fPThis pattern style is (only) useful to match full paths.This is kind of a pseudo pattern as it can not have any variable orunspecified parts \- the full path must be given. \fBpf:root/file.ext\fPmatches \fBroot/file.ext\fP only. A leading path separator is alwaysremoved..spImplementation note: this is implemented via very time\-efficient O(1)hashtable lookups (this means you can have huge amounts of such patternswithout impacting performance much).Due to that, this kind of pattern does not respect any context or order.If you use such a pattern to include a file, it will always be included(if the directory recursion encounters it).Other include/exclude patterns that would normally match will be ignored.Same logic applies for exclude..UNINDENT.sp\fBNOTE:\fP.INDENT 0.0.INDENT 3.5\fBre:\fP, \fBsh:\fP and \fBfm:\fP patterns are all implemented on top ofthe Python SRE engine. It is very easy to formulate patterns for eachof these types which requires an inordinate amount of time to matchpaths. If untrusted users are able to supply patterns, ensure theycannot supply \fBre:\fP patterns. Further, ensure that \fBsh:\fP and\fBfm:\fP patterns only contain a handful of wildcards at most..UNINDENT.UNINDENT.spExclusions can be passed via the command line option \fB\-\-exclude\fP\&. When usedfrom within a shell, the patterns should be quoted to protect them fromexpansion..spThe \fB\-\-exclude\-from\fP option permits loading exclusion patterns from a textfile with one pattern per line. Lines empty or starting with the hash sign\(aq#\(aq after removing whitespace on both ends are ignored. The optional styleselector prefix is also supported for patterns loaded from a file. Due towhitespace removal, paths with whitespace at the beginning or end can only beexcluded using regular expressions..spTo test your exclusion patterns without performing an actual backup you canrun \fBborg create \-\-list \-\-dry\-run ...\fP\&..spExamples:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# Exclude \(aq/home/user/file.o\(aq but not \(aq/home/user/file.odt\(aq:$ borg create \-e \(aq*.o\(aq archive /# Exclude \(aq/home/user/junk\(aq and \(aq/home/user/subdir/junk\(aq but# not \(aq/home/user/importantjunk\(aq or \(aq/etc/junk\(aq:$ borg create \-e \(aqhome/*/junk\(aq archive /# Exclude the contents of \(aq/home/user/cache\(aq but not the directory itself:$ borg create \-e home/user/cache/ archive /# The file \(aq/home/user/cache/important\(aq is *not* backed up:$ borg create \-e home/user/cache/ archive / /home/user/cache/important# The contents of directories in \(aq/home\(aq are not backed up when their name# ends in \(aq.tmp\(aq$ borg create \-\-exclude \(aqre:^home/[^/]+\e.tmp/\(aq archive /# Load exclusions from file$ cat >exclude.txt <<EOF# Comment linehome/*/junk*.tmpfm:aa:something/*re:^home/[^/]+\e.tmp/sh:home/*/.thumbnails# Example with spaces, no need to escape as it is processed by borgsome file with spaces.txtEOF$ borg create \-\-exclude\-from exclude.txt archive /.ft P.fi.UNINDENT.UNINDENT.spA more general and easier to use way to define filename matching patternsexists with the \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP options. Usingthese, you may specify the backup roots, default pattern styles andpatterns for inclusion and exclusion..INDENT 0.0.TP.B Root path prefix \fBR\fPA recursion root path starts with the prefix \fBR\fP, followed by a path(a plain path, not a file pattern). Use this prefix to have the rootpaths in the patterns file rather than as command line arguments..TP.B Pattern style prefix \fBP\fPTo change the default pattern style, use the \fBP\fP prefix, followed bythe pattern style abbreviation (\fBfm\fP, \fBpf\fP, \fBpp\fP, \fBre\fP, \fBsh\fP).All patterns following this line will use this style until another styleis specified..TP.B Exclude pattern prefix \fB\-\fPUse the prefix \fB\-\fP, followed by a pattern, to define an exclusion.This has the same effect as the \fB\-\-exclude\fP option..TP.B Exclude no\-recurse pattern prefix \fB!\fPUse the prefix \fB!\fP, followed by a pattern, to define an exclusionthat does not recurse into subdirectories. This saves time, butprevents include patterns to match any files in subdirectories..TP.B Include pattern prefix \fB+\fPUse the prefix \fB+\fP, followed by a pattern, to define inclusions.This is useful to include paths that are covered in an excludepattern and would otherwise not be backed up..UNINDENT.spThe first matching pattern is used, so if an include pattern matchesbefore an exclude pattern, the file is backed up. Note that a no\-recurseexclude stops examination of subdirectories so that potential includeswill not match \- use normal excludes for such use cases..spExample:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# Define the recursion rootR /# Exclude all iso files in any directory\- **/*.iso# Explicitly include all inside etc and root+ etc/**+ root/**# Exclude a specific directory under each user\(aqs home directories\- home/*/.cache# Explicitly include everything in /home+ home/**# Explicitly exclude some directories without recursing into them! re:^(dev|proc|run|sys|tmp)# Exclude all other files and directories# that are not specifically included earlier.\- **.ft P.fi.UNINDENT.UNINDENT.sp\fBTip: You can easily test your patterns with \-\-dry\-run and  \-\-list\fP:.INDENT 0.0.INDENT 3.5.sp.nf.ft C$ borg create \-\-dry\-run \-\-list \-\-patterns\-from patterns.txt archive.ft P.fi.UNINDENT.UNINDENT.spThis will list the considered files one per line, prefixed with acharacter that indicates the action (e.g. \(aqx\(aq for excluding, see\fBItem flags\fP in \fIborg create\fP usage docs)..sp\fBNOTE:\fP.INDENT 0.0.INDENT 3.5It\(aqs possible that a sub\-directory/file is matched while parentdirectories are not. In that case, parent directories are not backedup and thus their user, group, permission, etc. cannot be restored..UNINDENT.UNINDENT.spPatterns (\fB\-\-pattern\fP) and excludes (\fB\-\-exclude\fP) from the command line areconsidered first (in the order of appearance). Then patterns from \fB\-\-patterns\-from\fPare added. Exclusion patterns from \fB\-\-exclude\-from\fP files are appended last..spExamples:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# back up pics, but not the ones from 2018, except the good ones:# note: using = is essential to avoid cmdline argument parsing issues.borg create \-\-pattern=+pics/2018/good \-\-pattern=\-pics/2018 archive pics# back up only JPG/JPEG files (case insensitive) in all home directories:borg create \-\-pattern \(aq+ re:\e.jpe?g(?i)$\(aq archive /home# back up homes, but exclude big downloads (like .ISO files) or hidden files:borg create \-\-exclude \(aqre:\e.iso(?i)$\(aq \-\-exclude \(aqsh:home/**/.*\(aq archive /home# use a file with patterns (recursion root \(aq/\(aq via command line):borg create \-\-patterns\-from patterns.lst archive /.ft P.fi.UNINDENT.UNINDENT.spThe patterns.lst file could look like that:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# \(dqsh:\(dq pattern style is the default# exclude caches\- home/*/.cache# include susans home+ home/susan# also back up this exact file+ pf:home/bobby/specialfile.txt# don\(aqt back up the other home directories\- home/*# don\(aqt even look in /dev, /proc, /run, /sys, /tmp (note: would exclude files like /device, too)! re:^(dev|proc|run|sys|tmp).ft P.fi.UNINDENT.UNINDENT.spYou can specify recursion roots either on the command line or in a patternfile:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# these two commands do the same thingborg create \-\-exclude home/bobby/junk archive /home/bobby /home/susanborg create \-\-patterns\-from patternfile.lst archive.ft P.fi.UNINDENT.UNINDENT.sppatternfile.lst:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# note that excludes use fm: by default and patternfiles use sh: by default.# therefore, we need to specify fm: to have the same exact behavior.P fmR /home/bobbyR /home/susan\- home/bobby/junk.ft P.fi.UNINDENT.UNINDENT.spThis allows you to share the same patterns between multiple repositorieswithout needing to specify them on the command line..SH AUTHORThe Borg Collective.\" Generated by docutils manpage writer..
 |