码迷,mamicode.com
首页 > 数据库 > 详细

shell_backup_MySQL

时间:2020-01-07 14:41:50      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:mysqld   core   rm -rf   shell   pass   lock   star   roo   usr   

#!/bin/bash

#可修改如下参数
backup_filename=$(date +%Y%m%d%H%M%S)
backup_tmp_dir=/data/backup/
ip=10.0.1.182
user=root
passwd=starcor
databse_1=nn_core
databse_2=nn_cms
#备份目录
if [ ! -d ${backup_tmp_dir}/cms/db ]; then
mkdir -p ${backup_tmp_dir}/cms/db
fi
if [ ! -d ${backup_tmp_dir}/core/db ]; then
mkdir -p ${backup_tmp_dir}/core/db
fi

#备份
function data() {
/usr/local/mysql/bin/mysqldump -u$user -p$passwd -h127.0.0.1 $databse_1 --skip-lock-tables > ${backup_tmp_dir}/core/db/db_${databse_1}_${ip}_${backup_filename}.sql
/usr/local/mysql/bin/mysqldump -u$user -p$passwd -h127.0.0.1 $databse_2 --skip-lock-tables > ${backup_tmp_dir}/cms/db/db_${databse_2}_${ip}_${backup_filename}.sql
}
function package(){
#打包文件
cd ${backup_tmp_dir}/core/db
tar zcf db_${databse_1}_${ip}_${backup_filename}.sql.tar.gz db_$databse_1_$ip_${backup_filename}.sql
find ./ -name "*.sql" -exec rm -rf {} \;
cd ${backup_tmp_dir}/cms/db
tar zcf db_${databse_2}_${ip}_${backup_filename}.sql.tar.gz db_$databse_2_$ip_${backup_filename}.sql
find ./ -name "*.sql" -exec rm -rf {} \;
}
data
package
#保存7天备份文件
find /data/db_backup -type f -mtime +7 -exec rm -rf {} \;

shell_backup_MySQL

标签:mysqld   core   rm -rf   shell   pass   lock   star   roo   usr   

原文地址:https://www.cnblogs.com/jcjone/p/12161368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!