From da7aed381436f63c25a5d232340e009598ddcbab Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 19 Aug 2018 11:41:49 -0700 Subject: [PATCH] Support for Borg create --checkpoint-interval (#87). --- NEWS | 2 ++ borgmatic/borg/create.py | 2 ++ borgmatic/config/schema.yaml | 7 +++++++ borgmatic/tests/unit/borg/test_create.py | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/NEWS b/NEWS index d55a0ef..4b0043d 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ 1.2.3.dev0 + * #87: Support for Borg create --checkpoint-interval via "checkpoint_interval" option in + borgmatic's storage configuration. * #88: Fix declared pykwalify compatibility version range in setup.py to prevent use of ancient versions of pykwalify with large version numbers. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 632f39c..3b8c9d9 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -115,6 +115,7 @@ def create_archive( pattern_file = _write_pattern_file(location_config.get('patterns')) exclude_file = _write_pattern_file(_expand_directories(location_config.get('exclude_patterns'))) + checkpoint_interval = storage_config.get('checkpoint_interval', None) compression = storage_config.get('compression', None) remote_rate_limit = storage_config.get('remote_rate_limit', None) umask = storage_config.get('umask', None) @@ -140,6 +141,7 @@ def create_archive( location_config, exclude_file.name if exclude_file else None, ) + + (('--checkpoint-interval', str(checkpoint_interval)) if checkpoint_interval else ()) + (('--compression', compression) if compression else ()) + (('--remote-ratelimit', str(remote_rate_limit)) if remote_rate_limit else ()) + (('--one-file-system',) if location_config.get('one_file_system') else ()) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index a7b9a17..7219a67 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -124,6 +124,13 @@ map: punctuation, so it parses correctly. And backslash any quote or backslash literals as well. example: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" + checkpoint_interval: + type: int + desc: | + Number of seconds between each checkpoint during a long-running backup. See + https://borgbackup.readthedocs.io/en/stable/faq.html#if-a-backup-stops-mid-way-does-the-already-backed-up-data-stay-there + for details. Defaults to checkpoints every 1800 seconds (30 minutes). + example: 1800 compression: type: scalar desc: | diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 411893c..f918ae1 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -374,6 +374,26 @@ def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats ) +def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters(): + flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) + flexmock(module).should_receive('_write_pattern_file').and_return(None) + flexmock(module).should_receive('_make_pattern_flags').and_return(()) + flexmock(module).should_receive('_make_exclude_flags').and_return(()) + insert_subprocess_mock(CREATE_COMMAND + ('--checkpoint-interval', '600')) + + module.create_archive( + verbosity=None, + dry_run=False, + repository='repo', + location_config={ + 'source_directories': ['foo', 'bar'], + 'repositories': ['repo'], + 'exclude_patterns': None, + }, + storage_config={'checkpoint_interval': 600}, + ) + + def test_create_archive_with_compression_calls_borg_with_compression_parameters(): flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(()) flexmock(module).should_receive('_write_pattern_file').and_return(None)