From 84190584b8b48f4c7db9db6f655a35490c6d4553 Mon Sep 17 00:00:00 2001 From: ngosang Date: Thu, 2 Feb 2023 20:02:12 +0100 Subject: [PATCH] Fix snapshot time parsing for old versions of Restic. Resolves #1 --- restic-exporter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/restic-exporter.py b/restic-exporter.py index 7636c87..9715a51 100644 --- a/restic-exporter.py +++ b/restic-exporter.py @@ -98,7 +98,13 @@ class ResticCollector(object): stats = self.get_stats(snap['id']) time_parsed = re.sub(r'\.[^+-]+', '', snap['time']) - timestamp = time.mktime(datetime.datetime.strptime(time_parsed, "%Y-%m-%dT%H:%M:%S%z").timetuple()) + if len(time_parsed) > 19: + # restic 14: '2023-01-12T06:59:33.1576588+01:00' -> '2023-01-12T06:59:33+01:00' + time_format = "%Y-%m-%dT%H:%M:%S%z" + else: + # restic 12: '2023-02-01T14:14:19.30760523Z' -> '2023-02-01T14:14:19' + time_format = "%Y-%m-%dT%H:%M:%S" + timestamp = time.mktime(datetime.datetime.strptime(time_parsed, time_format).timetuple()) snapshots_total = 0 for snap2 in all_snapshots: