1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-29 11:16:43 +00:00
borg/docs/man/borg-patterns.1

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

362 lines
12 KiB
Groff
Raw Normal View History

2017-02-05 13:22:06 +00:00
.\" 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
..
2024-07-19 18:40:15 +00:00
.TH "BORG-PATTERNS" 1 "2024-07-19" "" "borg backup tool"
2022-06-23 23:19:19 +00:00
.SH NAME
borg-patterns \- Details regarding patterns
2017-02-05 13:22:06 +00:00
.SH DESCRIPTION
.sp
2022-06-23 23:19:19 +00:00
When specifying one or more file paths in a Borg command that supports
patterns for the respective option or argument, you can apply the
patterns described here to include only desired files and/or exclude
unwanted ones. Patterns can be used
.INDENT 0.0
.IP \(bu 2
for \fB\-\-exclude\fP option,
.IP \(bu 2
in the file given with \fB\-\-exclude\-from\fP option,
.IP \(bu 2
for \fB\-\-pattern\fP option,
.IP \(bu 2
in the file given with \fB\-\-patterns\-from\fP option and
.IP \(bu 2
for \fBPATH\fP arguments that explicitly support them.
.UNINDENT
2022-02-19 17:48:13 +00:00
.sp
2022-06-23 23:19:19 +00:00
Borg always stores all file paths normalized and relative to the
current recursion root. The recursion root is also named \fBPATH\fP in
Borg commands like \fIborg create\fP that do a file discovery, so do not
confuse the root with the \fBPATH\fP argument of e.g. \fIborg extract\fP\&.
2020-04-21 20:59:27 +00:00
.sp
2022-06-23 23:19:19 +00:00
Starting with Borg 1.2, paths that are matched against patterns always
appear relative. If you give \fB/absolute/\fP as root, the paths going
2023-06-11 21:10:23 +00:00
into the matcher will start with \fBabsolute/\fP\&.
If you give \fB\&../../relative\fP as root, the paths will be normalized
as \fBrelative/\fP\&.
.sp
Borg supports different pattern styles. To define a non\-default
style for a specific pattern, prefix it with two characters followed
by a colon \(aq:\(aq (i.e. \fBfm:path/*\fP, \fBsh:path/**\fP).
2017-02-05 13:22:06 +00:00
.INDENT 0.0
2017-06-18 10:13:28 +00:00
.TP
2022-06-23 23:19:19 +00:00
.B \fI\%Fnmatch\fP, selector \fBfm:\fP
2017-06-18 10:13:28 +00:00
This is the default style for \fB\-\-exclude\fP and \fB\-\-exclude\-from\fP\&.
2017-03-26 23:58:19 +00:00
These patterns use a variant of shell pattern syntax, with \(aq*\(aq matching
any number of characters, \(aq?\(aq matching any single character, \(aq[...]\(aq
matching any single character specified, including ranges, and \(aq[!...]\(aq
matching any character not specified. For the purpose of these patterns,
2019-02-24 19:40:07 +00:00
the path separator (backslash for Windows and \(aq/\(aq on other systems) is not
2017-02-05 13:22:06 +00:00
treated specially. Wrap meta\-characters in brackets for a literal
2022-06-23 23:19:19 +00:00
match (i.e. \fB[?]\fP to match the literal character \(aq?\(aq). For a path
2019-02-24 19:40:07 +00:00
to match a pattern, the full path must match, or it must match
from the start of the full path to just before a path separator. Except
2017-02-05 13:22:06 +00:00
for the root path, paths will never end in the path separator when
matching is attempted. Thus, if a given pattern ends in a path
2020-04-21 20:59:27 +00:00
separator, a \(aq*\(aq is appended before matching is attempted. A leading
path separator is always removed.
2017-06-18 10:13:28 +00:00
.TP
2022-06-23 23:19:19 +00:00
.B Shell\-style patterns, selector \fBsh:\fP
This is the default style for \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP\&.
2017-02-05 13:22:06 +00:00
Like fnmatch patterns these are similar to shell patterns. The difference
2022-06-23 23:19:19 +00:00
is that the pattern may include \fB**/\fP for matching zero or more directory
levels, \fB*\fP for matching zero or more arbitrary characters with the
2023-06-11 21:10:23 +00:00
exception of any path separator, \fB{}\fP containing comma\-separated
alternative patterns. A leading path separator is always removed.
2017-06-18 10:13:28 +00:00
.TP
2022-06-23 23:19:19 +00:00
.B \fI\%Regular expressions\fP, selector \fBre:\fP
Unlike shell patterns, regular expressions are not required to match the full
2017-02-05 13:22:06 +00:00
path and any substring match is sufficient. It is strongly recommended to
anchor patterns to the start (\(aq^\(aq), to the end (\(aq$\(aq) or both. Path
2019-02-24 19:40:07 +00:00
separators (backslash for Windows and \(aq/\(aq on other systems) in paths are
2022-06-23 23:19:19 +00:00
always normalized to a forward slash \(aq/\(aq before applying a pattern.
2017-06-18 10:13:28 +00:00
.TP
2022-06-23 23:19:19 +00:00
.B Path prefix, selector \fBpp:\fP
2017-02-05 13:22:06 +00:00
This pattern style is useful to match whole sub\-directories. The pattern
2022-06-23 23:19:19 +00:00
\fBpp:root/somedir\fP matches \fBroot/somedir\fP and everything therein.
A leading path separator is always removed.
2017-06-18 10:13:28 +00:00
.TP
2022-06-23 23:19:19 +00:00
.B Path full\-match, selector \fBpf:\fP
2019-02-24 19:40:07 +00:00
This pattern style is (only) useful to match full paths.
2017-03-26 23:58:19 +00:00
This is kind of a pseudo pattern as it can not have any variable or
2022-06-23 23:19:19 +00:00
unspecified parts \- the full path must be given. \fBpf:root/file.ext\fP
matches \fBroot/file.ext\fP only. A leading path separator is always
removed.
2017-03-26 23:58:19 +00:00
.sp
Implementation note: this is implemented via very time\-efficient O(1)
hashtable lookups (this means you can have huge amounts of such patterns
without 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
2017-06-18 10:13:28 +00:00
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
2022-06-23 23:19:19 +00:00
\fBre:\fP, \fBsh:\fP and \fBfm:\fP patterns are all implemented on top of
the Python SRE engine. It is very easy to formulate patterns for each
of these types which requires an inordinate amount of time to match
paths. If untrusted users are able to supply patterns, ensure they
cannot supply \fBre:\fP patterns. Further, ensure that \fBsh:\fP and
\fBfm:\fP patterns only contain a handful of wildcards at most.
2017-06-18 10:13:28 +00:00
.UNINDENT
2017-03-26 23:58:19 +00:00
.UNINDENT
.sp
2017-06-18 10:13:28 +00:00
Exclusions can be passed via the command line option \fB\-\-exclude\fP\&. When used
2021-05-11 20:33:28 +00:00
from within a shell, the patterns should be quoted to protect them from
2017-02-05 13:22:06 +00:00
expansion.
.sp
2017-06-18 10:13:28 +00:00
The \fB\-\-exclude\-from\fP option permits loading exclusion patterns from a text
2022-06-23 23:19:19 +00:00
file 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 style
2017-02-05 13:22:06 +00:00
selector prefix is also supported for patterns loaded from a file. Due to
2021-05-11 20:33:28 +00:00
whitespace removal, paths with whitespace at the beginning or end can only be
2017-02-05 13:22:06 +00:00
excluded using regular expressions.
.sp
2020-04-12 17:55:57 +00:00
To test your exclusion patterns without performing an actual backup you can
run \fBborg create \-\-list \-\-dry\-run ...\fP\&.
.sp
2017-02-05 13:22:06 +00:00
Examples:
.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:
2022-06-23 23:19:19 +00:00
$ borg create \-e \(aq*.o\(aq archive /
2017-02-05 13:22:06 +00:00
# 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:
2022-06-23 23:19:19 +00:00
$ borg create \-e \(aqhome/*/junk\(aq archive /
2017-02-05 13:22:06 +00:00
# Exclude the contents of \(aq/home/user/cache\(aq but not the directory itself:
2022-06-23 23:19:19 +00:00
$ borg create \-e home/user/cache/ archive /
2017-02-05 13:22:06 +00:00
# The file \(aq/home/user/cache/important\(aq is *not* backed up:
2022-06-23 23:19:19 +00:00
$ borg create \-e home/user/cache/ archive / /home/user/cache/important
2017-02-05 13:22:06 +00:00
# The contents of directories in \(aq/home\(aq are not backed up when their name
# ends in \(aq.tmp\(aq
2022-06-23 23:19:19 +00:00
$ borg create \-\-exclude \(aqre:^home/[^/]+\e.tmp/\(aq archive /
2017-02-05 13:22:06 +00:00
# Load exclusions from file
$ cat >exclude.txt <<EOF
# Comment line
2022-06-23 23:19:19 +00:00
home/*/junk
2017-02-05 13:22:06 +00:00
*.tmp
fm:aa:something/*
2022-06-23 23:19:19 +00:00
re:^home/[^/]+\e.tmp/
sh:home/*/.thumbnails
2020-12-06 19:45:41 +00:00
# Example with spaces, no need to escape as it is processed by borg
some file with spaces.txt
2017-02-05 13:22:06 +00:00
EOF
2022-06-23 23:19:19 +00:00
$ borg create \-\-exclude\-from exclude.txt archive /
2022-02-19 17:48:13 +00:00
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
2022-06-23 23:19:19 +00:00
A more general and easier to use way to define filename matching patterns
exists with the \fB\-\-pattern\fP and \fB\-\-patterns\-from\fP options. Using
these, you may specify the backup roots, default pattern styles and
patterns for inclusion and exclusion.
.INDENT 0.0
.TP
.B Root path prefix \fBR\fP
A 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 root
paths in the patterns file rather than as command line arguments.
.TP
.B Pattern style prefix \fBP\fP
To change the default pattern style, use the \fBP\fP prefix, followed by
the pattern style abbreviation (\fBfm\fP, \fBpf\fP, \fBpp\fP, \fBre\fP, \fBsh\fP).
All patterns following this line will use this style until another style
is specified.
.TP
.B Exclude pattern prefix \fB\-\fP
Use 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!\fP
Use the prefix \fB!\fP, followed by a pattern, to define an exclusion
that does not recurse into subdirectories. This saves time, but
prevents include patterns to match any files in subdirectories.
.TP
.B Include pattern prefix \fB+\fP
Use the prefix \fB+\fP, followed by a pattern, to define inclusions.
This is useful to include paths that are covered in an exclude
pattern and would otherwise not be backed up.
.UNINDENT
.sp
The first matching pattern is used, so if an include pattern matches
before an exclude pattern, the file is backed up. Note that a no\-recurse
exclude stops examination of subdirectories so that potential includes
2022-08-03 20:19:12 +00:00
will not match \- use normal excludes for such use cases.
2022-02-19 17:48:13 +00:00
.sp
2023-06-11 21:10:23 +00:00
Example:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
# Define the recursion root
R /
# 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
2022-06-23 23:19:19 +00:00
\fBTip: You can easily test your patterns with \-\-dry\-run and \-\-list\fP:
2022-02-19 17:48:13 +00:00
.INDENT 0.0
.INDENT 3.5
2022-06-23 23:19:19 +00:00
.sp
.nf
.ft C
$ borg create \-\-dry\-run \-\-list \-\-patterns\-from patterns.txt archive
.ft P
.fi
2022-02-19 17:48:13 +00:00
.UNINDENT
.UNINDENT
.sp
2022-06-23 23:19:19 +00:00
This will list the considered files one per line, prefixed with a
character that indicates the action (e.g. \(aqx\(aq for excluding, see
\fBItem flags\fP in \fIborg create\fP usage docs).
2022-02-19 17:48:13 +00:00
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
2022-06-23 23:19:19 +00:00
It\(aqs possible that a sub\-directory/file is matched while parent
directories are not. In that case, parent directories are not backed
up and thus their user, group, permission, etc. cannot be restored.
2022-02-19 17:48:13 +00:00
.UNINDENT
.UNINDENT
.sp
Patterns (\fB\-\-pattern\fP) and excludes (\fB\-\-exclude\fP) from the command line are
considered first (in the order of appearance). Then patterns from \fB\-\-patterns\-from\fP
are added. Exclusion patterns from \fB\-\-exclude\-from\fP files are appended last.
.sp
Examples:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
2023-01-02 22:51:22 +00:00
# back up pics, but not the ones from 2018, except the good ones:
2022-02-19 17:48:13 +00:00
# note: using = is essential to avoid cmdline argument parsing issues.
2022-06-23 23:19:19 +00:00
borg create \-\-pattern=+pics/2018/good \-\-pattern=\-pics/2018 archive pics
2019-02-24 19:40:07 +00:00
2023-01-02 22:51:22 +00:00
# back up only JPG/JPEG files (case insensitive) in all home directories:
2022-06-23 23:19:19 +00:00
borg create \-\-pattern \(aq+ re:\e.jpe?g(?i)$\(aq archive /home
2023-01-02 22:51:22 +00:00
# back up homes, but exclude big downloads (like .ISO files) or hidden files:
2022-06-23 23:19:19 +00:00
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 /
2022-02-19 17:48:13 +00:00
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The patterns.lst file could look like that:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
2022-09-10 14:03:27 +00:00
# \(dqsh:\(dq pattern style is the default
2022-06-23 23:19:19 +00:00
# exclude caches
\- home/*/.cache
2022-02-19 17:48:13 +00:00
# include susans home
2022-06-23 23:19:19 +00:00
+ home/susan
2022-02-19 17:48:13 +00:00
# also back up this exact file
2022-06-23 23:19:19 +00:00
+ pf:home/bobby/specialfile.txt
2023-01-02 22:51:22 +00:00
# don\(aqt back up the other home directories
2022-06-23 23:19:19 +00:00
\- home/*
# don\(aqt even look in /dev, /proc, /run, /sys, /tmp (note: would exclude files like /device, too)
! re:^(dev|proc|run|sys|tmp)
2022-02-19 17:48:13 +00:00
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
You 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 thing
2022-06-23 23:19:19 +00:00
borg create \-\-exclude home/bobby/junk archive /home/bobby /home/susan
borg create \-\-patterns\-from patternfile.lst archive
2022-02-19 17:48:13 +00:00
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
2022-06-23 23:19:19 +00:00
patternfile.lst:
2022-02-19 17:48:13 +00:00
.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 fm
R /home/bobby
R /home/susan
2022-06-23 23:19:19 +00:00
\- home/bobby/junk
2017-03-26 23:58:19 +00:00
.ft P
.fi
.UNINDENT
.UNINDENT
2022-02-19 17:48:13 +00:00
.sp
This allows you to share the same patterns between multiple repositories
without needing to specify them on the command line.
2017-02-05 13:22:06 +00:00
.SH AUTHOR
The Borg Collective
.\" Generated by docutils manpage writer.
.