se cambiaron mamadas

This commit is contained in:
Kevin Muñoz 2024-02-15 16:00:34 -05:00
parent cb5d1d3f89
commit 601438644e
No known key found for this signature in database
GPG Key ID: 3CA0B9DF1BE7CE09
3 changed files with 58 additions and 4 deletions

View File

@ -3,10 +3,7 @@ MARIADB_USER=""
MARIADB_PASSWORD="" MARIADB_PASSWORD=""
MARIADB_DATABASE="" MARIADB_DATABASE=""
SQLITE_DATABASE="" SQLITE_DATABASE=""
SFTP_HOST="" SFTP_HOST="condornas"
SFTP_USER=""
SFTP_PASSWORD=""
SFTP_PATH="" SFTP_PATH=""
SFTP_PORT=""
TELEGRAM_BOT_TOKEN="" TELEGRAM_BOT_TOKEN=""
TELEGRAM_CHAT_ID="" TELEGRAM_CHAT_ID=""

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import hashlib import hashlib
import datetime import datetime

56
respaldossql.sh Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
# Source the .env file
source <(sed 's/#.*//g' ./.env)
# Set up variables from environment variables
MARIADB_HOST=${MARIADB_HOST:-"localhost"}
MARIADB_USER=${MARIADB_USER:-"root"}
MARIADB_PASSWORD=${MARIADB_PASSWORD:-"passwd"}
MARIADB_DATABASE=${MARIADB_DATABASE:-"DBName"}
SQLITE_DATABASE=${SQLITE_DATABASE:-"/Path/to/database"}
SFTP_HOST=${SFTP_HOST:-"localhost"}
SFTP_PATH=${SFTP_PATH:-"/Paht/to/sftp"}
TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN:-"TOKEN"}
TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID:-"ID_CHAT"}
# Generate backups
start_time=$(date +%s)
mariadb_backup_filename="globalists_mariadb_backup_$(date +%Y%m%d).sql.gz"
mariadb-dump -h "$MARIADB_HOST" -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE" | gzip > "$mariadb_backup_filename"
sqlite_backup_filename="globalists_sqlite_backup_$(date +%Y%m%d).sql.gz"
sqlite3 "$SQLITE_DATABASE" .dump | gzip > "$sqlite_backup_filename"
# Calculate SHA512 hash of backups
mariadb_hash=$(sha512sum "$mariadb_backup_filename" | awk '{ print $1 }')
sqlite_hash=$(sha512sum "$sqlite_backup_filename" | awk '{ print $1 }')
# Transfer backups to SFTP server
sftp "$SFTP_HOST"<< EOF > /dev/null
cd "$SFTP_PATH"
put "$mariadb_backup_filename"
put "$sqlite_backup_filename"
quit
EOF
# Delete local backup files
rm "$mariadb_backup_filename"
rm "$sqlite_backup_filename"
# Send message via Telegram
message="
** Respaldo completado! **
** Base de datos:**
* MariaDB: **$(echo $mariadb_backup_filename hash: $mariadb_hash)**
* SQLite: **$(echo $sqlite_backup_filename hash: $sqlite_hash)**
**⏱️ Tiempo de transferencia:** $(date -u -d "@$(( $(date +%s) - start_time ))" +'%T')
** Disponible en SFTP:** ($SFTP_PATH)
"
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" -d chat_id="$TELEGRAM_CHAT_ID" -d text="$message" > /dev/null