备份系统重要文件
首先,大家如果看到有什么不懂的地方,欢迎吐槽!!!
我会在当天或者第二天及时回复,并且改进~~
#!/bin/bash
Time=$(date +%Y-%m-%d)
File_path="/data/File_bak"
Source_file="${Time}_bak.tbz2"
Source_all="${File_path}/${Source_file}"
Dest_path="${File_path}/${Time}/"
S_C1="172.16.1.13"
S_C2="172.16.1.14"
S_C3="172.16.1.15"
S_C4="172.16.1.16"
S_C5="172.16.1.17"
S_C6="172.16.1.18"
S_C7="172.16.1.11"
S_C8="172.16.1.12"
S_C9="172.16.1.19"
S_C10="172.16.1.20"
S_C11="172.16.1.21"
S_C12="172.16.1.22"
User="root"
for i in "$S_C1" "$S_C2" "$S_C3" "$S_C4" "$S_C5" "$S_C6" "$S_C7" "$S_C8" "$S_C9" "$S_C10" "$S_C11" "$S_C12"
do
ssh ${User}@${i} "[ -d $File_path ] || mkdir -p $File_path"
done
mkdir -p ${Dest_path}
#####S_C1_bak#####
ssh ${User}@${S_C1} "tar jcf ${Source_all}_SC1 /etc/redis.conf /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C1}:${Source_all}_SC1 $Dest_path
#####S_C2_Bak#####
ssh ${User}@${S_C2} "tar jcf ${Source_all}_SC2 /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C2}:${Source_all}_SC2 $Dest_path
#####S_C3_Bak#####
ssh ${User}@${S_C3} "tar jcf ${Source_all}_SC3 /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C3}:${Source_all}_SC3 $Dest_path
#####S_C6_Bak#####
ssh ${User}@${S_C6} "tar jcf ${Source_all}_SC6 /etc/squid /usr/local/mysql-proxy/conf"
scp ${User}@${S_C6}:${Source_all}_SC6 $Dest_path
#####S_C7_Bak#####
ssh ${User}@${S_C7} "tar jcf ${Source_all}_SC7 /etc/vsftpd /etc/postfix /usr/local/nginx/conf"
scp ${User}@${S_C7}:${Source_all}_SC7 $Dest_path
#####S_C8_Bak#####
tar jcf /data/File_bak/$(date +%Y-%m-%d)_bak.tbz2_SC8 /usr/local/zabbix/etc /usr/local/zabbix/shell /data/sh/
mv /data/File_bak/$(date +%Y-%m-%d)_bak.tbz2_SC8 $Dest_path
#####S_C9_Bak#####
ssh ${User}@${S_C9} "tar jcf ${Source_all}_SC9 /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C9}:${Source_all}_SC9 $Dest_path
#####S_C10_Bak#####
ssh ${User}@${S_C10} "tar jcf ${Source_all}_SC10 /etc/postfix/main.cf"
scp ${User}@${S_C10}:${Source_all}_SC10 $Dest_path
#####S_C11_Bak#####
ssh ${User}@${S_C11} "tar jcf ${Source_all}_SC11 /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C11}:${Source_all}_SC11 $Dest_path
#####S_C12_Bak#####
ssh ${User}@${S_C12} "tar jcf ${Source_all}_SC12 /usr/local/mysql/data/my.cnf"
scp ${User}@${S_C12}:${Source_all}_SC12 $Dest_path
tar jcf /tmp/$(date +%Y-%m-%d)_bak.tbz2 $Dest_path
echo "
Date is a $Time
S-C1 /etc/redis.conf,/usr/local/mysql/data/my.cnf
S-C2 /usr/local/mysql/data/my.cnf
S-C3 /usr/local/mysql/data/my.cnf
S-C6 /etc/squid/,/usr/local/mysql-proxy/conf/
S-C7 /etc/vsftpd,/etc/postfix,/usr/local/nginx/conf
S-C8 /usr/local/zabbix/etc,/usr/local/zabbix/shell,/data/sh/
S-C9 /usr/local/mysql/data/my.cnf
S-C10 /etc/postfix/main.cf
S-C11 /usr/local/mysql/data/my.cnf
S-C12 /usr/local/mysql/data/my.cnf" | mail -s "File.conf_bak" -a /tmp/$(date +%Y-%m-%d)_bak.tbz2 xxx@xxx.com