diff --git a/unifi_protect_backup/missing_event_checker.py b/unifi_protect_backup/missing_event_checker.py index 24b5f63..6c245f4 100644 --- a/unifi_protect_backup/missing_event_checker.py +++ b/unifi_protect_backup/missing_event_checker.py @@ -77,9 +77,11 @@ async def _get_missing_events(self) -> AsyncIterator[Event]: if not events_chunk: break # There were no events to backup - assert events_chunk[-1].end is not None - start_time = events_chunk[-1].end - unifi_events = {event.id: event for event in events_chunk} + # Filter out on-going events + unifi_events = {event.id: event for event in events_chunk if event.end is not None} + + # Next chunks start time should be the end of the oldest complete event in the current chunk + start_time = max([event.end for event in unifi_events.values()]) # Get list of events that have been backed up from the database