mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 09:45:28 +01:00
Remove schedule logic from backups.
This commit is contained in:
parent
4f55ffed0f
commit
c220c6d3d3
@ -111,5 +111,5 @@ class Management_Controller:
|
|||||||
return management_helper.get_backup_config(server_id)
|
return management_helper.get_backup_config(server_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None, auto_enabled: bool = True):
|
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None):
|
||||||
return management_helper.set_backup_config(server_id, backup_path, max_backups, auto_enabled)
|
return management_helper.set_backup_config(server_id, backup_path, max_backups)
|
||||||
|
@ -278,7 +278,7 @@ class helpers_management:
|
|||||||
return conf
|
return conf
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None, auto_enabled: bool = True):
|
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None):
|
||||||
logger.debug("Updating server {} backup config with {}".format(server_id, locals()))
|
logger.debug("Updating server {} backup config with {}".format(server_id, locals()))
|
||||||
try:
|
try:
|
||||||
row = Backups.select().where(Backups.server_id == server_id).join(Schedules).join(Servers)[0]
|
row = Backups.select().where(Backups.server_id == server_id).join(Schedules).join(Servers)[0]
|
||||||
@ -303,7 +303,6 @@ class helpers_management:
|
|||||||
new_row = True
|
new_row = True
|
||||||
if max_backups is not None:
|
if max_backups is not None:
|
||||||
conf['max_backups'] = max_backups
|
conf['max_backups'] = max_backups
|
||||||
schd['enabled'] = bool(auto_enabled)
|
|
||||||
if not new_row:
|
if not new_row:
|
||||||
with database.atomic():
|
with database.atomic():
|
||||||
if backup_path is not None:
|
if backup_path is not None:
|
||||||
@ -311,15 +310,12 @@ class helpers_management:
|
|||||||
else:
|
else:
|
||||||
u1 = 0
|
u1 = 0
|
||||||
u2 = Backups.update(conf).where(Backups.server_id == server_id).execute()
|
u2 = Backups.update(conf).where(Backups.server_id == server_id).execute()
|
||||||
u3 = Schedules.update(schd).where(Schedules.schedule_id == row.schedule_id).execute()
|
|
||||||
logger.debug("Updating existing backup record. {}+{}+{} rows affected".format(u1, u2, u3))
|
logger.debug("Updating existing backup record. {}+{}+{} rows affected".format(u1, u2, u3))
|
||||||
else:
|
else:
|
||||||
with database.atomic():
|
with database.atomic():
|
||||||
conf["server_id"] = server_id
|
conf["server_id"] = server_id
|
||||||
if backup_path is not None:
|
if backup_path is not None:
|
||||||
u = Servers.update(backup_path=backup_path).where(Servers.server_id == server_id)
|
u = Servers.update(backup_path=backup_path).where(Servers.server_id == server_id)
|
||||||
s = Schedules.create(**schd)
|
|
||||||
conf['schedule_id'] = s.schedule_id
|
|
||||||
b = Backups.create(**conf)
|
b = Backups.create(**conf)
|
||||||
logger.debug("Creating new backup record.")
|
logger.debug("Creating new backup record.")
|
||||||
|
|
||||||
|
@ -801,10 +801,6 @@ class PanelHandler(BaseHandler):
|
|||||||
else:
|
else:
|
||||||
backup_path = server_obj.backup_path
|
backup_path = server_obj.backup_path
|
||||||
max_backups = bleach.clean(self.get_argument('max_backups', None))
|
max_backups = bleach.clean(self.get_argument('max_backups', None))
|
||||||
try:
|
|
||||||
enabled = int(float(bleach.clean(self.get_argument('auto_enabled'), '0')))
|
|
||||||
except Exception as e:
|
|
||||||
enabled = '0'
|
|
||||||
|
|
||||||
if not permissions['Backup'] in user_perms:
|
if not permissions['Backup'] in user_perms:
|
||||||
if not exec_user['superuser']:
|
if not exec_user['superuser']:
|
||||||
@ -830,7 +826,7 @@ class PanelHandler(BaseHandler):
|
|||||||
server_obj = self.controller.servers.get_server_obj(server_id)
|
server_obj = self.controller.servers.get_server_obj(server_id)
|
||||||
server_obj.backup_path = backup_path
|
server_obj.backup_path = backup_path
|
||||||
self.controller.servers.update_server(server_obj)
|
self.controller.servers.update_server(server_obj)
|
||||||
self.controller.management.set_backup_config(server_id, max_backups=max_backups, auto_enabled=True)
|
self.controller.management.set_backup_config(server_id, max_backups=max_backups)
|
||||||
|
|
||||||
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
self.controller.management.add_to_audit_log(exec_user['user_id'],
|
||||||
"Edited server {}: updated backups".format(server_id),
|
"Edited server {}: updated backups".format(server_id),
|
||||||
|
@ -56,16 +56,6 @@
|
|||||||
<input type="text" class="form-control" name="max_backups" id="max_backups" value="{{ data['backup_config']['max_backups'] }}" placeholder="{{ translate('serverBackups', 'maxBackups', data['lang']) }}" >
|
<input type="text" class="form-control" name="max_backups" id="max_backups" value="{{ data['backup_config']['max_backups'] }}" placeholder="{{ translate('serverBackups', 'maxBackups', data['lang']) }}" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="superuser" class="form-check-label ml-4 mb-4">
|
|
||||||
{% if data['backup_config']['auto_enabled'] %}
|
|
||||||
<input type="checkbox" class="form-check-input" id="auto_enabled" name="auto_enabled" checked="" value="1" >{{ translate('serverBackups', 'backupAtMidnight', data['lang']) }}
|
|
||||||
{% else %}
|
|
||||||
<input type="checkbox" class="form-check-input" id="auto_enabled" name="auto_enabled" value="1" >{{ translate('serverBackups', 'backupAtMidnight', data['lang']) }}
|
|
||||||
{% end %}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success mr-2">{{ translate('serverBackups', 'save', data['lang']) }}</button>
|
<button type="submit" class="btn btn-success mr-2">{{ translate('serverBackups', 'save', data['lang']) }}</button>
|
||||||
<button type="reset" class="btn btn-light">{{ translate('serverBackups', 'cancel', data['lang']) }}</button>
|
<button type="reset" class="btn btn-light">{{ translate('serverBackups', 'cancel', data['lang']) }}</button>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user