Backup scheduling fixes in case of an initial backup

Mon, 29 Jan 2018 14:32:27 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 29 Jan 2018 14:32:27 +0000
changeset 96
de8ac6c470d8
parent 95
41bd7025532f
child 97
96d5adbe0205

Backup scheduling fixes in case of an initial backup

borgend/backup.py file | annotate | diff | comparison | revisions
--- a/borgend/backup.py	Mon Jan 29 14:17:03 2018 +0000
+++ b/borgend/backup.py	Mon Jan 29 14:32:27 2018 +0000
@@ -365,6 +365,9 @@
                     self.last_create_when=monotonic
             else:
                 self.logger.info('borg info: Could not discover a previous backup')
+                with self._cond:
+                    self.last_create_finished=-1
+                    self.last_create_when=None
 
     def __do_launch(self, op, archive_or_repository,
                     common_params, op_params, paths=[]):
@@ -564,7 +567,7 @@
         if self.backup_interval==0:
             # Manual backup
             return None
-        elif not self.last_create_finished:
+        elif self.last_create_finished==None:
             # Don't know when last create finished: try to get it from
             # archive list.
             if not self.errors.ok() and self.retry_interval==0:
@@ -578,20 +581,21 @@
                 # Nothing has been attempted: run immediately
                 tm=dreamtime.MonotonicTime.now()
             return Operation(Operation.LIST, tm, reason='initial')
-        elif not self.errors.ok() or not self.last_create_finished:
-            # Retry create in case of errors
-
-            if not self.errors.ok():
-                reason='retry'
-            else:
-                reason='initial'
-
+        elif self.errors.ok() and self.last_create_finished<0:
+            # No backup exists; perform initial backup
+            tm=dreamtime.MonotonicTime.now()
+            return Operation(Operation.CREATE, tm, reason='initial')
+        elif not self.errors.ok():
+            # Retry create in case of errors unless retry has been disabled
             if self.retry_interval==0:
                 return None
             else:
-                basetime = self.last_create_finished or time.monotonic()
+                if self.last_create_finished<0:
+                    basetime=time.monotonic()
+                else:
+                    basetime=self.last_create_finished
                 tm=dreamtime.MonotonicTime(basetime+self.retry_interval)
-                return Operation(Operation.CREATE, tm, reason=reason)
+                return Operation(Operation.CREATE, tm, reason='retry')
         else:
             # All ok - run create at standard backup interval
             tm=self.timeclass.from_monotonic(self.last_create_when+self.backup_interval)

mercurial