2023-10-26 22:12:13 -07:00
|
|
|
import argparse
|
2018-05-26 16:19:05 -07:00
|
|
|
import logging
|
2019-04-02 22:30:14 -07:00
|
|
|
|
2022-12-02 12:12:10 -08:00
|
|
|
import borgmatic.logger
|
2022-10-03 22:50:37 -07:00
|
|
|
from borgmatic.borg import environment, feature, flags
|
2022-10-14 16:19:26 -07:00
|
|
|
from borgmatic.execute import execute_command, execute_command_and_capture_output
|
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
|
|
|
|
|
|
|
|
|
2023-10-26 22:12:13 -07:00
|
|
|
def make_info_command(
|
2023-03-26 23:52:25 +05:30
|
|
|
repository_path,
|
2023-07-08 23:14:30 -07:00
|
|
|
config,
|
2022-08-12 14:53:20 -07:00
|
|
|
local_borg_version,
|
|
|
|
|
info_arguments,
|
2023-05-08 23:00:49 -07:00
|
|
|
global_arguments,
|
2023-10-26 22:12:13 -07:00
|
|
|
local_path,
|
|
|
|
|
remote_path,
|
2018-09-29 22:45:00 -07:00
|
|
|
):
|
2018-05-26 16:19:05 -07:00
|
|
|
'''
|
2023-10-26 22:12:13 -07:00
|
|
|
Given a local or remote repository path, a configuration dict, the local Borg version, the
|
|
|
|
|
arguments to the info action as an argparse.Namespace, and global arguments, return a command
|
|
|
|
|
as a tuple to display summary information for archives in the repository.
|
2018-05-26 16:19:05 -07:00
|
|
|
'''
|
2023-10-26 22:12:13 -07:00
|
|
|
return (
|
2019-09-12 15:27:04 -07:00
|
|
|
(local_path, 'info')
|
2019-06-25 10:46:55 -07:00
|
|
|
+ (
|
|
|
|
|
('--info',)
|
|
|
|
|
if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json
|
|
|
|
|
else ()
|
|
|
|
|
)
|
|
|
|
|
+ (
|
|
|
|
|
('--debug', '--show-rc')
|
|
|
|
|
if logger.isEnabledFor(logging.DEBUG) and not info_arguments.json
|
|
|
|
|
else ()
|
|
|
|
|
)
|
2022-08-17 15:36:19 -07:00
|
|
|
+ flags.make_flags('remote-path', remote_path)
|
2023-05-08 23:00:49 -07:00
|
|
|
+ flags.make_flags('log-json', global_arguments.log_json)
|
2023-10-26 22:12:13 -07:00
|
|
|
+ flags.make_flags('lock-wait', config.get('lock_wait'))
|
2022-08-17 15:36:19 -07:00
|
|
|
+ (
|
2022-10-03 22:50:37 -07:00
|
|
|
(
|
|
|
|
|
flags.make_flags('match-archives', f'sh:{info_arguments.prefix}*')
|
|
|
|
|
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
|
|
|
|
else flags.make_flags('glob-archives', f'{info_arguments.prefix}*')
|
|
|
|
|
)
|
2022-08-17 15:36:19 -07:00
|
|
|
if info_arguments.prefix
|
2023-03-31 15:21:08 -07:00
|
|
|
else (
|
|
|
|
|
flags.make_match_archives_flags(
|
2023-04-04 21:25:10 -07:00
|
|
|
info_arguments.match_archives
|
|
|
|
|
or info_arguments.archive
|
2023-07-08 23:14:30 -07:00
|
|
|
or config.get('match_archives'),
|
|
|
|
|
config.get('archive_name_format'),
|
2023-04-01 23:57:55 -07:00
|
|
|
local_borg_version,
|
2023-03-31 15:21:08 -07:00
|
|
|
)
|
|
|
|
|
)
|
2022-08-17 15:36:19 -07:00
|
|
|
)
|
|
|
|
|
+ flags.make_flags_from_arguments(
|
2023-04-04 21:25:10 -07:00
|
|
|
info_arguments, excludes=('repository', 'archive', 'prefix', 'match_archives')
|
2022-08-17 15:36:19 -07:00
|
|
|
)
|
2023-03-26 23:52:25 +05:30
|
|
|
+ flags.make_repository_flags(repository_path, local_borg_version)
|
2018-05-26 16:19:05 -07:00
|
|
|
)
|
|
|
|
|
|
2023-10-26 22:12:13 -07:00
|
|
|
|
|
|
|
|
def display_archives_info(
|
|
|
|
|
repository_path,
|
|
|
|
|
config,
|
|
|
|
|
local_borg_version,
|
|
|
|
|
info_arguments,
|
|
|
|
|
global_arguments,
|
|
|
|
|
local_path='borg',
|
|
|
|
|
remote_path=None,
|
|
|
|
|
):
|
|
|
|
|
'''
|
|
|
|
|
Given a local or remote repository path, a configuration dict, the local Borg version, the
|
|
|
|
|
arguments to the info action as an argparse.Namespace, and global arguments, display summary
|
|
|
|
|
information for Borg archives in the repository or return JSON summary information.
|
|
|
|
|
'''
|
|
|
|
|
borgmatic.logger.add_custom_log_levels()
|
|
|
|
|
|
|
|
|
|
main_command = make_info_command(
|
|
|
|
|
repository_path,
|
|
|
|
|
config,
|
|
|
|
|
local_borg_version,
|
|
|
|
|
info_arguments,
|
|
|
|
|
global_arguments,
|
|
|
|
|
local_path,
|
|
|
|
|
remote_path,
|
|
|
|
|
)
|
|
|
|
|
json_command = make_info_command(
|
|
|
|
|
repository_path,
|
|
|
|
|
config,
|
|
|
|
|
local_borg_version,
|
|
|
|
|
argparse.Namespace(**dict(info_arguments.__dict__, json=True)),
|
|
|
|
|
global_arguments,
|
|
|
|
|
local_path,
|
|
|
|
|
remote_path,
|
|
|
|
|
)
|
2024-01-21 11:34:40 -08:00
|
|
|
borg_exit_codes = config.get('borg_exit_codes')
|
2023-10-26 22:12:13 -07:00
|
|
|
|
|
|
|
|
json_info = execute_command_and_capture_output(
|
|
|
|
|
json_command,
|
|
|
|
|
extra_environment=environment.make_environment(config),
|
|
|
|
|
borg_local_path=local_path,
|
2024-01-21 11:34:40 -08:00
|
|
|
borg_exit_codes=borg_exit_codes,
|
2023-10-26 22:12:13 -07:00
|
|
|
)
|
|
|
|
|
|
2022-10-14 16:19:26 -07:00
|
|
|
if info_arguments.json:
|
2023-10-26 22:12:13 -07:00
|
|
|
return json_info
|
|
|
|
|
|
|
|
|
|
flags.warn_for_aggressive_archive_flags(json_command, json_info)
|
|
|
|
|
|
|
|
|
|
execute_command(
|
|
|
|
|
main_command,
|
|
|
|
|
output_log_level=logging.ANSWER,
|
|
|
|
|
extra_environment=environment.make_environment(config),
|
2024-01-21 11:34:40 -08:00
|
|
|
borg_local_path=local_path,
|
|
|
|
|
borg_exit_codes=borg_exit_codes,
|
2023-10-26 22:12:13 -07:00
|
|
|
)
|