mirror of https://github.com/borgbackup/borg.git
Adds --prefix to the archives filters arguments
- adds prefix argument to helpers.Archives.list - also renames function PrefixSpec to prefix_spec
This commit is contained in:
parent
f6b9276de9
commit
17f2363935
|
@ -30,7 +30,7 @@ from .constants import * # NOQA
|
||||||
from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR
|
from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR
|
||||||
from .helpers import Error, NoManifestError
|
from .helpers import Error, NoManifestError
|
||||||
from .helpers import location_validator, archivename_validator, ChunkerParams, CompressionSpec
|
from .helpers import location_validator, archivename_validator, ChunkerParams, CompressionSpec
|
||||||
from .helpers import PrefixSpec, sort_by_spec, HUMAN_SORT_KEYS
|
from .helpers import prefix_spec, sort_by_spec, HUMAN_SORT_KEYS
|
||||||
from .helpers import BaseFormatter, ItemFormatter, ArchiveFormatter, format_time, format_file_size, format_archive
|
from .helpers import BaseFormatter, ItemFormatter, ArchiveFormatter, format_time, format_file_size, format_archive
|
||||||
from .helpers import safe_encode, remove_surrogates, bin_to_hex
|
from .helpers import safe_encode, remove_surrogates, bin_to_hex
|
||||||
from .helpers import prune_within, prune_split
|
from .helpers import prune_within, prune_split
|
||||||
|
@ -1605,7 +1605,7 @@ class Archiver:
|
||||||
subparser.add_argument('--last', dest='last',
|
subparser.add_argument('--last', dest='last',
|
||||||
type=int, default=None, metavar='N',
|
type=int, default=None, metavar='N',
|
||||||
help='only check last N archives (Default: all)')
|
help='only check last N archives (Default: all)')
|
||||||
subparser.add_argument('-P', '--prefix', dest='prefix', type=PrefixSpec,
|
subparser.add_argument('-P', '--prefix', dest='prefix', type=prefix_spec,
|
||||||
help='only consider archive names starting with this prefix')
|
help='only consider archive names starting with this prefix')
|
||||||
subparser.add_argument('-p', '--progress', dest='progress',
|
subparser.add_argument('-p', '--progress', dest='progress',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
|
@ -1995,7 +1995,7 @@ class Archiver:
|
||||||
subparser.add_argument('--format', '--list-format', dest='format', type=str,
|
subparser.add_argument('--format', '--list-format', dest='format', type=str,
|
||||||
help="""specify format for file listing
|
help="""specify format for file listing
|
||||||
(default: "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NL}")""")
|
(default: "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NL}")""")
|
||||||
subparser.add_argument('-P', '--prefix', dest='prefix', type=PrefixSpec,
|
subparser.add_argument('-P', '--prefix', dest='prefix', type=prefix_spec,
|
||||||
help='only consider archive names starting with this prefix')
|
help='only consider archive names starting with this prefix')
|
||||||
subparser.add_argument('-e', '--exclude', dest='excludes',
|
subparser.add_argument('-e', '--exclude', dest='excludes',
|
||||||
type=parse_pattern, action='append',
|
type=parse_pattern, action='append',
|
||||||
|
@ -2161,7 +2161,7 @@ class Archiver:
|
||||||
help='number of monthly archives to keep')
|
help='number of monthly archives to keep')
|
||||||
subparser.add_argument('-y', '--keep-yearly', dest='yearly', type=int, default=0,
|
subparser.add_argument('-y', '--keep-yearly', dest='yearly', type=int, default=0,
|
||||||
help='number of yearly archives to keep')
|
help='number of yearly archives to keep')
|
||||||
subparser.add_argument('-P', '--prefix', dest='prefix', type=PrefixSpec,
|
subparser.add_argument('-P', '--prefix', dest='prefix', type=prefix_spec,
|
||||||
help='only consider archive names starting with this prefix')
|
help='only consider archive names starting with this prefix')
|
||||||
subparser.add_argument('--save-space', dest='save_space', action='store_true',
|
subparser.add_argument('--save-space', dest='save_space', action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
|
@ -2634,7 +2634,7 @@ class Archiver:
|
||||||
if args.location.archive:
|
if args.location.archive:
|
||||||
raise Error('The options --first, --last and --prefix can only be used on repository targets.')
|
raise Error('The options --first, --last and --prefix can only be used on repository targets.')
|
||||||
|
|
||||||
archives = manifest.archives.list()
|
archives = manifest.archives.list(prefix=args.prefix)
|
||||||
if not archives:
|
if not archives:
|
||||||
logger.critical('There are no archives.')
|
logger.critical('There are no archives.')
|
||||||
self.exit_code = self.exit_code or EXIT_WARNING
|
self.exit_code = self.exit_code or EXIT_WARNING
|
||||||
|
@ -2645,7 +2645,7 @@ class Archiver:
|
||||||
if args.last:
|
if args.last:
|
||||||
archives.reverse()
|
archives.reverse()
|
||||||
|
|
||||||
n = args.first or args.last
|
n = args.first or args.last or len(archives)
|
||||||
|
|
||||||
return archives[:n]
|
return archives[:n]
|
||||||
|
|
||||||
|
|
|
@ -142,11 +142,11 @@ class Archives(abc.MutableMapping):
|
||||||
name = safe_encode(name)
|
name = safe_encode(name)
|
||||||
del self._archives[name]
|
del self._archives[name]
|
||||||
|
|
||||||
def list(self, sort_by=None, reverse=False):
|
def list(self, sort_by=None, reverse=False, prefix=''):
|
||||||
""" Inexpensive Archive.list_archives replacement if we just need .name, .id, .ts
|
""" Inexpensive Archive.list_archives replacement if we just need .name, .id, .ts
|
||||||
Returns list of borg.helpers.ArchiveInfo instances
|
Returns list of borg.helpers.ArchiveInfo instances
|
||||||
"""
|
"""
|
||||||
archives = list(self.values()) # [self[name] for name in self]
|
archives = [x for x in self.values() if x.name.startswith(prefix)]
|
||||||
if sort_by is not None:
|
if sort_by is not None:
|
||||||
archives = sorted(archives, key=attrgetter(sort_by))
|
archives = sorted(archives, key=attrgetter(sort_by))
|
||||||
if reverse:
|
if reverse:
|
||||||
|
@ -572,10 +572,6 @@ def CompressionSpec(s):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
|
|
||||||
def PrefixSpec(s):
|
|
||||||
return replace_placeholders(s)
|
|
||||||
|
|
||||||
|
|
||||||
def dir_is_cachedir(path):
|
def dir_is_cachedir(path):
|
||||||
"""Determines whether the specified path is a cache directory (and
|
"""Determines whether the specified path is a cache directory (and
|
||||||
therefore should potentially be excluded from the backup) according to
|
therefore should potentially be excluded from the backup) according to
|
||||||
|
@ -658,10 +654,13 @@ def replace_placeholders(text):
|
||||||
}
|
}
|
||||||
return format_line(text, data)
|
return format_line(text, data)
|
||||||
|
|
||||||
|
prefix_spec = replace_placeholders
|
||||||
|
|
||||||
|
|
||||||
HUMAN_SORT_KEYS = ['timestamp'] + list(ArchiveInfo._fields)
|
HUMAN_SORT_KEYS = ['timestamp'] + list(ArchiveInfo._fields)
|
||||||
HUMAN_SORT_KEYS.remove('ts')
|
HUMAN_SORT_KEYS.remove('ts')
|
||||||
|
|
||||||
|
|
||||||
def sort_by_spec(text):
|
def sort_by_spec(text):
|
||||||
for token in text.split(','):
|
for token in text.split(','):
|
||||||
if token not in HUMAN_SORT_KEYS:
|
if token not in HUMAN_SORT_KEYS:
|
||||||
|
|
Loading…
Reference in New Issue