|
@@ -64,7 +64,7 @@ from .helpers import basic_json_data, json_print
|
|
|
from .helpers import replace_placeholders
|
|
|
from .helpers import ChunkIteratorFileWrapper
|
|
|
from .helpers import popen_with_error_handling
|
|
|
-from .nanorst import RstToTextLazy, ansi_escapes
|
|
|
+from .nanorst import rst_to_terminal
|
|
|
from .patterns import ArgparsePatternAction, ArgparseExcludeFileAction, ArgparsePatternFileAction, parse_exclude_pattern
|
|
|
from .patterns import PatternMatcher
|
|
|
from .item import Item
|
|
@@ -1837,8 +1837,10 @@ class Archiver:
|
|
|
helptext['patterns'] = textwrap.dedent('''
|
|
|
File patterns support these styles: fnmatch, shell, regular expressions,
|
|
|
path prefixes and path full-matches. By default, fnmatch is used for
|
|
|
- `--exclude` patterns and shell-style is used for `--pattern`. If followed
|
|
|
- by a colon (':') the first two characters of a pattern are used as a
|
|
|
+ `--exclude` patterns and shell-style is used for the experimental `--pattern`
|
|
|
+ option.
|
|
|
+
|
|
|
+ If followed by a colon (':') the first two characters of a pattern are used as a
|
|
|
style selector. Explicit style selection is necessary when a
|
|
|
non-default style is desired or when the desired pattern starts with
|
|
|
two alphanumeric characters followed by a colon (i.e. `aa:something/*`).
|
|
@@ -1846,7 +1848,7 @@ class Archiver:
|
|
|
`Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
|
|
|
|
|
|
This is the default style for --exclude and --exclude-from.
|
|
|
- These patterns use a variant of shell pattern syntax, with '*' matching
|
|
|
+ These patterns use a variant of shell pattern syntax, with '\*' matching
|
|
|
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,
|
|
@@ -1857,7 +1859,7 @@ class Archiver:
|
|
|
must match from the start 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
|
|
|
- separator, a '*' is appended before matching is attempted.
|
|
|
+ separator, a '\*' is appended before matching is attempted.
|
|
|
|
|
|
Shell-style patterns, selector `sh:`
|
|
|
|
|
@@ -1940,39 +1942,40 @@ class Archiver:
|
|
|
EOF
|
|
|
$ borg create --exclude-from exclude.txt backup /
|
|
|
|
|
|
-
|
|
|
- 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 (starting points) and patterns for inclusion/exclusion. A
|
|
|
- root path starts with the prefix `R`, followed by a path (a plain path, not a
|
|
|
- file pattern). An include rule starts with the prefix +, an exclude rule starts
|
|
|
- with the prefix -, both followed by a pattern.
|
|
|
- Inclusion patterns are useful to include paths that are contained in an excluded
|
|
|
- path. The first matching pattern is used so if an include pattern matches before
|
|
|
- an exclude pattern, the file is backed up.
|
|
|
-
|
|
|
- Note that the default pattern style for `--pattern` and `--patterns-from` is
|
|
|
- shell style (`sh:`), so those patterns behave similar to rsync include/exclude
|
|
|
- patterns. The pattern style can be set via the `P` prefix.
|
|
|
-
|
|
|
- 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.
|
|
|
-
|
|
|
- An example `--patterns-from` file could look like that::
|
|
|
-
|
|
|
- # "sh:" pattern style is the default, so the following line is not needed:
|
|
|
- P sh
|
|
|
- R /
|
|
|
- # can be rebuild
|
|
|
- - /home/*/.cache
|
|
|
- # they're downloads for a reason
|
|
|
- - /home/*/Downloads
|
|
|
- # susan is a nice person
|
|
|
- # include susans home
|
|
|
- + /home/susan
|
|
|
- # don't backup the other home directories
|
|
|
- - /home/*\n\n''')
|
|
|
+ .. container:: experimental
|
|
|
+
|
|
|
+ A more general and easier to use way to define filename matching patterns exists
|
|
|
+ with the experimental `--pattern` and `--patterns-from` options. Using these, you
|
|
|
+ may specify the backup roots (starting points) and patterns for inclusion/exclusion.
|
|
|
+ A root path starts with the prefix `R`, followed by a path (a plain path, not a
|
|
|
+ file pattern). An include rule starts with the prefix +, an exclude rule starts
|
|
|
+ with the prefix -, both followed by a pattern.
|
|
|
+ Inclusion patterns are useful to include paths that are contained in an excluded
|
|
|
+ path. The first matching pattern is used so if an include pattern matches before
|
|
|
+ an exclude pattern, the file is backed up.
|
|
|
+
|
|
|
+ Note that the default pattern style for `--pattern` and `--patterns-from` is
|
|
|
+ shell style (`sh:`), so those patterns behave similar to rsync include/exclude
|
|
|
+ patterns. The pattern style can be set via the `P` prefix.
|
|
|
+
|
|
|
+ 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.
|
|
|
+
|
|
|
+ An example `--patterns-from` file could look like that::
|
|
|
+
|
|
|
+ # "sh:" pattern style is the default, so the following line is not needed:
|
|
|
+ P sh
|
|
|
+ R /
|
|
|
+ # can be rebuild
|
|
|
+ - /home/*/.cache
|
|
|
+ # they're downloads for a reason
|
|
|
+ - /home/*/Downloads
|
|
|
+ # susan is a nice person
|
|
|
+ # include susans home
|
|
|
+ + /home/susan
|
|
|
+ # don't backup the other home directories
|
|
|
+ - /home/*\n\n''')
|
|
|
helptext['placeholders'] = textwrap.dedent('''
|
|
|
Repository (or Archive) URLs, --prefix and --remote-path values support these
|
|
|
placeholders:
|
|
@@ -2099,7 +2102,7 @@ class Archiver:
|
|
|
if not args.topic:
|
|
|
parser.print_help()
|
|
|
elif args.topic in self.helptext:
|
|
|
- print(self.helptext[args.topic])
|
|
|
+ print(rst_to_terminal(self.helptext[args.topic]))
|
|
|
elif args.topic in commands:
|
|
|
if args.epilog_only:
|
|
|
print(commands[args.topic].epilog)
|
|
@@ -2257,11 +2260,6 @@ class Archiver:
|
|
|
setattr(args, dest, option_value)
|
|
|
|
|
|
def build_parser(self):
|
|
|
- if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() and (sys.platform != 'win32' or 'ANSICON' in os.environ):
|
|
|
- rst_state_hook = ansi_escapes
|
|
|
- else:
|
|
|
- rst_state_hook = None
|
|
|
-
|
|
|
# You can use :ref:`xyz` in the following usage pages. However, for plain-text view,
|
|
|
# e.g. through "borg ... --help", define a substitution for the reference here.
|
|
|
# It will replace the entire :ref:`foo` verbatim.
|
|
@@ -2279,7 +2277,7 @@ class Archiver:
|
|
|
epilog = [line for line in epilog if not line.startswith('.. man')]
|
|
|
epilog = '\n'.join(epilog)
|
|
|
if mode == 'command-line':
|
|
|
- epilog = RstToTextLazy(epilog, rst_state_hook, rst_plain_text_references)
|
|
|
+ epilog = rst_to_terminal(epilog, rst_plain_text_references)
|
|
|
return epilog
|
|
|
|
|
|
def define_common_options(add_common_option):
|
|
@@ -2793,9 +2791,9 @@ class Archiver:
|
|
|
'objects themselves from the backup archive')
|
|
|
exclude_group.add_argument('--pattern',
|
|
|
action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
exclude_group.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
|
|
|
fs_group = subparser.add_argument_group('Filesystem options')
|
|
|
fs_group.add_argument('-x', '--one-file-system', dest='one_file_system',
|
|
@@ -2878,9 +2876,9 @@ class Archiver:
|
|
|
subparser.add_argument('--exclude-from', action=ArgparseExcludeFileAction,
|
|
|
metavar='EXCLUDEFILE', help='read exclude patterns from EXCLUDEFILE, one per line')
|
|
|
subparser.add_argument('--pattern', action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
subparser.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
subparser.add_argument('--numeric-owner', dest='numeric_owner',
|
|
|
action='store_true', default=False,
|
|
|
help='only obey numeric user and group identifiers')
|
|
@@ -2951,9 +2949,9 @@ class Archiver:
|
|
|
subparser.add_argument('--exclude-from', action=ArgparseExcludeFileAction,
|
|
|
metavar='EXCLUDEFILE', help='read exclude patterns from EXCLUDEFILE, one per line')
|
|
|
subparser.add_argument('--pattern', action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
subparser.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
subparser.add_argument('--strip-components', dest='strip_components',
|
|
|
type=int, default=0, metavar='NUMBER',
|
|
|
help='Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped.')
|
|
@@ -3027,9 +3025,9 @@ class Archiver:
|
|
|
'objects themselves from the backup archive')
|
|
|
exclude_group.add_argument('--pattern',
|
|
|
action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
exclude_group.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
|
|
|
rename_epilog = process_epilog("""
|
|
|
This command renames an archive in the repository.
|
|
@@ -3148,9 +3146,9 @@ class Archiver:
|
|
|
'objects themselves from the backup archive')
|
|
|
exclude_group.add_argument('--pattern',
|
|
|
action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
exclude_group.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
|
|
|
mount_epilog = process_epilog("""
|
|
|
This command mounts an archive as a FUSE filesystem. This can be useful for
|
|
@@ -3522,9 +3520,9 @@ class Archiver:
|
|
|
'objects themselves from the backup archive')
|
|
|
exclude_group.add_argument('--pattern',
|
|
|
action=ArgparsePatternAction,
|
|
|
- metavar="PATTERN", help='include/exclude paths matching PATTERN')
|
|
|
+ metavar="PATTERN", help='experimental: include/exclude paths matching PATTERN')
|
|
|
exclude_group.add_argument('--patterns-from', action=ArgparsePatternFileAction,
|
|
|
- metavar='PATTERNFILE', help='read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
+ metavar='PATTERNFILE', help='experimental: read include/exclude patterns from PATTERNFILE, one per line')
|
|
|
|
|
|
archive_group = subparser.add_argument_group('Archive options')
|
|
|
archive_group.add_argument('--target', dest='target', metavar='TARGET', default=None,
|