Last active
March 1, 2016 06:49
-
-
Save ls0f/c424774c6a51c6ed6748 to your computer and use it in GitHub Desktop.
backup mysql
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 | |
echo " = = = = = back up start @ `date` = = = = = " | |
BACKUP_DIR="/opt/data/backup" | |
DUMP_CMD="/usr/bin/mysqldump" | |
HOST="127.0.0.1" | |
PORT="3306" | |
USER="root" | |
PASSWORD="123456" | |
cd $BACKUP_DIR | |
TIMESTAMP=`date +%F-%H%M` | |
DB_TOBACK="test" # 空格分隔多个数据库 | |
for db in $DB_TOBACK;do | |
echo "$db is in process... @ `date`" | |
backup_name="$db-$TIMESTAMP.sql" | |
$DUMP_CMD -h $HOST -P $PORT -u$USER -p$PASSWORD $db > $backup_name | |
gzip $backup_name | |
echo "done" | |
done | |
find $BACKUP_DIR -type f -mtime +10 -name "*.gz" | xargs -r rm -r | |
echo " = = = = = back up end @ `date` = = = = = " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment