| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 | .\" 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 "2022-01-23" "" "borg backup tool".SH NAMEborg-patterns \- Details regarding patterns.SH DESCRIPTION.spThe path/filenames used as input for the pattern matching start from thecurrently active recursion root. You usually give the recursion root(s)when invoking borg and these can be either relative or absolute paths..spSo, when you give \fIrelative/\fP as root, the paths going into the matcherwill look like \fIrelative/.../file.ext\fP\&. When you give \fI/absolute/\fP asroot, they will look like \fI/absolute/.../file.ext\fP\&..spFile paths in Borg archives are always stored normalized and relative.This means that e.g. \fBborg create /path/to/repo ../some/path\fP willstore all files as \fIsome/path/.../file.ext\fP and \fBborg create/path/to/repo /home/user\fP will store all files as\fIhome/user/.../file.ext\fP\&..spFile patterns support these styles: fnmatch, shell, regular expressions,path prefixes and path full\-matches. By default, fnmatch is used for\fB\-\-exclude\fP patterns and shell\-style is used for the experimental\fB\-\-pattern\fP option. For commands that support patterns in their\fBPATH\fP argument like (\fBborg list\fP), the default pattern is pathprefix..spStarting with Borg 1.2, for all but regular expression pattern matchingstyles, all paths are treated as relative, meaning that a leading pathseparator is removed after normalizing and before matching. This allowsyou to use absolute or relative patterns arbitrarily..spIf followed by a colon (\(aq:\(aq) the first two characters of a pattern areused as a style selector. Explicit style selection is necessary when anon\-default style is desired or when the desired pattern starts withtwo alphanumeric characters followed by a colon (i.e. \fIaa:something/*\fP)..INDENT 0.0.TP.B \fI\%Fnmatch\fP, selector \fIfm:\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. \fI[?]\fP to match the literal character \fI?\fP). 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 \fIsh:\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 \fI**/\fP for matching zero or more directorylevels, \fI*\fP for matching zero or more arbitrary characters with theexception of any path separator. A leading path separator is always removed..TP.B Regular expressions, selector \fIre:\fPRegular expressions similar to those found in Perl are supported. Unlikeshell 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. Theregular expression syntax is described in the \fI\%Python documentation forthe re module\fP\&..TP.B Path prefix, selector \fIpp:\fPThis pattern style is useful to match whole sub\-directories. The pattern\fIpp:root/somedir\fP matches \fIroot/somedir\fP and everything therein. A leadingpath separator is always removed..TP.B Path full\-match, selector \fIpf:\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. \fIpf:root/file.ext\fP matches\fIroot/file.ext\fP only. A leading path separator is always removed..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\fIre:\fP, \fIsh:\fP and \fIfm:\fP patterns are all implemented on top of the Python SREengine. It is very easy to formulate patterns for each of these types whichrequires an inordinate amount of time to match paths. If untrusted usersare able to supply patterns, ensure they cannot supply \fIre:\fP patterns.Further, ensure that \fIsh:\fP and \fIfm:\fP patterns only contain a handful ofwildcards 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 number 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 backup /# 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 \(aq/home/*/junk\(aq backup /# Exclude the contents of \(aq/home/user/cache\(aq but not the directory itself:$ borg create \-e home/user/cache/ backup /# The file \(aq/home/user/cache/important\(aq is *not* backed up:$ borg create \-e /home/user/cache/ backup / /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 backup /# Load exclusions from file$ cat >exclude.txt <<EOF# Comment line/home/*/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 backup /.ft P.fi.UNINDENT.UNINDENTA more general and easier to use way to define filename matching patterns existswith the experimental \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP options. Using these, youmay specify the backup roots (starting points) and patterns for inclusion/exclusion.A root path starts with the prefix \fIR\fP, followed by a path (a plain path, not afile pattern). An include rule starts with the prefix +, an exclude rule startswith the prefix \-, an exclude\-norecurse rule starts with !, all followed by a pattern..sp\fBNOTE:\fP.INDENT 0.0.INDENT 3.5Via \fB\-\-pattern\fP or \fB\-\-patterns\-from\fP you can define BOTH inclusion and exclusionof files using pattern prefixes \fB+\fP and \fB\-\fP\&. With \fB\-\-exclude\fP and\fB\-\-exclude\-from\fP ONLY excludes are defined..UNINDENT.UNINDENT.spInclusion patterns are useful to include paths that are contained in an excludedpath. The first matching pattern is used so if an include pattern matches beforean exclude pattern, the file is backed up. If an exclude\-norecurse pattern matchesa directory, it won\(aqt recurse into it and won\(aqt discover any potential matches forinclude rules below that directory..spNote that the default pattern style for \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP isshell style (\fIsh:\fP), so those patterns behave similar to rsync include/excludepatterns. The pattern style can be set via the \fIP\fP prefix..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# backup 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 repo::arch pics# use a file with patterns:borg create \-\-patterns\-from patterns.lst repo::arch.ft P.fi.UNINDENT.UNINDENT.spThe patterns.lst file could look like that:.INDENT 0.0.INDENT 3.5.sp.nf.ft C# "sh:" pattern style is the default, so the following line is not needed:P shR /# can be rebuild\- /home/*/.cache# they\(aqre downloads for a reason\- /home/*/Downloads# susan is a nice person# include susans home+ /home/susan# don\(aqt backup the other home directories\- /home/*# don\(aqt even look in /proc! /proc.ft P.fi.UNINDENT.UNINDENT.SH AUTHORThe Borg Collective.\" Generated by docutils manpage writer..
 |