腳本編寫:
備份服務(wù)客戶端腳本:
nfs01:
mkdir -p /server/scripts
vim /server/scripts/beifen.sh
[root@nfs10 backup]# vim /server/scripts/beifen.sh
#!/bin/bash
backup_dir="/backup"
backup_ip=$(hostname -i)
#00.創(chuàng)建任務(wù)所需目錄與文件
mkdir /backup -p
mkdir -p $backup_dir/$backup_ip
touch /etc/sysconfig/iptables
echo 打包日志 >>/log/rsync_$(date +%F).log
#01.打包備份文件數(shù)據(jù)
tar zvcPhf $backup_dir/$backup_ip/system_backup_(date +%F).log
#02.給備份打包文件生成指紋信息
find $backup_dir/$backup_ip -type f -name "*.tar.gz"|xargs md5sum >backup_ip/finger.txt
echo rsync 日志 >>/log/rsync_$(date +%F).log
#03.傳輸任務(wù)文件包
rsync -avz $backup_dir/$backup_ip/ rsync_backup@172.16.1.108::backup/$backup_ip --password-file=/etc/rsync.password >>/log/rsync_$(date +%F).log
#04.刪除七天前壓縮包
find $backup_dir/ -type f -name "*.tar.gz" -mtime +7 -delete
web1
mkdir -p /server/scripts
vim /server/scripts/beifen.sh
#!/bin/bash
backup_dir="/backup"
backup_ip=$(hostname -i)
00.創(chuàng)建任務(wù)所需目錄與文件
mkdir /backup -p
mkdir -p $backup_dir/$backup_ip
mkdir -p /var/html/www
mkdir -p /app/logs
touch /etc/sysconfig/iptables
echo 打包日志 >>/log/rsync_$(date +%F).log
#01.打包備份文件數(shù)據(jù)
tar zvcPhf $backup_dir/$backup_ip/system_backup_$(date +%F_%A).tar.gz /var/spool/cron/root /etc/rc.local /etc/sysconfig/iptables /var/html/www /app/logs >>/log/rsync_$(date +%F).log
#02.給備份打包文件生成指紋信息
find $backup_dir/$backup_ip -type f -name "*.tar.gz"|xargs md5sum >$backup_dir/$backup_ip/finger.txt
echo rsync 日志 >>/log/rsync_$(date +%F).log
#03.傳輸任務(wù)文件包
rsync -avz $backup_dir/$backup_ip/ rsync_backup@172.16.1.108::backup/$backup_ip --password-file=/etc/rsync.password >>/log/rsync_$(date +%F).log
#04.刪除七天前壓縮包
find $backup_dir/ -type f -name "*.tar.gz" -mtime +7 -delete
備份服務(wù)服務(wù)端腳本編寫:
先添加mail信息 創(chuàng)建/server/scripts腳本存放目錄
backup10
#!/bin/bash
#01.找出指紋信息 進(jìn)行比對
find /backup -type f -name "finger.txt"|xargs md5sum -c >/tmp/zhiwen.txt
#02.將指紋信息做成表格
cat /tmp/zhiwen.txt|sed -r 's#/backup|/|:# #g'|awk 'BEGIN{print "備份服務(wù)器地址信息","備份文件信息","備份結(jié)果信息"}{print $0}'|column
-t > /tmp/baogao.txt
#03.將結(jié)果發(fā)送郵箱
mail -s "全網(wǎng)備份完成" xxx@qq.com </tmp/baogao.txt
#04.刪除180天外除了周一數(shù)據(jù)外的壓縮包
find /backup -type f -name "*.tar.gz" -mtime +180 ! -iname "*_monday.tar.gz"
-delete
郵件配置
vim /etc/mail.rc
按G跳到最后一行 o下一行開始編輯
set from=xxx@163.com
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=xxx(此處寫郵箱授權(quán)碼不是登錄密碼)
set smtp-auth=login
編輯郵件內(nèi)容格式
echo 郵件內(nèi)容|mail -s "郵件標(biāo)題" 目標(biāo)郵箱地址