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

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

465 lines
18 KiB
PHP
Raw Normal View History

2016-07-05 21:30:08 +00:00
.. IMPORTANT: this file is auto-generated from borg's built-in help, do not edit!
.. _borg_patterns:
borg help patterns
~~~~~~~~~~~~~~~~~~
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
- for ``--exclude`` option,
- in the file given with ``--exclude-from`` option,
- for ``--pattern`` option,
- in the file given with ``--patterns-from`` option and
- for ``PATH`` arguments that explicitly support them.
Borg always stores all file paths normalized and relative to the
current recursion root. The recursion root is also named ``PATH`` in
Borg commands like `borg create` that do a file discovery, so do not
confuse the root with the ``PATH`` argument of e.g. `borg extract`.
Starting with Borg 1.2, paths that are matched against patterns always
appear relative. If you give ``/absolute/`` as root, the paths going
2023-06-11 21:09:20 +00:00
into the matcher will start with ``absolute/``.
If you give ``../../relative`` as root, the paths will be normalized
as ``relative/``.
2022-06-23 23:19:19 +00:00
2023-06-11 21:09:20 +00:00
Borg supports different pattern styles. To define a non-default
style for a specific pattern, prefix it with two characters followed
by a colon ':' (i.e. ``fm:path/*``, ``sh:path/**``).
2022-06-23 23:19:19 +00:00
`Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector ``fm:``
2017-06-18 10:12:50 +00:00
This is the default style for ``--exclude`` and ``--exclude-from``.
2017-06-09 17:22:18 +00:00
These patterns use a variant of shell pattern syntax, with '\*' matching
2017-03-26 23:45:45 +00:00
any number of characters, '?' matching any single character, '[...]'
matching any single character specified, including ranges, and '[!...]'
matching any character not specified. For the purpose of these patterns,
2019-02-24 19:39:42 +00:00
the path separator (backslash for Windows and '/' on other systems) is not
treated specially. Wrap meta-characters in brackets for a literal
2022-06-23 23:19:19 +00:00
match (i.e. ``[?]`` to match the literal character '?'). For a path
2019-02-24 19:39:42 +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
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:56:55 +00:00
separator, a '\*' is appended before matching is attempted. A leading
path separator is always removed.
2016-01-23 19:54:20 +00:00
2022-06-23 23:19:19 +00:00
Shell-style patterns, selector ``sh:``
2017-06-20 13:22:24 +00:00
This is the default style for ``--pattern`` and ``--patterns-from``.
2016-01-23 19:54:20 +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 ``**/`` for matching zero or more directory
levels, ``*`` for matching zero or more arbitrary characters with the
2023-06-11 21:09:20 +00:00
exception of any path separator, ``{}`` containing comma-separated
alternative patterns. A leading path separator is always removed.
2016-01-23 19:54:20 +00:00
2022-06-23 23:19:19 +00:00
`Regular expressions <https://docs.python.org/3/library/re.html>`_, selector ``re:``
Unlike shell patterns, regular expressions are not required to match the full
2016-01-23 19:54:20 +00:00
path and any substring match is sufficient. It is strongly recommended to
anchor patterns to the start ('^'), to the end ('$') or both. Path
2019-02-24 19:39:42 +00:00
separators (backslash for Windows and '/' on other systems) in paths are
2022-06-23 23:19:19 +00:00
always normalized to a forward slash '/' before applying a pattern.
2016-01-23 19:54:20 +00:00
2022-06-23 23:19:19 +00:00
Path prefix, selector ``pp:``
2022-01-23 14:52:21 +00:00
This pattern style is useful to match whole sub-directories. The pattern
2022-06-23 23:19:19 +00:00
``pp:root/somedir`` matches ``root/somedir`` and everything therein.
A leading path separator is always removed.
2016-01-23 19:54:20 +00:00
2022-06-23 23:19:19 +00:00
Path full-match, selector ``pf:``
2022-01-23 14:52:21 +00:00
This pattern style is (only) useful to match full paths.
2017-03-26 23:45:45 +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. ``pf:root/file.ext``
matches ``root/file.ext`` only. A leading path separator is always
removed.
2017-03-26 23:45:45 +00:00
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.
.. note::
2022-06-23 23:19:19 +00:00
``re:``, ``sh:`` and ``fm:`` 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 ``re:`` patterns. Further, ensure that ``sh:`` and
``fm:`` patterns only contain a handful of wildcards at most.
2017-06-18 10:12:50 +00:00
Exclusions can be passed via the command line option ``--exclude``. When used
2021-05-11 20:33:55 +00:00
from within a shell, the patterns should be quoted to protect them from
2016-01-23 19:54:20 +00:00
expansion.
2017-06-18 10:12:50 +00:00
The ``--exclude-from`` 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
'#' after removing whitespace on both ends are ignored. The optional style
2016-01-23 19:54:20 +00:00
selector prefix is also supported for patterns loaded from a file. Due to
2021-05-11 20:33:55 +00:00
whitespace removal, paths with whitespace at the beginning or end can only be
2016-01-23 19:54:20 +00:00
excluded using regular expressions.
2020-04-12 17:51:49 +00:00
To test your exclusion patterns without performing an actual backup you can
run ``borg create --list --dry-run ...``.
Examples::
2016-01-23 19:54:20 +00:00
# Exclude '/home/user/file.o' but not '/home/user/file.odt':
2022-06-23 23:19:19 +00:00
$ borg create -e '*.o' archive /
2016-01-23 19:54:20 +00:00
# Exclude '/home/user/junk' and '/home/user/subdir/junk' but
# not '/home/user/importantjunk' or '/etc/junk':
2022-06-23 23:19:19 +00:00
$ borg create -e 'home/*/junk' archive /
2016-01-23 19:54:20 +00:00
# Exclude the contents of '/home/user/cache' but not the directory itself:
2022-06-23 23:19:19 +00:00
$ borg create -e home/user/cache/ archive /
2016-01-23 19:54:20 +00:00
# The file '/home/user/cache/important' is *not* backed up:
2022-06-23 23:19:19 +00:00
$ borg create -e home/user/cache/ archive / /home/user/cache/important
2016-01-23 19:54:20 +00:00
# The contents of directories in '/home' are not backed up when their name
# ends in '.tmp'
2022-06-23 23:19:19 +00:00
$ borg create --exclude 're:^home/[^/]+\.tmp/' archive /
2016-01-23 19:54:20 +00:00
# Load exclusions from file
$ cat >exclude.txt <<EOF
# Comment line
2022-06-23 23:19:19 +00:00
home/*/junk
*.tmp
fm:aa:something/*
2022-06-23 23:19:19 +00:00
re:^home/[^/]+\.tmp/
sh:home/*/.thumbnails
2020-12-06 19:44:59 +00:00
# Example with spaces, no need to escape as it is processed by borg
some file with spaces.txt
EOF
2022-06-23 23:19:19 +00:00
$ borg create --exclude-from exclude.txt archive /
2022-06-23 23:19:19 +00:00
A more general and easier to use way to define filename matching patterns
exists with the ``--pattern`` and ``--patterns-from`` options. Using
these, you may specify the backup roots, default pattern styles and
patterns for inclusion and exclusion.
2022-02-19 17:47:47 +00:00
2022-06-23 23:19:19 +00:00
Root path prefix ``R``
A recursion root path starts with the prefix ``R``, 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.
2022-02-19 17:47:47 +00:00
2022-06-23 23:19:19 +00:00
Pattern style prefix ``P``
To change the default pattern style, use the ``P`` prefix, followed by
the pattern style abbreviation (``fm``, ``pf``, ``pp``, ``re``, ``sh``).
All patterns following this line will use this style until another style
is specified.
2022-02-19 17:47:47 +00:00
2022-06-23 23:19:19 +00:00
Exclude pattern prefix ``-``
Use the prefix ``-``, followed by a pattern, to define an exclusion.
This has the same effect as the ``--exclude`` option.
2022-02-19 17:47:47 +00:00
2022-06-23 23:19:19 +00:00
Exclude no-recurse pattern prefix ``!``
Use the prefix ``!``, 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.
Include pattern prefix ``+``
Use the prefix ``+``, 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.
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-06-23 23:19:19 +00:00
2023-06-11 21:09:20 +00:00
Example::
# 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's 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.
- **
2022-06-23 23:19:19 +00:00
**Tip: You can easily test your patterns with --dry-run and --list**::
2022-02-19 17:47:47 +00:00
2022-06-23 23:19:19 +00:00
$ borg create --dry-run --list --patterns-from patterns.txt archive
2022-02-19 17:47:47 +00:00
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. 'x' for excluding, see
**Item flags** in `borg create` usage docs).
.. note::
It's 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:47:47 +00:00
Patterns (``--pattern``) and excludes (``--exclude``) from the command line are
considered first (in the order of appearance). Then patterns from ``--patterns-from``
are added. Exclusion patterns from ``--exclude-from`` files are appended last.
Examples::
# back up pics, but not the ones from 2018, except the good ones:
2022-02-19 17:47:47 +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
2022-02-19 17:47:47 +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 '+ re:\.jpe?g(?i)$' archive /home
# back up homes, but exclude big downloads (like .ISO files) or hidden files:
2022-06-23 23:19:19 +00:00
borg create --exclude 're:\.iso(?i)$' --exclude 'sh:home/**/.*' archive /home
# use a file with patterns (recursion root '/' via command line):
borg create --patterns-from patterns.lst archive /
2022-02-19 17:47:47 +00:00
The patterns.lst file could look like that::
2022-06-23 23:19:19 +00:00
# "sh:" pattern style is the default
# exclude caches
- home/*/.cache
2022-02-19 17:47:47 +00:00
# include susans home
2022-06-23 23:19:19 +00:00
+ home/susan
2022-02-19 17:47:47 +00:00
# also back up this exact file
2022-06-23 23:19:19 +00:00
+ pf:home/bobby/specialfile.txt
# don't back up the other home directories
2022-06-23 23:19:19 +00:00
- home/*
# don't 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:47:47 +00:00
You can specify recursion roots either on the command line or in a patternfile::
# 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:47:47 +00:00
2022-06-23 23:19:19 +00:00
patternfile.lst::
2022-02-19 17:47:47 +00:00
# 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
2022-02-19 17:47:47 +00:00
This allows you to share the same patterns between multiple repositories
without needing to specify them on the command line.
2017-03-26 23:45:45 +00:00
2022-10-02 13:51:17 +00:00
.. _borg_match-archives:
borg help match-archives
~~~~~~~~~~~~~~~~~~~~~~~~
The ``--match-archives`` option matches a given pattern against the list of all archive
names in the repository.
It uses pattern styles similar to the ones described by ``borg help patterns``:
Identical match pattern, selector ``id:`` (default)
Simple string match, must fully match exactly as given.
Shell-style patterns, selector ``sh:``
Match like on the shell, wildcards like `*` and `?` work.
`Regular expressions <https://docs.python.org/3/library/re.html>`_, selector ``re:``
Full regular expression support.
This is very powerful, but can also get rather complicated.
Examples::
# id: style
borg delete --match-archives 'id:archive-with-crap'
borg delete -a 'id:archive-with-crap' # same, using short option
borg delete -a 'archive-with-crap' # same, because 'id:' is the default
# sh: style
borg delete -a 'sh:home-kenny-*'
# re: style
borg delete -a 're:pc[123]-home-(user1|user2)-2022-09-.*'
2016-08-27 22:17:24 +00:00
.. _borg_placeholders:
borg help placeholders
~~~~~~~~~~~~~~~~~~~~~~
2022-10-02 13:51:17 +00:00
Repository URLs, ``--name``, ``-a`` / ``--match-archives``, ``--comment``
2019-09-06 22:27:17 +00:00
and ``--remote-path`` values support these placeholders:
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{hostname}
The (short) hostname of the machine.
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{fqdn}
The full name of the machine.
2016-08-27 22:17:24 +00:00
{reverse-fqdn}
The full name of the machine in reverse domain name notation.
2016-10-01 16:23:36 +00:00
{now}
The current local date and time, by default in ISO-8601 format.
2022-04-14 19:09:23 +00:00
You can also supply your own `format string <https://docs.python.org/3.9/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{utcnow}
The current UTC date and time, by default in ISO-8601 format.
2022-04-14 19:09:23 +00:00
You can also supply your own `format string <https://docs.python.org/3.9/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{user}
The user name (or UID, if no name is available) of the user running borg.
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{pid}
The current process ID.
2016-08-27 22:17:24 +00:00
2016-10-01 16:23:36 +00:00
{borgversion}
The version of borg, e.g.: 1.0.8rc1
2016-10-28 23:58:21 +00:00
{borgmajor}
The version of borg, only the major version, e.g.: 1
2016-10-28 23:58:21 +00:00
{borgminor}
The version of borg, only major and minor version, e.g.: 1.0
2016-10-28 23:58:21 +00:00
{borgpatch}
The version of borg, only major, minor and patch version, e.g.: 1.0.8
2016-08-27 22:17:24 +00:00
2017-04-29 23:31:20 +00:00
If literal curly braces need to be used, double them for escaping::
borg create /path/to/repo::{{literal_text}}
2016-08-27 22:17:24 +00:00
Examples::
2024-09-26 05:57:01 +00:00
borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S%z} ...
borg prune -a 'sh:{hostname}-*' ...
2016-10-01 16:23:36 +00:00
.. note::
systemd uses a difficult, non-standard syntax for command lines in unit files (refer to
the `systemd.unit(5)` manual page).
When invoking borg from unit files, pay particular attention to escaping,
especially when using the now/utcnow placeholders, since systemd performs its own
%-based variable replacement even in quoted text. To avoid interference from systemd,
double all percent signs (``{hostname}-{now:%Y-%m-%d_%H:%M:%S}``
becomes ``{hostname}-{now:%%Y-%%m-%%d_%%H:%%M:%%S}``).
2016-10-01 16:23:36 +00:00
.. _borg_compression:
borg help compression
~~~~~~~~~~~~~~~~~~~~~
2017-06-18 10:12:50 +00:00
It is no problem to mix different compression methods in one repo,
deduplication is done on the source data chunks (not on the compressed
or encrypted data).
If some specific chunk was once compressed and stored into the repo, creating
another backup that also uses this chunk will not change the stored chunk.
So if you use different compression specs for the backups, whichever stores a
chunk first determines its compression. See also borg recreate.
2017-03-26 23:45:45 +00:00
Compression is lz4 by default. If you want something else, you have to specify what you want.
2016-10-01 16:23:36 +00:00
Valid compression specifiers are:
none
2017-03-26 23:45:45 +00:00
Do not compress.
2016-10-01 16:23:36 +00:00
lz4
2019-02-24 19:39:42 +00:00
Use lz4 compression. Very high speed, very low compression. (default)
zstd[,L]
Use zstd ("zstandard") compression, a modern wide-range algorithm.
If you do not explicitly give the compression level L (ranging from 1
to 22), it will use level 3.
2016-10-01 16:23:36 +00:00
zlib[,L]
Use zlib ("gz") compression. Medium speed, medium compression.
If you do not explicitly give the compression level L (ranging from 0
2016-10-01 16:23:36 +00:00
to 9), it will use level 6.
Giving level 0 (means "no compression", but still has zlib protocol
overhead) is usually pointless, you better use "none" compression.
lzma[,L]
Use lzma ("xz") compression. Low speed, high compression.
If you do not explicitly give the compression level L (ranging from 0
2016-10-01 16:23:36 +00:00
to 9), it will use level 6.
Giving levels above 6 is pointless and counterproductive because it does
not compress better due to the buffer size used by borg - but it wastes
lots of CPU cycles and RAM.
auto,C[,L]
Use a built-in heuristic to decide per chunk whether to compress or not.
The heuristic tries with lz4 whether the data is compressible.
For incompressible data, it will not use compression (uses "none").
For compressible data, it uses the given C[,L] compression - with C[,L]
being any valid compression specifier.
2020-12-06 19:44:59 +00:00
obfuscate,SPEC,C[,L]
Use compressed-size obfuscation to make fingerprinting attacks based on
2023-06-11 21:09:20 +00:00
the observable stored chunk size more difficult. Note:
2020-12-06 19:44:59 +00:00
2023-06-11 21:09:20 +00:00
- You must combine this with encryption, or it won't make any sense.
- Your repo size will be bigger, of course.
- A chunk is limited by the constant ``MAX_DATA_SIZE`` (cur. ~20MiB).
The SPEC value determines how the size obfuscation works:
*Relative random reciprocal size variation* (multiplicative)
2020-12-06 19:44:59 +00:00
Size will increase by a factor, relative to the compressed data size.
2023-06-11 21:09:20 +00:00
Smaller factors are used often, larger factors rarely.
Available factors::
1: 0.01 .. 100
2: 0.1 .. 1,000
3: 1 .. 10,000
4: 10 .. 100,000
5: 100 .. 1,000,000
6: 1,000 .. 10,000,000
Example probabilities for SPEC ``1``::
90 % 0.01 .. 0.1
9 % 0.1 .. 1
0.9 % 1 .. 10
0.09% 10 .. 100
*Randomly sized padding up to the given size* (additive)
::
110: 1kiB (2 ^ (SPEC - 100))
...
120: 1MiB
...
123: 8MiB (max.)
2020-12-06 19:44:59 +00:00
2016-10-01 16:23:36 +00:00
Examples::
borg create --compression lz4 REPO::ARCHIVE data
2019-02-24 19:39:42 +00:00
borg create --compression zstd REPO::ARCHIVE data
borg create --compression zstd,10 REPO::ARCHIVE data
2016-10-01 16:23:36 +00:00
borg create --compression zlib REPO::ARCHIVE data
borg create --compression zlib,1 REPO::ARCHIVE data
borg create --compression auto,lzma,6 REPO::ARCHIVE data
2017-04-29 23:31:20 +00:00
borg create --compression auto,lzma ...
2023-06-11 21:09:20 +00:00
borg create --compression obfuscate,110,none ...
2020-12-06 19:44:59 +00:00
borg create --compression obfuscate,3,auto,zstd,10 ...
borg create --compression obfuscate,2,zstd,6 ...
2016-10-01 16:23:36 +00:00