#!/bin/bash
BACK_DIR=/data/mysql_backup
HOST=192.168.10.100
USER=node
PASSWORD=a12gd
DATABASES=(
node
gobe
)
BEGIN_TIME=`date '+%F %T'`
BEGIN_TIME_TIMESTAMP=`date '+%s'`
for database in ${DATABASES[*]};do
mysqldump -h${HOST} -u${USER} -p${PASSWORD} --single-transaction --master-data=2 -B $database > ${BACK_DIR}/${database}_`date +%F_%H-%M-%S`.sql
gzip -1 ${BACK_DIR}/*.sql
done
END_TIME_TIMESTAMP=`date '+%s'`
echo "备份开始时间:${BEGIN_TIME},总耗时$((${END_TIME_TIMESTAMP} - ${BEGIN_TIME_TIMESTAMP}))秒!" >> ${BACK_DIR}/backup.log
find ${BACK_DIR}/*.gz -mtime +6 | xargs rm -f
结合任务计划执行:
00 00 * * * /data/mysql_backup/backup.sh