shell_backup_MySQL
Posted jcjone
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell_backup_MySQL相关的知识,希望对你有一定的参考价值。
#!/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的主要内容,如果未能解决你的问题,请参考以下文章