Skip to content

Commit

Permalink
add support to set repository_version if init restic repository (#171)
Browse files Browse the repository at this point in the history
The newer versions of restic use a new repository format with new
features. In legacy environments it may be useful to support both
version of repository formats.

---------

Co-authored-by: Samuel Warkentin <[email protected]>
Co-authored-by: Michael Lynch <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2024
1 parent 2692500 commit 24a63f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Initializes a new restic repository at the current repository location.
- `copy-chunker-params`: Copy chunker parameters from the secondary repository
- `from_repo`: Secondary repository to copy chunker parameters from
- `from_password_file`: Path to file containing password for secondary repository
- `repository_version`: Version number of repository format to use (can be `1` or `2`)

### Returns

Expand Down
6 changes: 5 additions & 1 deletion restic/internal/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
def run(restic_base_command,
copy_chunker_params=False,
from_repo=None,
from_password_file=None):
from_password_file=None,
repository_version=None):
cmd = restic_base_command + ['init']

if copy_chunker_params:
Expand All @@ -19,6 +20,9 @@ def run(restic_base_command,
if from_password_file:
cmd.extend(['--from-password-file', from_password_file])

if repository_version:
cmd.extend(['--repository-version', str(repository_version)])

return _parse_result(command_executor.execute(cmd))


Expand Down
14 changes: 14 additions & 0 deletions restic/internal/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ def test_init_with_secondary_repository(self, mock_execute):
'restic', '--json', 'init', '--copy-chunker-params', '--from-repo',
's3:https://some.backend.com/mybucket'
])

@mock.patch.object(init.command_executor, 'execute')
def test_init_with_repository_version(self, mock_execute):
mock_execute.return_value = """
{"message_type":"initialized","id":"d0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48","repository":"/tmp/tmp.lNaHYLGR7F"}
""".strip()

repository_id = restic.init(repository_version=1)

self.assertEqual(
'd0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48',
repository_id)
mock_execute.assert_called_with(
['restic', '--json', 'init', '--repository-version', '1'])

0 comments on commit 24a63f3

Please sign in to comment.