Skip to content

Instantly share code, notes, and snippets.

@ls0f
Last active March 1, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ls0f/c424774c6a51c6ed6748 to your computer and use it in GitHub Desktop.
Save ls0f/c424774c6a51c6ed6748 to your computer and use it in GitHub Desktop.
backup mysql
#!/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