Skip to content

Commit

Permalink
Handle case where there are no snapshots yet (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
brechtm committed Feb 8, 2024
1 parent db6a8e8 commit cf53a75
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions thriftybackup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import plistlib
import re

from contextlib import suppress
from datetime import datetime, timedelta
from functools import cached_property
from itertools import chain
Expand Down Expand Up @@ -152,9 +153,10 @@ def get_last_snapshot(self):
while True:
output = self._run([DISKUTIL, 'apfs', 'listSnapshots', '-plist', device],
echo=self.echo, check=True, capture_output=True).stdout
snapshot = plistlib.loads(output)['Snapshots'][-1]['SnapshotName']
if datetime.now() - snapshot_datetime(snapshot) < timedelta(hours=1):
break
with suppress(IndexError):
snapshot = plistlib.loads(output)['Snapshots'][-1]['SnapshotName']
if datetime.now() - snapshot_datetime(snapshot) < timedelta(hours=1):
break
self._run([TMUTIL, 'localsnapshot'], echo=self.echo, check=True)
return device, snapshot

Expand Down

0 comments on commit cf53a75

Please sign in to comment.