Created
February 1, 2017 21:20
-
-
Save Thijzer/0aa82f8b226e79d9dd45b251092bdfbb 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 | |
if [ $# -eq 0 ] || [ $# -eq 1 ] || [ $# -eq 2 ] | |
then | |
echo "usage : mysql_backup.sh user passw backup destination" | |
exit 1 | |
fi | |
umask 007 | |
renice 10 $$ >/dev/null | |
MYSQL_USER=$1 | |
MYSQL_PASSWORD=$2 | |
BASE_PATH=$3 | |
TIMESTAMP=$(date +"%F") | |
BACKUP_DIR="/$BASE_PATH/mysql/$TIMESTAMP" | |
MYSQL=/usr/bin/mysql | |
MYSQLDUMP=/usr/bin/mysqldump | |
mkdir -p "$BACKUP_DIR" | |
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` | |
for db in $databases; do | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment