Created
January 22, 2015 17:43
-
-
Save italoveloso/b64f05865bb78919f492 to your computer and use it in GitHub Desktop.
Backup MySQL
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 | |
TIMESTAMP=$(date +"%F") | |
BACKUP_DIR="/backups/$TIMESTAMP" | |
MYSQL_USER="user_DB" | |
MYSQL=/usr/bin/mysql | |
MYSQL_PASSWORD="password_DB" | |
MYSQLDUMP=/usr/bin/mysqldump | |
mkdir -p "$BACKUP_DIR/mysql" | |
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"` | |
for db in $databases; do | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment