Add check_success.py

This commit is contained in:
augustin64 2025-03-19 17:21:33 +01:00
parent 0bb783aca4
commit 7cd6eb8821
2 changed files with 37 additions and 1 deletions

34
src/check_success.py Normal file
View File

@ -0,0 +1,34 @@
from datetime import datetime
import requests
import os
import config
def raiseWebhook(message, file=None):
data = {
"username": "Backup script",
"embeds":
[{
"title": "Erreur lors de la sauvegarde",
"description": message,
"color": color_red,
"fields": []
}]
}
if file is not None:
data[files]={"file": open(file, "rb")}
requests.post(config.ERROR_WEBHOOK, json=data)
with open("latest-success", "r") as f:
latest_success = f.read().strip()
today = datetime.today().strftime('%Y-%m-%d')
if latest_success != today:
log_file = None
if os.path.exists(f"logs/{today}.txt"):
log_file = f"logs/{today}.txt"
raiseWebhook(f"No successful backup today", file=log_file)

View File

@ -7,4 +7,6 @@ REMOTE_LOCATION = "192.168.1.5"
REMOTE_USER = "myuser"
BACKUP_MAP = [
("/home/remote/MyData", "backup-it-here") # myuser@192.168.1.5:/home/remote/MyData will be backed up to /mnt/{backup-date and "latest"}/backup-it-here
]
]
ERROR_WEBHOOK = "https://discord.com/api/webhooks/...."