This commit is contained in:
2025-09-09 00:10:53 +03:00
parent 38f2a05107
commit 204fc092d7
239 changed files with 22447 additions and 9536 deletions

37
backup.py Normal file
View File

@@ -0,0 +1,37 @@
import os
import requests
from datetime import datetime
from zipfile import ZipFile, ZIP_DEFLATED
from dotenv import load_dotenv
# Загрузка переменных из .env
load_dotenv()
TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN')
CHAT_ID = os.getenv('CHAT_ID')
DB_PATH = os.path.join(os.getenv('DB_PATH'), 'database.sqlite')
def send_document(filename, caption):
url = f'https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendDocument'
with open(filename, 'rb') as f:
response = requests.post(
url,
data={'chat_id': CHAT_ID, 'caption': caption},
files={'document': f}
)
print(response.json())
def main():
if not TELEGRAM_TOKEN or not CHAT_ID or not DB_PATH:
print("Помилка: TELEGRAM_TOKEN, CHAT_ID або DB_PATH не задано в .env.")
return
if os.path.exists(DB_PATH):
timestamp = datetime.now().strftime("%d.%m.%Y %H:%M")
caption = f"Backup Sheep Service DB - {timestamp}"
send_document(DB_PATH, caption)
else:
print("ZIP file not created")
if __name__ == "__main__":
main()