2018-05-26 16:19:05 -07:00
|
|
|
import logging
|
2019-04-02 22:30:14 -07:00
|
|
|
|
2019-06-25 10:18:30 -07:00
|
|
|
from borgmatic.borg.flags import make_flags, make_flags_from_arguments
|
2019-06-12 12:13:59 -07:00
|
|
|
from borgmatic.execute import execute_command
|
2018-05-26 16:19:05 -07:00
|
|
|
|
2019-06-17 11:53:08 -07:00
|
|
|
logger = logging.getLogger(__name__)
|
2018-05-26 16:19:05 -07:00
|
|
|
|
|
|
|
|
2019-10-16 10:24:58 -07:00
|
|
|
# A hack to convince Borg to exclude archives ending in ".checkpoint". This assumes that a
|
|
|
|
# non-checkpoint archive name ends in a digit (e.g. from a timestamp).
|
|
|
|
BORG_EXCLUDE_CHECKPOINTS_GLOB = '*[0123456789]'
|
2019-10-13 15:58:11 -07:00
|
|
|
|
|
|
|
|
2019-06-25 10:18:30 -07:00
|
|
|
def list_archives(repository, storage_config, list_arguments, local_path='borg', remote_path=None):
|
2018-05-26 16:19:05 -07:00
|
|
|
'''
|
2019-06-25 10:18:30 -07:00
|
|
|
Given a local or remote repository path, a storage config dict, and the arguments to the list
|
|
|
|
action, display the output of listing Borg archives in the repository or return JSON output. Or,
|
|
|
|
if an archive name is given, listing the files in that archive.
|
2018-05-26 16:19:05 -07:00
|
|
|
'''
|
|
|
|
lock_wait = storage_config.get('lock_wait', None)
|
2019-10-13 15:58:11 -07:00
|
|
|
if list_arguments.successful:
|
|
|
|
list_arguments.glob_archives = BORG_EXCLUDE_CHECKPOINTS_GLOB
|
2018-05-26 16:19:05 -07:00
|
|
|
|
|
|
|
full_command = (
|
2019-09-12 15:27:04 -07:00
|
|
|
(local_path, 'list')
|
2019-06-25 10:18:30 -07:00
|
|
|
+ (
|
|
|
|
('--info',)
|
|
|
|
if logger.getEffectiveLevel() == logging.INFO and not list_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ (
|
|
|
|
('--debug', '--show-rc')
|
|
|
|
if logger.isEnabledFor(logging.DEBUG) and not list_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ make_flags('remote-path', remote_path)
|
|
|
|
+ make_flags('lock-wait', lock_wait)
|
2019-10-13 15:58:11 -07:00
|
|
|
+ make_flags_from_arguments(
|
|
|
|
list_arguments, excludes=('repository', 'archive', 'successful')
|
|
|
|
)
|
2019-09-12 15:27:04 -07:00
|
|
|
+ (
|
|
|
|
'::'.join((repository, list_arguments.archive))
|
|
|
|
if list_arguments.archive
|
|
|
|
else repository,
|
|
|
|
)
|
2018-05-26 16:19:05 -07:00
|
|
|
)
|
2018-07-28 21:21:38 +00:00
|
|
|
|
2019-06-25 10:18:30 -07:00
|
|
|
return execute_command(
|
|
|
|
full_command, output_log_level=None if list_arguments.json else logging.WARNING
|
|
|
|
)
|