Bug10853m (#1096)
* autobackup; add delay after wake from sleep/hibernate to allow time for system to settle. Fixes #10953 * Autobackup only if new commits since last autobackup in session
This commit is contained in:
@@ -537,7 +537,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.transaction = None
|
self.transaction = None
|
||||||
self.abort_possible = False
|
self.abort_possible = False
|
||||||
self._bm_changes = 0
|
self._bm_changes = 0
|
||||||
self.has_changed = False
|
self.has_changed = 0 # Also gives commits since startup
|
||||||
self.surname_list = []
|
self.surname_list = []
|
||||||
self.genderStats = GenderStats() # can pass in loaded stats as dict
|
self.genderStats = GenderStats() # can pass in loaded stats as dict
|
||||||
self.owner = Researcher()
|
self.owner = Researcher()
|
||||||
|
@@ -1779,7 +1779,9 @@ class GrampsPreferences(ConfigureDialog):
|
|||||||
formats = [_("Never"),
|
formats = [_("Never"),
|
||||||
_("Every 15 minutes"),
|
_("Every 15 minutes"),
|
||||||
_("Every 30 minutes"),
|
_("Every 30 minutes"),
|
||||||
_("Every hour")]
|
_("Every hour"),
|
||||||
|
_("Every 12 hours"),
|
||||||
|
_("Every day")]
|
||||||
list(map(obox.append_text, formats))
|
list(map(obox.append_text, formats))
|
||||||
active = config.get('database.autobackup')
|
active = config.get('database.autobackup')
|
||||||
obox.set_active(active)
|
obox.set_active(active)
|
||||||
|
@@ -458,6 +458,10 @@ class DisplayState(Callback):
|
|||||||
minutes = 30
|
minutes = 30
|
||||||
elif interval == 3:
|
elif interval == 3:
|
||||||
minutes = 60
|
minutes = 60
|
||||||
|
elif interval == 4:
|
||||||
|
minutes = 720
|
||||||
|
elif interval == 5:
|
||||||
|
minutes = 1440
|
||||||
if interval > 0:
|
if interval > 0:
|
||||||
self.backup_timer = GLib.timeout_add_seconds(
|
self.backup_timer = GLib.timeout_add_seconds(
|
||||||
minutes*60, self.__emit_autobackup)
|
minutes*60, self.__emit_autobackup)
|
||||||
|
@@ -56,6 +56,7 @@ LOG = logging.getLogger(".")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -181,6 +182,9 @@ class ViewManager(CLIManager):
|
|||||||
self.views = None
|
self.views = None
|
||||||
self.current_views = [] # The current view in each category
|
self.current_views = [] # The current view in each category
|
||||||
self.view_changing = False
|
self.view_changing = False
|
||||||
|
self.autobackup_time = time.time() # time of start or last autobackup
|
||||||
|
self.delay_timer = None # autobackup delay timer for after wakeup
|
||||||
|
self.prev_has_changed = 0 # db commit count at autobackup time
|
||||||
|
|
||||||
self.show_navigator = config.get('interface.view')
|
self.show_navigator = config.get('interface.view')
|
||||||
self.show_toolbar = config.get('interface.toolbar-on')
|
self.show_toolbar = config.get('interface.toolbar-on')
|
||||||
@@ -1183,7 +1187,33 @@ class ViewManager(CLIManager):
|
|||||||
"""
|
"""
|
||||||
Backup the current family tree.
|
Backup the current family tree.
|
||||||
"""
|
"""
|
||||||
if self.dbstate.db.is_open() and self.dbstate.db.has_changed:
|
if self.delay_timer is not None:
|
||||||
|
GLib.source_remove(self.delay_timer)
|
||||||
|
self.delay_timer = None
|
||||||
|
interval = config.get('database.autobackup')
|
||||||
|
if interval == 1:
|
||||||
|
seconds = 900. # 15min *60
|
||||||
|
elif interval == 2:
|
||||||
|
seconds = 1800. # 30min *60
|
||||||
|
elif interval == 3:
|
||||||
|
seconds = 3600. # 60min *60
|
||||||
|
elif interval == 4:
|
||||||
|
seconds = 43200. # (12 hours) 720min *60
|
||||||
|
elif interval == 5:
|
||||||
|
seconds = 86400. # (24 hours) 1440min *60
|
||||||
|
now = time.time()
|
||||||
|
if interval and now > self.autobackup_time + seconds + 300.:
|
||||||
|
# we have been delayed by more than 5 minutes
|
||||||
|
# so we have probably been awakened from sleep/hibernate
|
||||||
|
# we should delay a bit more to let the system settle
|
||||||
|
self.delay_timer = GLib.timeout_add_seconds(300, self.autobackup)
|
||||||
|
self.autobackup_time = now
|
||||||
|
return
|
||||||
|
self.autobackup_time = now
|
||||||
|
# Only backup if more commits since last time
|
||||||
|
if(self.dbstate.db.is_open() and
|
||||||
|
self.dbstate.db.has_changed > self.prev_has_changed):
|
||||||
|
self.prev_has_changed = self.dbstate.db.has_changed
|
||||||
self.uistate.set_busy_cursor(True)
|
self.uistate.set_busy_cursor(True)
|
||||||
self.uistate.progress.show()
|
self.uistate.progress.show()
|
||||||
self.uistate.push_message(self.dbstate, _("Autobackup..."))
|
self.uistate.push_message(self.dbstate, _("Autobackup..."))
|
||||||
|
@@ -276,7 +276,7 @@ class DBAPI(DbGeneric):
|
|||||||
self.undodb.commit(txn, msg)
|
self.undodb.commit(txn, msg)
|
||||||
self._after_commit(txn)
|
self._after_commit(txn)
|
||||||
txn.clear()
|
txn.clear()
|
||||||
self.has_changed = True
|
self.has_changed += 1 # Also gives commits since startup
|
||||||
|
|
||||||
def transaction_abort(self, txn):
|
def transaction_abort(self, txn):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user