脚本编写:
备份服务客户端脚本:
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.创建任务所需目录与文件
mkdir /backup -p
mkdir -p $backup_dir/$backup_ip
touch /etc/sysconfig/iptables
echo 打包日志 >>/log/rsync_$(date +%F).log
#01.打包备份文件数据
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.传输任务文件包
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.创建任务所需目录与文件
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.打包备份文件数据
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.传输任务文件包
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
备份服务服务端脚本编写:
先添加mail信息 创建/server/scripts脚本存放目录
backup10
#!/bin/bash
#01.找出指纹信息 进行比对
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 "备份服务器地址信息","备份文件信息","备份结果信息"}{print $0}'|column
-t > /tmp/baogao.txt
#03.将结果发送邮箱
mail -s "全网备份完成" xxx@qq.com </tmp/baogao.txt
#04.删除180天外除了周一数据外的压缩包
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(此处写邮箱授权码不是登录密码)
set smtp-auth=login
编辑邮件内容格式
echo 邮件内容|mail -s "邮件标题" 目标邮箱地址
网友评论