Skip to content

Commit

Permalink
Add snapshots command
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Mar 28, 2021
1 parent 1e5213a commit 3ee0faf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions e2e/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def emit(self, record):
logger.fatal('Expected to restored file to contain %s (got %s)',
RESTORED_DATA_EXPECTED, RESTORED_DATA_ACTUAL)

snapshots = restic.snapshots(group_by='host')
logger.info('repo snapshots: %s', json.dumps(snapshots))

stats = restic.stats(mode='blobs-per-file')
logger.info('repo stats: %s', stats)
if stats['total_size'] != len(RESTORED_DATA_EXPECTED):
Expand Down
5 changes: 5 additions & 0 deletions restic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from restic.internal import init as internal_init
from restic.internal import restore as internal_restore
from restic.internal import self_update as internal_self_update
from restic.internal import snapshots as internal_snapshots
from restic.internal import stats as internal_stats
from restic.internal import unlock as internal_unlock
from restic.internal import version as internal_version
Expand Down Expand Up @@ -48,6 +49,10 @@ def self_update():
return internal_self_update.run(_make_base_command())


def snapshots(*args, **kwargs):
return internal_snapshots.run(_make_base_command(), *args, **kwargs)


def stats(*args, **kwargs):
return internal_stats.run(_make_base_command(), *args, **kwargs)

Expand Down
12 changes: 12 additions & 0 deletions restic/internal/snapshots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json

from restic.internal import command_executor


def run(restic_base_command, group_by=None):
cmd = restic_base_command + ['snapshots']

if group_by:
cmd.extend(['--group-by', group_by])

return json.loads(command_executor.execute(cmd))
28 changes: 28 additions & 0 deletions restic/internal/snapshots_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
from unittest import mock

import restic
from restic.internal import snapshots

# Ignore suggestions to turn methods into functions.
# pylint: disable=R0201


class SelfUpdateTest(unittest.TestCase):

@mock.patch.object(snapshots.command_executor, 'execute')
def test_snapshots_simple(self, mock_execute):
mock_execute.return_value = '{}'

restic.snapshots()

mock_execute.assert_called_with(['restic', '--json', 'snapshots'])

@mock.patch.object(snapshots.command_executor, 'execute')
def test_snapshots_group_by_host(self, mock_execute):
mock_execute.return_value = '{}'

restic.snapshots(group_by='host')

mock_execute.assert_called_with(
['restic', '--json', 'snapshots', '--group-by', 'host'])

0 comments on commit 3ee0faf

Please sign in to comment.