-
-
Save guweigang/5557076256d5834f8edf 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 | |
# mysql 自动备份 | |
TIMESTAMP=$(date +"%Y%m%d") | |
BACKUP_DIR="/usr/local/mysql/backup" | |
MYSQL_USER="root" | |
MYSQL=/usr/local/mysql/bin/mysql | |
MYSQL_PASSWORD="root" | |
MYSQLDUMP=/usr/local/mysql/bin/mysqldump | |
mkdir -p "$BACKUP_DIR/$TIMESTAMP" | |
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql|test)"` | |
for db in $databases; do | |
FILE=$BACKUP_DIR/$TIMESTAMP/$db.sql | |
echo -n "$db > $FILE ..." | |
if [ ! -f $FILE ]; then | |
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db > $FILE | |
echo -e " \033[32;49;2mdone!\033[39;49;0m" | |
else | |
echo -e " \033[31;49;2malready exists!\033[39;49;0m" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment