温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

rsync---全网备份---实现步骤

发布时间:2020-06-22 18:22:44 来源:网络 阅读:1694 作者:51_cto_con 栏目:建站服务器




具体要求如下

1)所有服务器的备份目录必须都为/backup

2)要备份的系统配置文件包括但不限于:

      a.定时任务服务的配置文件(/var/spool/cron/root)(适合web和nfs服务器

      b.开机自启动的配置文件(/etc/rc.local)适合web和nfs服务器

      c.日常脚本的目录(/server/scripts)

      d.防火墙iptables的配置文件(/etc/sysconfig/iptables)

      e..............

3)Web服务器站点目录假定为(/var/html/www)

4)Web服务器A访问日志路径假定为(/app/logs)

5)Web服务器保留打包后的7天的备份数据即可(本地留存不能多于7天,因为太多硬盘会满)

6)备份服务器上,保留每周一的所有数据副本,其它要保留6个月的数据副本

7)备份服务器上要按照备份数据服务器的内网IP为目录保存备份,备份的文件按照时间名字保存

8)*需要确保备份的数据尽量完整正确,在备份服务器上对备份的数据进行检查,把备份的成功及失败结果信息发       给系统管理员邮箱中



PS1="\[\e[32;1m\][\u@\h \W]\\$ \[\e[0m\]"  >>/etc/bashrc   ##小功能优化

sed -i.bak 's@#UseDNS yes@UseDNSno@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g'/etc/ssh/sshd_config
/etc/init.d/sshd reload


一、服务端配置


01、查看服务器上有无rsync软件

rpm -qa rsync


02、开始配置

vim /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = no
list = no
hosts allow =10.0.0.0/24    ##外网 -- 测试  用于没有准备第二块网卡
auth users = rsync_backup
secrets file =/etc/rsync.password
[backup]
path = /backup

03、搭建rsync服务器需要的配置

 

①useadd -s /sbin/nologin -M rsync
②echo "rsync_backup:123456"  >>/etc/rsync.password
③chmod 600 /etc/rsync.password
④mkdir -p /backup
⑤chown -R rsync.rsync /backup


04、启动rsync-------####xinetd

ps -ef |grep rsync
rsync --daemon
ps -ef |grep rsync

05、开机自启动rsync服务

echo "rsync --daemon" >>/etc/rc.local


二、客户端配置

01、创建密码文件

vim /etc/rync.password
123456
说明:客户端存放密码的文件路径最后与服务端一致,密码必须一致

02、更改密码文件权限

chmod 600 /etc/rync.password
ll /etc/rync.password

03、测试

rsync -avzP /etc/services rsync_backup@10.0.0.1::backup --password-file=/etc/rsync.password


三、客户端备份脚本的编写

温馨注释:在远程连接中,另外克隆一个窗口,进行操作,把测试好的命令复制到要写的脚本文件当中;

01、创建/backup备份目录

mkdir -p /backup/$(hostname -I |awk '{print $1}')

02、压缩备份数据到/backup目录中

cd / && tar zcfh /backup/$(hostname -I |awk '{print $1}')/\
ifconfig_backup_$(date +%F_week0%w).tar.gz var/spool/cron etc/rc.local \
server/scripts etc/sysconfig/iptables

03、推送备份目录数据到rsync服务器--推送的必须能让rsync服务端知道是谁进行推送的  

rsync -az /backup/$(hostname -I |awk '{print $1}') rsync_backup@10.0.0.1::backup \
--password-file=/etc/rsync.password

04、删除7天以前的备份数据

find /backup/$(hostname -I) -type f -mtime +7 |xargs rm -f

05、对备份的数据进行验证,加上相应的指纹信息

find /backup/$(hostname -I |awk '{print $1}')/ \
-type f -name "*$(date +%F_week0%name "*$(date +%F_week0%w).tar.gz" \
|xargs md5sum >/backup/$(hostname -I |awk '{print $1}')/falg_$(date +%F_week0%w).txt


06、脚本编写

#! /bin/bash

IP=$(hostname -I |awk '{print $1}')


mkdir -p /backup/$IP &&\


#compress

cd / && tar zcfh /backup/$IP/ifconfig_backup_$(date +%F_week0%w).tar.gz var/spool/cron etc/rc.local server/scripts etc/sysconfig/iptables &&\


#check falg

find /backup/$IP/ -type f -name "*$(date +%F_week0%w).tar.gz" |xargs md5sum >/backup/$IP/falg_$(date +%F_week0%w).txt

#push info

rsync -az /backup/$IP rsync_backup@10.0.0.1::backup --password-file=/etc/rsync.password


#clear info

find /backup/$IP/ -type f -mtime +7 |xargs rm -f


三、客户端编写定时任务

crontab -e
#crontab-id:02-backup date
00 00 * * * /bin/bash /server/scripts/backup.sh &>/dev/null

四、服务器端脚本编写

01、验证传输数据完整性

cat falg_2017-05-06_week06.txt
md5sum -c falg_2017-05-06_week06.txt


02、检验当天数据的完整性

[root@backup 10.0.0.2]# md5sum -c falg_$(date +%F_week0%w).txt


03、检验优化

[root@backup 10.0.0.2]# find /backup/ -type f -name "*$(date +%F_week0%w).txt"


04、把脚本推送到web服务器上

[root@nfs01 ~]# rsync -avzP /server/scripts/backup.sh root@10.0.0.3:/server/scripts/


05、web服务器推送到rsync服务器上

[root@web01 ~]# mkdir -p /app/logs /var/html/www
[root@web01 ~]# sh /server/scripts/backup.sh

06、打包

cd / && tar zcfh /backup/$IP/www_backup_$(date +%F_week0%w).tar.gz var/html/www &&\
cd / && tar zcfh /backup/$IP/app_log_backup_$(date +%F_week0%w).tar.gz app/logs



07、邮箱配置

set from=
set smtp=smtp.qq.com
set smtp-auth-user=
set smtp-auth-password=
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/ &>/dev/null

set from=17600201416@163.com smtp=smtp.163.com

set smtp-auth-user=17600201416 smtp-auth-password=sangfor123 smtp-auth=login



08、rsync服务器上的脚本编写

vim /server/scripts/server_backup.sh

find /backup -type f -name "*$(date +%F_week0%w).txt" |xargs md5sum -c >/tmp/mails.txt

mail -s "check data" xxxxxx@qq.com </tmp/mails.txt

###clear info

find /backup -type f -mtime +180 ! -name  "*week01.tar.gz" |xargs rm -f


09、编写定时任务

crontab -e 

00 06 * * * /bin/bash  /server/scripts/server_backup.sh  &>/dev/null

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI