Recovery¶
Normal run¶
First, open a new database file with a deterministically generated name before beginning backup (e.g. ~database).
Now, for every mail, we write the details of the mail to the temporary database file before opening, saving, and closing the mailfile. When everything is done, we rename the old database-file (e.g. database.old), rename the new database-file (~database to database), and then remove the old database-file.
Detection¶
If gmailcc exits prematurely, the ~database-file will tell gmailcc on the next run that the previous session was canceled prematurely.
Recovery¶
First, we cannot know if the last mail in the temporary database-file was completed succesfully. In fact, it was most probably not, so we remove that one from the file and, if it exists, remove the file of it.
All mails in the temporary database-file are now known to be correct. We can load it just like any other database-file. Upon execution gmailcc will detect new mails because the count will be different.