备份配置文件linux,linux备份数据库和配置文件shell脚本

linux备份数据库和配置文件shell脚本

#!/bin/bash

# backup root path

backup_root_path=/data/backup

# the time of this backup

backup_time=`date +%Y%m%d%H%M%S`

# year

path_year=${backup_time:0:4}

# month

path_month=${backup_time:4:2}

# day

path_day=${backup_time:6:2}

# the path of year,if not exists,create this dir.

path_year_full=${backup_root_path}"/"${path_year}

if [ ! -d "$path_year_full" ];then

mkdir "$path_year_full"

fi

# the path of month,if not exists,create this dir.

path_month_full=${path_year_full}"/"${path_month}

if [ ! -d "$path_month_full" ];then

mkdir "$path_month_full"

fi

# the path of day,if not exists,create this dir.

path_day_full=${path_month_full}"/"${path_day}

if [ ! -d "$path_day_full" ];then

mkdir "$path_day_full"

fi

# --------------------------

# backup mysql databases

# --------------------------

path_backup_mysql=${path_day_full}"/mysql"

if [ ! -d "$path_backup_mysql" ];then

mkdir "$path_backup_mysql"

fi

db_names=(db1 db2)

db_user=root

db_pass=123456

for db_name in ${db_names[@]}

do

db_file_name=${path_backup_mysql}"/db"${backup_time}${db_name}

#echo $db_file_name

mysqldump -u${db_user} -p${db_pass} --opt -q -R $db_name | gzip >"$db_file_name".sql.gz

done

# ------------------------

# backup config file

# ------------------------

bk_config_path=config

path_backup_config=${path_day_full}"/"${bk_config_path}

if [ ! -d "$path_backup_config" ];then

mkdir "$path_backup_config"

fi

# src file

config_files=(

"/usr/local/nginx-1.6.0/conf/nginx.conf"

"/usr/local/tomcat/apache-tomcat-7.0.54/conf/server.xml"

"/etc/mysql/my.cnf"

)

# dst file

config_dst_files=(

"nginx.conf"

"tomcat_conf_server.xml"

"mysql_my.cnf"

)

config_count=${#config_files[@]}

#echo $config_count

for ((i=0;i

do

#echo $i

#echo ${config_files[i]} to ${path_backup_config}"/"${config_dst_files[i]}

cp -f ${config_files[i]} ${path_backup_config}"/"${config_dst_files[i]}

done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值