Created
August 28, 2019 20:11
-
-
Save TFWIsaac/7fd9918756ab3bc562f2850f30ba0344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOLD_DAYS=14 | |
TIMESTAMP=$(date +"%F") | |
BACKUP_DIR="/opt/sql-backup" | |
MYSQL_USR="xxx" | |
MYSQL_PWD="xxx" | |
DATENBANK="xxx" | |
HOST="xxx" | |
telegrambot="xxx" | |
telegramchatid="xxx" | |
url="https://api.telegram.org/bot"$telegrambot"/sendMessage" | |
date="$(date "+%F %T")" | |
mkdir -p "$BACKUP_DIR/$TIMESTAMP" | |
mysqldump --force --opt --user=$MYSQL_USR -h $HOST -p$MYSQL_PWD --databases $DATENBANK | gzip > "$BACKUP_DIR/$TIMESTAMP/$DATENBANK.gz" | |
if [ "$?" -eq 0 ]; then | |
find $BACKUP_DIR -maxdepth 1 -mindepth 1 -type d -mtime +$HOLD_DAYS -exec rm -rf {} \; | |
message="SQL-Datenbank Dump erfolgreich fertiggestellt! "$date | |
curl -s -d "chat_id="$telegramchatid"&text=$message" $url > /dev/null 2>&1 | |
else | |
message="SQL-Datenbank Dump ACHTUNG Fehler festgestellt! "$date | |
curl -s -d "chat_id="$telegramchatid"&text=$message" $url > /dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment