crontab-mysql备份脚本
my生气了
#!/bin/bash
#####################
# mysql 备份脚本 #
# #
#####################
# 备份目录
base_path='/home/mysql_backup'
# 备份时间
backup_date=$(date -d now "+%y%m%d-%H%m")
# remote host
remote_host="rm-8vbnl75zgm2ffsatido.mysql.zhangbei.rds.aliyuncs.com"
remote_user="root3"
remote_passwd="GMgm123!@#"
#remote_database="--all-databases"
remote_database=" cnaca cnaca_oxhide cnaca_oxhide_test cnaca_test "
# 保留天数
KEEP_DAYS=60
############################################
logs_path=${base_path}
log_name=${base_path}/${backup_date}.log
file_name=${base_path}/${backup_date}.sql
# 创建备份目录
#if [ ! -d "$basepath" ]; then
#mkdir -p "$basepath"
#fi
touch ${log_name}
echo 'start !!' > ${log_name}
retry_times=5
# 是否执行成功
function overdump {
echo "mysqldump exec status : $? , retry_times : ${retry_times} " >> ${log_name}
if [[ $? -eq 0 ]];then
echo "backuped successful !!" >> ${log_name}
else
echo "backup is running !!" >> ${log_name}
if [ ${retry_times} -eq 0 ];then
echo "retry_times is over!mysqldump is not find or system is busy !!" >> ${log_name}
exit
fi
/bin/sleep 10
retry_times=$[ ${retry_times} - 1]
overdump
fi
}
# mysql dump脚本
mysqldump -h ${remote_host} -u ${remote_user} -p${remote_passwd} --databases ${remote_database} --lock-tables=0 --default-character-set=utf8| gzip > ${file_name}.gz
overdump
echo "${file_name} backup!!!" >> ${log_name}
# 日志删除 修改的删除
if [ -d "${logs_path}" ]; then
find "${logs_path}" -type f -name "*.*" -mtime +${KEEP_DAYS} -exec rm -f {} \;
fi
echo "rm log over!!" >> ${log_name}
###########################################################################
# 单独安装mysqldump
# yum -y install holland-mysqldump.noarch
# #
# 定时任务设置 每天0点30分 #
# 30 0 * * * /bin/sh /home/mysql_backup/gm_mysql_backup.sh #
# #
###########################################################################