poprawka w formacie loga auto backupu

This commit is contained in:
Mateusz Gruszczyński 2025-03-09 15:09:10 +01:00
parent ec364aac0c
commit ef31984144

18
app.py
View File

@ -211,17 +211,15 @@ def automated_backup_for_host(host):
raise Exception(f"Daemon GET error: {resp.status_code} - {resp.text}")
data = resp.json()
content = data.get("hosts", "")
# Wyodrębnienie adresu IP z daemon_url (bez portu)
daemon_str = host.daemon_url.split("://")[-1]
daemon_ip = daemon_str.split(":")[0]
backup_info = f"[BACKUP] Automatic backup created for server {host.hostname} (Daemon IP: {daemon_ip})"
# Używamy format_host, aby log był zgodny z deploy
backup_info = f"[BACKUP] Automatic backup created for server {format_host(host)}"
else:
if host.type == 'mikrotik':
ssh = open_ssh_connection(host)
stdin, stdout, stderr = ssh.exec_command("/ip dns static export")
content = stdout.read().decode('utf-8')
ssh.close()
backup_info = f"[BACKUP] Automatic backup created for server {host.hostname}"
backup_info = f"[BACKUP] Automatic backup created for server {format_host(host)}"
else:
ssh = open_ssh_connection(host)
sftp = ssh.open_sftp()
@ -229,13 +227,13 @@ def automated_backup_for_host(host):
content = remote_file.read().decode('utf-8')
sftp.close()
ssh.close()
backup_info = f"[BACKUP] Automatic backup created for server {host.hostname}"
backup_info = f"[BACKUP] Automatic backup created for server {format_host(host)}"
backup = Backup(
user_id=host.user_id,
host_id=host.id,
content=content,
description=f'Backup from server {host.hostname} at {datetime.now(timezone.utc).isoformat()}'
description=f'Backup from server {format_host(host)} at {datetime.now(timezone.utc).isoformat()}'
)
db.session.add(backup)
db.session.commit()
@ -244,9 +242,9 @@ def automated_backup_for_host(host):
db.session.add(log_entry)
db.session.commit()
print(f'Automated backup for server {host.hostname} created successfully.')
print(f'Automated backup for server {format_host(host)} created successfully.')
except Exception as e:
print(f'Error creating automated backup for server {host.hostname}: {str(e)}')
print(f'Error creating automated backup for server {format_host(host)}: {str(e)}')
def automated_backups():
with app.app_context():
@ -1650,7 +1648,7 @@ def server_info(id):
except Exception as e:
return {"error": str(e)}, 500
else:
return {"error": "This server does not use daemon."}, 400
return {"error": "This server do not use daemon."}, 400
@app.errorhandler(404)
def page_not_found(error):