mysql备份脚本

!/bin/bash

desc: db_bk

Author: kuvi [email protected]

db_install_dir=/usr/local/mysql
mysql_data_dir=/data/mysql

DBname=
dbrootpwd=

backup_dir=/data/backup
expired_days=5

LogFile={backup_dir}/DB_(date +%Y%m%d_%H).sql
NewFile={DBname}{backup_dir}/DB(date +%Y%m%d --date="${expired_days} days ago")*.tgz

[ ! -e "{backup_dir}

DB_tmp=${db_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "show databases\G" | grep ${DBname}
[ -z "{DBname}] not exist" >> ${LogFile} ; exit 1 ; }

if [ -n "ls ${OldFile} 2>/dev/null" ]; then
rm -f {OldFile}] Delete Old File Success" >> {OldFile}] Delete Old Backup File" >> ${LogFile}
fi

if [ -e "{NewFile}] The Backup File is exists, Can't Backup" >> {db_install_dir}/bin/mysqldump -uroot -p{DBname} > {backup_dir} > /dev/null
tar czf {DumpFile##*/} >> {NewFile}] Backup success ">> {DumpFile}
popd > /dev/null
fi

image.png

你可能感兴趣的:(mysql备份脚本)