Skip to content

Commit 5ac0501

Browse files
committed
add auto backups
1 parent 5a87df0 commit 5ac0501

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Setting:
5858
'debug': Setting(None, False, 'Debug mtc console mode. Prints Traceback on errors'),
5959
'subscribe_tg_channel': Setting('validator', False, 'Disables warning about subscribing to the `TON STATUS` channel'),
6060
'BotToken': Setting('alert-bot', None, 'Alerting Telegram bot token'),
61-
'ChatId': Setting('alert-bot', None, 'Alerting Telegram chat id')
61+
'ChatId': Setting('alert-bot', None, 'Alerting Telegram chat id'),
62+
'auto_backup': Setting('validator', True, 'Make backup of validator every election'),
63+
'auto_backup_path': Setting('validator', '/tmp/mytoncore/backups/', 'Path to store backups'),
6264
}
6365

6466

mytoncore/mytoncore.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ def ElectionEntry(self, args=None):
14551455
self.local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime))
14561456

14571457
self.clear_tmp()
1458+
self.make_backup(startWorkTime)
14581459

14591460
#end define
14601461

@@ -1471,6 +1472,18 @@ def clear_tmp(self):
14711472

14721473
self.local.add_log(f"Removed {count} old files from tmp dir for {int(time.time() - start)} seconds", "info")
14731474

1475+
def make_backup(self, election_id: str):
1476+
if not self.local.db.get("auto_backup"):
1477+
return
1478+
from mytonctrl.mytonctrl import create_backup
1479+
args = []
1480+
name = f"/mytonctrl_backup_elid{election_id}.zip"
1481+
if self.local.db.get("auto_backup_path"):
1482+
args.append(self.local.db.get("auto_backup_path") + name)
1483+
else:
1484+
args.append(self.tempDir + "/backups" + name)
1485+
create_backup(self.local, self, args + ['-y'])
1486+
14741487
def GetValidatorKeyByTime(self, startWorkTime, endWorkTime):
14751488
self.local.add_log("start GetValidatorKeyByTime function", "debug")
14761489
# Check temp key

0 commit comments

Comments
 (0)