Add check_success.py
This commit is contained in:
parent
0bb783aca4
commit
7cd6eb8821
34
src/check_success.py
Normal file
34
src/check_success.py
Normal 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)
|
@ -7,4 +7,6 @@ REMOTE_LOCATION = "192.168.1.5"
|
|||||||
REMOTE_USER = "myuser"
|
REMOTE_USER = "myuser"
|
||||||
BACKUP_MAP = [
|
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
|
("/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/...."
|
Loading…
x
Reference in New Issue
Block a user