diff --git a/docs/index.md b/docs/index.md index f27d897..d4aef91 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/restic/internal/init.py b/restic/internal/init.py index 7a5232b..bf12e19 100644 --- a/restic/internal/init.py +++ b/restic/internal/init.py @@ -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: @@ -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)) diff --git a/restic/internal/init_test.py b/restic/internal/init_test.py index 602adb1..f233124 100644 --- a/restic/internal/init_test.py +++ b/restic/internal/init_test.py @@ -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'])