Skip to content

Commit c95a177

Browse files
committed
create mtc db backup after every set
1 parent 02bfb3b commit c95a177

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

mytoncore/mytoncore.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,23 @@ def CheckConfigFile(self, fift, liteClient):
118118
self.dbFile = mconfig_path
119119
self.Refresh()
120120
elif not os.path.isfile(backup_path) or time.time() - os.path.getmtime(backup_path) > 3600:
121-
self.local.add_log("Create backup config file", "info")
122-
backup_tmp_path = backup_path + '.tmp'
123-
subprocess.run(["cp", mconfig_path, backup_tmp_path])
124-
try:
125-
with open(backup_tmp_path, "r") as file:
126-
json.load(file)
127-
os.rename(backup_tmp_path, backup_path) # atomic opetation
128-
except:
129-
self.local.add_log("Could not update backup, backup_tmp file is broken", "warning")
130-
os.remove(backup_tmp_path)
121+
self.local.try_function(self.create_self_db_backup)
131122
#end define
132123

124+
def create_self_db_backup(self):
125+
self.local.add_log("Create backup config file", "info")
126+
mconfig_path = self.local.buffer.db_path
127+
backup_path = mconfig_path + ".backup"
128+
backup_tmp_path = backup_path + '.tmp'
129+
subprocess.run(["cp", mconfig_path, backup_tmp_path])
130+
try:
131+
with open(backup_tmp_path, "r") as file:
132+
json.load(file)
133+
os.rename(backup_tmp_path, backup_path) # atomic opetation
134+
except:
135+
self.local.add_log("Could not update backup, backup_tmp file is broken", "warning")
136+
os.remove(backup_tmp_path)
137+
133138
def GetVarFromWorkerOutput(self, text, search):
134139
if ':' not in search:
135140
search += ':'
@@ -3044,6 +3049,7 @@ def SetSettings(self, name, data):
30443049
except: pass
30453050
self.local.db[name] = data
30463051
self.local.save()
3052+
self.create_self_db_backup()
30473053
#end define
30483054

30493055
def migrate_to_modes(self):

0 commit comments

Comments
 (0)