MYSQL定时自动备份脚本

#!/bin/sh

DUMP=/usr/local/mysql/bin/mysqldump
OUT_DIRDATE=/opt/backup/pay_bak

LINUX_USER=root
DB_HOST=192.168.28.10
DB_NAME=pay
DB_USER=root
DB_PASS=123456
#How much days backup most

DAYS=1

#Core of script

cd $OUT_DIRDATE
DATE=`date +%Y_%m_%d`
OUT_SQL="pay_$DATE.sql"
TAR_SQL="pay_$DATE.tar.gz"

$DUMP -h$DB_HOST -u$DB_USER -p$DB_PASS --default-character-set=utf8 --skip-opt -q --extended-insert=false  --max_allowed_packet=4194304 --net_buffer_length=16384  --mas
ter-data=2 --databases $DB_NAME> $OUT_SQL

tar zcvf $TAR_SQL ./$OUT_SQL

find ./ -name "*.sql" -type f -mtime +$DAYS -exec rm {} \;

 

你可能感兴趣的:(MYSQL定时自动备份脚本)