2023-01-26 07:31:07 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import borgmatic.borg.compact
|
|
|
|
import borgmatic.borg.feature
|
2023-03-16 15:13:45 +00:00
|
|
|
import borgmatic.config.validate
|
2023-01-26 07:31:07 +00:00
|
|
|
import borgmatic.hooks.command
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def run_compact(
|
|
|
|
config_filename,
|
|
|
|
repository,
|
2023-07-09 06:14:30 +00:00
|
|
|
config,
|
2023-01-26 07:31:07 +00:00
|
|
|
local_borg_version,
|
|
|
|
compact_arguments,
|
|
|
|
global_arguments,
|
|
|
|
dry_run_label,
|
|
|
|
local_path,
|
|
|
|
remote_path,
|
|
|
|
):
|
|
|
|
'''
|
|
|
|
Run the "compact" action for the given repository.
|
|
|
|
'''
|
2023-03-16 15:13:45 +00:00
|
|
|
if compact_arguments.repository and not borgmatic.config.validate.repositories_match(
|
|
|
|
repository, compact_arguments.repository
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
2023-01-26 07:31:07 +00:00
|
|
|
if borgmatic.borg.feature.available(borgmatic.borg.feature.Feature.COMPACT, local_borg_version):
|
2025-01-25 22:14:48 +00:00
|
|
|
logger.info(f'Compacting segments{dry_run_label}')
|
2023-01-26 07:31:07 +00:00
|
|
|
borgmatic.borg.compact.compact_segments(
|
|
|
|
global_arguments.dry_run,
|
2023-03-24 19:34:57 +00:00
|
|
|
repository['path'],
|
2023-07-09 06:14:30 +00:00
|
|
|
config,
|
2023-01-26 07:31:07 +00:00
|
|
|
local_borg_version,
|
2023-05-09 06:00:49 +00:00
|
|
|
global_arguments,
|
2023-01-26 07:31:07 +00:00
|
|
|
local_path=local_path,
|
|
|
|
remote_path=remote_path,
|
|
|
|
progress=compact_arguments.progress,
|
|
|
|
cleanup_commits=compact_arguments.cleanup_commits,
|
|
|
|
threshold=compact_arguments.threshold,
|
|
|
|
)
|
|
|
|
else: # pragma: nocover
|
2025-01-25 22:14:48 +00:00
|
|
|
logger.info('Skipping compact (only available/needed in Borg 1.2+)')
|