mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 14:41:43 +00:00
Merge pull request #3880 from ThomasWaldmann/cat_config-1.1
borg config --list <repo>, fixes #3612 (1.1 backport)
This commit is contained in:
commit
fe8b52fc87
2 changed files with 51 additions and 12 deletions
|
@ -1775,11 +1775,32 @@ def cache_validate(section, name, value=None, check_value=True):
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid name')
|
raise ValueError('Invalid name')
|
||||||
|
|
||||||
try:
|
def list_config(config):
|
||||||
section, name = args.name.split('.')
|
default_values = {
|
||||||
except ValueError:
|
'version': '1',
|
||||||
section = args.cache and "cache" or "repository"
|
'segments_per_dir': str(DEFAULT_SEGMENTS_PER_DIR),
|
||||||
name = args.name
|
'max_segment_size': str(MAX_SEGMENT_SIZE_LIMIT),
|
||||||
|
'additional_free_space': '0',
|
||||||
|
'storage_quota': repository.storage_quota,
|
||||||
|
'append_only': repository.append_only
|
||||||
|
}
|
||||||
|
print('[repository]')
|
||||||
|
for key in ['version', 'segments_per_dir', 'max_segment_size',
|
||||||
|
'storage_quota', 'additional_free_space', 'append_only',
|
||||||
|
'id']:
|
||||||
|
value = config.get('repository', key, fallback=False)
|
||||||
|
if value is None:
|
||||||
|
value = default_values.get(key)
|
||||||
|
if value is None:
|
||||||
|
raise Error('The repository config is missing the %s key which has no default value' % key)
|
||||||
|
print('%s = %s' % (key, value))
|
||||||
|
|
||||||
|
if not args.list:
|
||||||
|
try:
|
||||||
|
section, name = args.name.split('.')
|
||||||
|
except ValueError:
|
||||||
|
section = args.cache and "cache" or "repository"
|
||||||
|
name = args.name
|
||||||
|
|
||||||
if args.cache:
|
if args.cache:
|
||||||
manifest, key = Manifest.load(repository, (Manifest.Operation.WRITE,))
|
manifest, key = Manifest.load(repository, (Manifest.Operation.WRITE,))
|
||||||
|
@ -1803,6 +1824,8 @@ def cache_validate(section, name, value=None, check_value=True):
|
||||||
if len(config.options(section)) == 0:
|
if len(config.options(section)) == 0:
|
||||||
config.remove_section(section)
|
config.remove_section(section)
|
||||||
save()
|
save()
|
||||||
|
elif args.list:
|
||||||
|
list_config(config)
|
||||||
elif args.value:
|
elif args.value:
|
||||||
validate(section, name, args.value)
|
validate(section, name, args.value)
|
||||||
if section not in config.sections():
|
if section not in config.sections():
|
||||||
|
@ -3846,10 +3869,13 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
|
||||||
This command gets and sets options in a local repository or cache config file.
|
This command gets and sets options in a local repository or cache config file.
|
||||||
For security reasons, this command only works on local repositories.
|
For security reasons, this command only works on local repositories.
|
||||||
|
|
||||||
To delete a config value entirely, use ``--delete``. To get an existing key, pass
|
To delete a config value entirely, use ``--delete``. To list the values
|
||||||
only the key name. To set a key, pass both the key name and the new value. Keys
|
of the configuration file or the default values, use ``--list``. To get and existing
|
||||||
can be specified in the format "section.name" or simply "name"; the section will
|
key, pass only the key name. To set a key, pass both the key name and
|
||||||
default to "repository" and "cache" for the repo and cache configs, respectively.
|
the new value. Keys can be specified in the format "section.name" or
|
||||||
|
simply "name"; the section will default to "repository" and "cache" for
|
||||||
|
the repo and cache configs, respectively.
|
||||||
|
|
||||||
|
|
||||||
By default, borg config manipulates the repository config file. Using ``--cache``
|
By default, borg config manipulates the repository config file. Using ``--cache``
|
||||||
edits the repository cache's config file instead.
|
edits the repository cache's config file instead.
|
||||||
|
@ -3862,13 +3888,17 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
|
||||||
subparser.set_defaults(func=self.do_config)
|
subparser.set_defaults(func=self.do_config)
|
||||||
subparser.add_argument('-c', '--cache', dest='cache', action='store_true',
|
subparser.add_argument('-c', '--cache', dest='cache', action='store_true',
|
||||||
help='get and set values from the repo cache')
|
help='get and set values from the repo cache')
|
||||||
subparser.add_argument('-d', '--delete', dest='delete', action='store_true',
|
|
||||||
|
group = subparser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument('-d', '--delete', dest='delete', action='store_true',
|
||||||
help='delete the key from the config file')
|
help='delete the key from the config file')
|
||||||
|
group.add_argument('-l', '--list', dest='list', action='store_true',
|
||||||
|
help='list the configuration of the repo')
|
||||||
|
|
||||||
subparser.add_argument('location', metavar='REPOSITORY',
|
subparser.add_argument('location', metavar='REPOSITORY',
|
||||||
type=location_validator(archive=False, proto='file'),
|
type=location_validator(archive=False, proto='file'),
|
||||||
help='repository to configure')
|
help='repository to configure')
|
||||||
subparser.add_argument('name', metavar='NAME',
|
subparser.add_argument('name', metavar='NAME', nargs='?',
|
||||||
help='name of config key')
|
help='name of config key')
|
||||||
subparser.add_argument('value', metavar='VALUE', nargs='?',
|
subparser.add_argument('value', metavar='VALUE', nargs='?',
|
||||||
help='new value for key')
|
help='new value for key')
|
||||||
|
|
|
@ -2785,6 +2785,14 @@ def test_config(self):
|
||||||
self.create_test_files()
|
self.create_test_files()
|
||||||
os.unlink('input/flagfile')
|
os.unlink('input/flagfile')
|
||||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||||
|
output = self.cmd('config', '--list', self.repository_location)
|
||||||
|
self.assert_in('[repository]', output)
|
||||||
|
self.assert_in('version', output)
|
||||||
|
self.assert_in('segments_per_dir', output)
|
||||||
|
self.assert_in('storage_quota', output)
|
||||||
|
self.assert_in('append_only', output)
|
||||||
|
self.assert_in('additional_free_space', output)
|
||||||
|
self.assert_in('id', output)
|
||||||
for cfg_key, cfg_value in [
|
for cfg_key, cfg_value in [
|
||||||
('additional_free_space', '2G'),
|
('additional_free_space', '2G'),
|
||||||
('repository.append_only', '1'),
|
('repository.append_only', '1'),
|
||||||
|
@ -2794,8 +2802,9 @@ def test_config(self):
|
||||||
self.cmd('config', self.repository_location, cfg_key, cfg_value)
|
self.cmd('config', self.repository_location, cfg_key, cfg_value)
|
||||||
output = self.cmd('config', self.repository_location, cfg_key)
|
output = self.cmd('config', self.repository_location, cfg_key)
|
||||||
assert output == cfg_value + '\n'
|
assert output == cfg_value + '\n'
|
||||||
self.cmd('config', self.repository_location, '--delete', cfg_key)
|
self.cmd('config', '--delete', self.repository_location, cfg_key)
|
||||||
self.cmd('config', self.repository_location, cfg_key, exit_code=1)
|
self.cmd('config', self.repository_location, cfg_key, exit_code=1)
|
||||||
|
self.cmd('config', '--list', '--delete', self.repository_location, exit_code=2)
|
||||||
|
|
||||||
requires_gnutar = pytest.mark.skipif(not have_gnutar(), reason='GNU tar must be installed for this test.')
|
requires_gnutar = pytest.mark.skipif(not have_gnutar(), reason='GNU tar must be installed for this test.')
|
||||||
requires_gzip = pytest.mark.skipif(not shutil.which('gzip'), reason='gzip must be installed for this test.')
|
requires_gzip = pytest.mark.skipif(not shutil.which('gzip'), reason='gzip must be installed for this test.')
|
||||||
|
|
Loading…
Reference in a new issue