#!/bin/bash
#
MYSQL_USER='tangce'
MYSQL_PASS='tang@)ce!#'
DATABASE=user_center
FILE_NAME=$DATABASE.`date +%Y%m%d`.tar.gz
TMP_FILENAME=$DATABASE.`date +%Y%m%d%H%M%S`.sql.gz
#切换到文件存放的目录,防止在tar时,报警告信息:tar: Removing leading `/’ from member names
cd /home/backup/
#删除7天以前的备份文件
rm -rf $DATABASE.$(date -d -1day +"%Y%m%d").tar.gz
mysqldump -u$MYSQL_USER -p$MYSQL_PASS $DATABASE --socket=/var/lib/mysql/mysql.sock |
gzip -9 -> $TMP_FILENAME
tar -czf $FILE_NAME $TMP_FILENAME
rm -rf $TMP_FILENAME