Add max_tries param
This commit is contained in:
parent
9264b837c8
commit
346773f790
pwnagotchi
@ -28,6 +28,7 @@ main:
|
|||||||
auto-backup:
|
auto-backup:
|
||||||
enabled: false
|
enabled: false
|
||||||
interval: 1 # every day
|
interval: 1 # every day
|
||||||
|
max_tries: 0 # 0=infinity
|
||||||
files:
|
files:
|
||||||
- /root/brain.nn
|
- /root/brain.nn
|
||||||
- /root/brain.json
|
- /root/brain.json
|
||||||
|
@ -13,20 +13,14 @@ class AutoBackup(plugins.Plugin):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
|
self.tries = 0
|
||||||
self.status = StatusFile('/root/.auto-backup')
|
self.status = StatusFile('/root/.auto-backup')
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
if 'files' not in self.options or ('files' in self.options and self.options['files'] is None):
|
for opt in ['files', 'interval', 'commands', 'max_tries']:
|
||||||
logging.error("AUTO-BACKUP: No files to backup.")
|
if opt not in self.options or (opt in self.options and self.options[opt] is None):
|
||||||
return
|
logging.error(f"AUTO-BACKUP: Option {opt} is not set.")
|
||||||
|
return
|
||||||
if 'interval' not in self.options or ('interval' in self.options and self.options['interval'] is None):
|
|
||||||
logging.error("AUTO-BACKUP: Interval is not set.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if 'commands' not in self.options or ('commands' in self.options and self.options['commands'] is None):
|
|
||||||
logging.error("AUTO-BACKUP: No commands given.")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.ready = True
|
self.ready = True
|
||||||
logging.info("AUTO-BACKUP: Successfully loaded.")
|
logging.info("AUTO-BACKUP: Successfully loaded.")
|
||||||
@ -35,6 +29,9 @@ class AutoBackup(plugins.Plugin):
|
|||||||
if not self.ready:
|
if not self.ready:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.options['max_tries'] and self.tries >= self.options['max_tries']:
|
||||||
|
return
|
||||||
|
|
||||||
if self.status.newer_then_days(self.options['interval']):
|
if self.status.newer_then_days(self.options['interval']):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -62,6 +59,7 @@ class AutoBackup(plugins.Plugin):
|
|||||||
display.update()
|
display.update()
|
||||||
self.status.update()
|
self.status.update()
|
||||||
except OSError as os_e:
|
except OSError as os_e:
|
||||||
|
self.tries += 1
|
||||||
logging.info(f"AUTO-BACKUP: Error: {os_e}")
|
logging.info(f"AUTO-BACKUP: Error: {os_e}")
|
||||||
display.set('status', 'Backup failed!')
|
display.set('status', 'Backup failed!')
|
||||||
display.update()
|
display.update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user