From 2a36a2a312a140dae7ef84e6698d26014c5e2acd Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 26 Feb 2023 23:22:23 -0800 Subject: [PATCH] Add "--repository" flag to the "rcreate" action. Add "--progress" flag to the "transfer" action. --- NEWS | 3 +++ borgmatic/actions/rcreate.py | 6 ++++++ borgmatic/borg/transfer.py | 4 +++- borgmatic/commands/arguments.py | 10 ++++++++++ docs/how-to/upgrade.md | 19 ++++++++++++++----- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 46042ab..8e8e1de 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ action. * Fix the "create" action with the "--dry-run" flag querying for databases when a PostgreSQL/MySQL "all" database is configured. Now, these queries are skipped due to the dry run. + * Add "--repository" flag to the "rcreate" action to optionally select one configured repository to + create. + * Add "--progress" flag to the "transfer" action, new in Borg 2.0.0b5. 1.7.7 * #642: Add MySQL database hook "add_drop_database" configuration option to control whether dumped diff --git a/borgmatic/actions/rcreate.py b/borgmatic/actions/rcreate.py index daf4b5b..0052b4b 100644 --- a/borgmatic/actions/rcreate.py +++ b/borgmatic/actions/rcreate.py @@ -1,6 +1,7 @@ import logging import borgmatic.borg.rcreate +import borgmatic.config.validate logger = logging.getLogger(__name__) @@ -17,6 +18,11 @@ def run_rcreate( ''' Run the "rcreate" action for the given repository. ''' + if rcreate_arguments.repository and not borgmatic.config.validate.repositories_match( + repository, rcreate_arguments.repository + ): + return + logger.info('{}: Creating repository'.format(repository)) borgmatic.borg.rcreate.create_repository( global_arguments.dry_run, diff --git a/borgmatic/borg/transfer.py b/borgmatic/borg/transfer.py index fd9c46a..bad02d0 100644 --- a/borgmatic/borg/transfer.py +++ b/borgmatic/borg/transfer.py @@ -2,7 +2,7 @@ import logging import borgmatic.logger from borgmatic.borg import environment, flags -from borgmatic.execute import execute_command +from borgmatic.execute import DO_NOT_CAPTURE, execute_command logger = logging.getLogger(__name__) @@ -28,6 +28,7 @@ def transfer_archives( + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + flags.make_flags('remote-path', remote_path) + flags.make_flags('lock-wait', storage_config.get('lock_wait', None)) + + (('--progress',) if transfer_arguments.progress else ()) + ( flags.make_flags( 'match-archives', transfer_arguments.match_archives or transfer_arguments.archive @@ -45,6 +46,7 @@ def transfer_archives( return execute_command( full_command, output_log_level=logging.ANSWER, + output_file=DO_NOT_CAPTURE if transfer_arguments.progress else None, borg_local_path=local_path, extra_environment=environment.make_environment(storage_config), ) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 6061da9..8af9bb5 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -247,6 +247,10 @@ def make_parsers(): metavar='KEY_REPOSITORY', help='Path to an existing Borg repository whose key material should be reused (Borg 2.x+ only)', ) + rcreate_group.add_argument( + '--repository', + help='Path of the new repository to create (must be already specified in a borgmatic configuration file), defaults to the configured repository if there is only one', + ) rcreate_group.add_argument( '--copy-crypt-key', action='store_true', @@ -292,6 +296,12 @@ def make_parsers(): '--upgrader', help='Upgrader type used to convert the transfered data, e.g. "From12To20" to upgrade data from Borg 1.2 to 2.0 format, defaults to no conversion', ) + transfer_group.add_argument( + '--progress', + default=False, + action='store_true', + help='Display progress as each archive is transferred', + ) transfer_group.add_argument( '-a', '--match-archives', diff --git a/docs/how-to/upgrade.md b/docs/how-to/upgrade.md index 15411c8..296b3f8 100644 --- a/docs/how-to/upgrade.md +++ b/docs/how-to/upgrade.md @@ -169,12 +169,21 @@ The `--source-repository` flag is necessary to reuse key material from your Borg 1 repository so that the subsequent data transfer can work. The `--encryption` value above selects the same chunk ID algorithm (`blake2`) -used in Borg 1, thereby making deduplication work across transferred archives -and new archives. Note that `repokey-blake2-chacha20-poly1305` may be faster -than `repokey-blake2-aes-ocb` on certain platforms like ARM64. Read about -[Borg encryption +commonly used in Borg 1, thereby making deduplication work across transferred +archives and new archives. + +If you get an error about "You must keep the same ID hash" from Borg, that +means the encryption value you specified doesn't correspond to your source +repository's chunk ID algorithm. In that case, try not using `blake2`: + +```bash +borgmatic rcreate --verbosity 1 --encryption repokey-aes-ocb \ + --source-repository original.borg --repository upgraded.borg +``` + +Read about [Borg encryption modes](https://borgbackup.readthedocs.io/en/2.0.0b5/usage/rcreate.html#encryption-mode-tldr) -for the menu of available encryption modes. +for more details. To transfer data from your original Borg 1 repository to your newly created Borg 2 repository: