Fixing script crashing for no connection for download backup

main
Jan Beníček 2024-06-25 06:17:10 +02:00
parent d1c900b4a0
commit 5015a556da
2 changed files with 26 additions and 14 deletions

View File

@ -1,19 +1,33 @@
from conf import get_config from conf import get_config
import pterodactylReader, fileDownloader, datetime, discordPoster, time, oldRemover import pterodactylReader, fileDownloader, datetime, discordPoster, time, oldRemover
def run(run_number: int):
try:
conf = get_config()
api_client = pterodactylReader.init_client(config=conf)
today_date = datetime.datetime.now()
conf = get_config() backups_dict = pterodactylReader.get_backups_list(api_client=api_client, server_id=conf.server_id)
api_client = pterodactylReader.init_client(config=conf) backup_uuid = pterodactylReader.get_last_backup_id(backups_dict)
today_date = datetime.datetime.now() backup_url = pterodactylReader.get_backup_url(api_client=api_client, server_id=conf.server_id, backup_id=backup_uuid)
backups_dict = pterodactylReader.get_backups_list(api_client=api_client, server_id=conf.server_id) print(f"Backup UUID of try #{run_number}: {backup_uuid}")
backup_uuid = pterodactylReader.get_last_backup_id(backups_dict) print(f"Backup URL of try #{run_number}: {backup_url}")
backup_url = pterodactylReader.get_backup_url(api_client=api_client, server_id=conf.server_id, backup_id=backup_uuid)
time.sleep(5)
backup_local_path = fileDownloader.create_dirs_and_download(backup_url=backup_url, date=today_date, base_path=conf.save_dir)
if conf.discord_enabled == 1: time.sleep(20)
discordPoster.send_url_to_discord(webhook_url=conf.discord_webhook, backup_url=f"{conf.main_domain}{backup_local_path}", datetim=today_date, backup_name=conf.discord_backupname) backup_local_path = fileDownloader.create_dirs_and_download(backup_url=backup_url, date=today_date, base_path=conf.save_dir)
if conf.backups_keep_days != 0: if conf.discord_enabled == 1:
oldRemover.remove_old_files(today_date=today_date, keep_days=conf.backups_keep_days, root_path=conf.save_dir) discordPoster.send_url_to_discord(webhook_url=conf.discord_webhook, backup_url=f"{conf.main_domain}{backup_local_path}", datetim=today_date, backup_name=conf.discord_backupname)
if conf.backups_keep_days != 0:
oldRemover.remove_old_files(today_date=today_date, keep_days=conf.backups_keep_days, root_path=conf.save_dir)
except Exception as e:
print(f"Error on try #{run_number}: {e}")
if run_number < 5:
run(run_number=(run_number + 1))
run(0)

View File

@ -17,8 +17,6 @@ def remove_old_files(today_date: datetime.datetime, keep_days: int, root_path: s
older_date = today_date - datetime.timedelta(days=keep_days) older_date = today_date - datetime.timedelta(days=keep_days)
last_date = today_date - datetime.timedelta(days=keep_days) last_date = today_date - datetime.timedelta(days=keep_days)
print(file_path_creator(date=older_date, default_path=root_path))
while older_date > (datetime.datetime.now() - datetime.timedelta(days=10 + keep_days)): while older_date > (datetime.datetime.now() - datetime.timedelta(days=10 + keep_days)):
older_date = older_date - datetime.timedelta(days=1) older_date = older_date - datetime.timedelta(days=1)