Created
June 15, 2014 15:45
-
-
Save dominikzogg/3d13fbb7544fd988e671 to your computer and use it in GitHub Desktop.
mysqlbackup
This file contains hidden or 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 | |
TARGET=/backups/mysqldatabases | |
IGNORE="mysql|information_schema|performance_schema|test" | |
CONF=/etc/mysql/debian.cnf | |
HOST=localhost | |
PORT=3306 | |
USER=root | |
PASSWORD= | |
if [ ! -r $CONF ]; then /usr/bin/logger "$0 - auf $CONF konnte nicht zugegriffen werden"; exit 1; fi | |
if [ ! -d $TARGET ] || [ ! -w $TARGET ]; then /usr/bin/logger "$0 - Backup-Verzeichnis nicht beschreibbar"; exit 1; fi | |
DBS="$(/usr/bin/mysql --defaults-extra-file=$CONF --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD -Bse 'show databases' | /bin/grep -Ev $IGNORE)" | |
NOW=$(date +"%Y-%m-%d") | |
for DB in $DBS; do | |
/usr/bin/mysqldump --defaults-extra-file=$CONF --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD --skip-extended-insert --skip-comments $DB > $TARGET/$DB.sql | |
done | |
if [ -x /usr/bin/git ] && [ -d ${TARGET}/.git ]; then | |
cd $TARGET | |
/usr/bin/git add -A | |
/usr/bin/git commit -m "$NOW" | |
else | |
/usr/bin/logger "$0 - git nicht verfuegbar oder Backup-Ziel nicht unter Versionskontrolle" | |
fi | |
/usr/bin/logger "$0 - Backup von $NOW erfolgreich durchgefuehrt" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment