From eb9f54b296b8a2c0776babddff5cfe2e2febea3b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 20 May 2021 12:38:57 +0200 Subject: syncoid autosuspend: improve log out put and timer accuracy --- roles/storage/zfs/syncoid/templates/autosuspend.py.j2 | 13 +++++++++++-- roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 | 1 + roles/storage/zfs/syncoid/templates/pull.timer.j2 | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'roles/storage') diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 index 3dd893b2..58752328 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 @@ -56,7 +56,7 @@ class AutoSuspender(object): try: return datetime.datetime.fromtimestamp(int(props['NextElapseUSecRealtime']) / 1000000) except ValueError: - return datetime.datetime.now() + return None def check(self): result = True @@ -71,6 +71,11 @@ class AutoSuspender(object): timers = self._get_syncoid_timers() for timer in timers: next = self._get_timer_next_elapse(timer[1]) + if next == None: + print(" [NO] the next elapse of timer '%s' is invalid, assuming the unit is currently active" % (timer[0])) + result = False + continue + until = next - datetime.datetime.now() if(until < datetime.timedelta(minutes=10)): print(" [NO] timer '%s' elapses in less then 10 Minutes -> %s (%s)" % (timer[0], next, until)) @@ -85,7 +90,11 @@ class AutoSuspender(object): if not manager.CanSuspend(): print("suspending is not possible!") return - manager.Suspend(False) + try: + manager.Suspend(False) + except dbus.exceptions.DBusException: + print("ERR: %s" % error) + return None if __name__ == "__main__": diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 index 44413114..fee94905 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 @@ -3,6 +3,7 @@ Description=automatic system suspender for syncoid-based backups [Timer] OnCalendar=*-*-* *:04/10:30 +AccuracySec=10s [Install] WantedBy=timers.target diff --git a/roles/storage/zfs/syncoid/templates/pull.timer.j2 b/roles/storage/zfs/syncoid/templates/pull.timer.j2 index cc252854..bcbb1a28 100644 --- a/roles/storage/zfs/syncoid/templates/pull.timer.j2 +++ b/roles/storage/zfs/syncoid/templates/pull.timer.j2 @@ -3,6 +3,7 @@ Description=syncoid-based backup for {{ item.key }} [Timer] OnCalendar={{ item.value.periodic.schedule }} +AccuracySec=10s WakeSystem={{ zfs_syncoid_autosuspend | ternary('true', 'false') }} [Install] -- cgit v1.2.3