标签:项目 errors eth created compress useradd inux incr conf
某公司有多台服务器,里面的数据很重要,如果磁盘坏了,数据就会丢失,所以公司要求把重要服务器数据备份以便出现问题时可以进行恢复,要求:每天晚上00点整在所有服务器上打包备份系统配置文件、网站程序目录及访问日志并通过rsync命令推送备份服务器backup上备份保留(备份思路可以是先在本地按日期打包,然后再推到备份服务器backup上)
所有服务器的备份目录必须一致 /backup/
要备份的系统配置文件包括但不限于:
一、定时任务服务器的配置文件(/var/spool/cron/root 适合web服务器和nfs服务器)
二、开机自启动服务的配置文件(/etc/tc.local 适合web和nfs服务器)
三、日常脚本目录(/server/scripts)
四、防火墙iptables的配置文件 (/etc/init.d/iptables)
1、web服务器站点目录例如(/var/html/www)
2、web服务器访问日志路径例如(/app/logs)
3、web服务器保留打包后的7天的备份数据即可(因为本地服务器的磁盘会满)
4、备份服务器上,保留近180天的备份数据,6个月前的数据清除 每周一的所有数据进行保留
5、备份服务器上,要按照备份服务器的内网IP为目录保存备份,备份的文件按照时间名字保存
6、需要保存的数据尽量完整正确,在备份服务器上对备份的数据进行检查,把本分成功及失败的结果信息发送到系统管理员邮箱中
服务器说明 |
外网IP |
内网IP |
服务器主机名 |
Nginx web服务器 |
10.0.0.8/24 |
172.16.1.8/24 |
web01 |
NFS存储服务器 |
10.0.0.31/24 |
172.16.1.31/24 |
nfs01 |
rsync备份服务器 |
10.0.0.41/24 |
172.16.1.41/24 |
backup |
1、rsync主配置文件
cat >/etc/rsyncd.conf<<EOF #rsync server# #created by yanxinjiang 2017-8-15 ##rsyncd.conf start## 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 = false list = false hosts allow = 172.16.1.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password [backup] path = /backup EOF
2、创建统一备份数据的目录,添加备份目录管理用户
mkdir /backup -p chown -R rsync.rsync /backup/ useradd -s /sbin/nologin -M rsync
3、创建用户认证文件
echo "rsync_backup:123456" >/etc/rsync.password chmod 600 /etc/rsync.password
4、启动rsync服务并设置开机自启动
rsync --daemon lsof -i:873 echo "rsync --daemon" >>/etc/rc.local
5、rsync客户端创建用户认证文件
echo "123456" >/etc/rsync.password chmod 600 /etc/rsync.password
6、客户端验证rsync服务推送功能
①nfs01服务器验证 [root@nfs01 backup]#rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password sending incremental file list hosts ②web01服务器验证 [root@web01 ~]#rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password sending incremental file list hosts
#!/bin/bash # name: web_backup.sh # desc: backup rsync client data info #no.1 create backup dir Backup_Dir=/backup IP=`/sbin/ifconfig eth1|awk -F "[ :]+" ‘NR==2{print $4}‘` mkdir $Backup_Dir/$IP -p #no.2 compress system data to backup_dir cd / &&tar zchf $Backup_Dir/$IP/systemfile_info_$(date +%F).tar.gz var/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables &&tar zchf $Backup_Dir/$IP/www_info_$(date +%F).tar.gz var/html/www &&tar zchf $Backup_Dir/$IP/www_log_$(date +%F).tar.gz app/logs &&#no.3 create data finger info file find $Backup_Dir/$IP/ -type f -name "*.tar.gz"|xargs md5sum >$Backup_Dir/$IP/finger_$(date +%F).txt #no.4 push data info to rsync_server‘s backup_dir rsync -az $Backup_Dir/$IP rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password #no.5 delete 7 day ago data info find $Backup_Dir/$IP -type f -name "*.tar.gz" -mtime +7|xargs rm -f
#!/bin/bash # name: nfs_backup.sh # desc: backup rsync client data info # author: yanxinjiang Backup_Dir=/backup IP=`/sbin/ifconfig eth1|awk -F "[ :]+" ‘NR==2{print $4}‘` Date_info=`date +%F_%w` #no.1 create backup dir mkdir $Backup_Dir/$IP -p #no.2 compress system data to backup_dir cd / &&tar zchf backup/$IP/systemfile_info_${Date_info}.tar.gz var/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables #no.3 create data finger info file find $Backup_Dir/$IP/ -type f -name "*${Date_info}.tar.gz"|xargs md5sum >$Backup_Dir/$IP/finger.txt #no.4 push data info to rsync_server‘s backup_dir rsync -az $Backup_Dir/$IP rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password #no.5 delete 7 day ago data info find $Backup_Dir/$IP/ -type f -name "*.tar.gz" -mtime +7|xargs rm -f
#!/bin/bash # name: backup_server.sh # time: 2017/08/15 16:00 # desc: backup rsync server data info # author yanxinjiang #no.1check data info find /backup/ -type f -name "finger.txt"|xargs md5sum -c >/backup/check_info.txt #no.2 send mail to sa mail -s "check_data mail" 774181401@qq.com </backup/check_info.txt &>/dev/null #no.3 delete 180 day ago unless week01 find /backup/ -type f -name "*.tar.gz" -mtime +180 ! -name "*1.tar.gz" |xargs rm -f
#nfs01 backup data info-cron 00 00 * * * /bin/sh /server/scripts/nfs_backup.sh &>dev/null
#web01 backup data info-cron 00 00 * * * /bin/sh /server/scripts/web_backup.sh &>dev/null
# backup: backup data info cron 00 05 * * * /bin/sh /server/scripts/backup_server.sh &>/dev/null
标签:项目 errors eth created compress useradd inux incr conf
原文地址:http://www.cnblogs.com/yanxinjiang/p/7373803.html