标签:UI logs iba host www 站点 create end nginx web
rsync上机实战考试题:
某公司里有一台Web服务器,里面的数据很重要,但是如果硬盘坏了,数据就会丢失,现在领导要求你把数据在其他机器上做一个周期性定时备份。要求如下:
每天晚上00点整在Web服务器A(web01 )上打包备份网站程序目录并通过rsync命令推送到服务器B(backup)上备份保留
(备份思路可以是先在本地按日期打包,然后再利用rsync推到备份服务器上)。
具体要求如下:
1)Web服务器A和备份服务器B的备份目录必须都为/backup。
2)Web服务器站点目录假定为(/var/www/html)。
3)Web服务器本地仅保留7天内的备份。
4)备份服务器上每周六的数据都保留,其他备份仅保留180天备份。
5)备份服务器上检查备份结果是否正常,并将每天的备份结果发给管理员信箱。
服务器说明 |
外网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 |
要求:每天晚上0点整在web服务器上打包备份系统配置文件,通过rsync命令推送备份服务器backup上备份保留。
[root@backup ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
. [root@backup ~]# cat /etc/rsyncd.conf
######rsync_config_______________start
#created by oldboy 15:01 2007-6-5
#QQ 31333741 blog:http://oldboy.blog.51cto.com
##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/
[nfsbackup]
path = /nfsbackup
#rsync_config_______________end
[root@backup ~]# useradd -M -s /sbin/nologin rsync
[root@backup ~]# mkdir /backup
[root@backup ~]# chown -R rsync /backup
[root@backup ~]# rsync --daemon
[root@backup ~]# ss -antup | grep rsync
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1851,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",1851,4))
[root@backup ~]# ps -ef|grep rsync|grep -v grep
root 23049 1 0 Jan15 ? 00:00:00 rsync --daemon
root@backup ~]# lsof -i:rsync
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 23049 root 3u IPv4 56971 0t0 TCP *:rsync (LISTEN)
rsync 23049 root 5u IPv6 56972 0t0 TCP *:rsync (LISTEN)
[root@backup ~]# netstat -lntup|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 23049/rsync
tcp 0 0 :::873 :::* LISTEN 23049/rsync
[root@backup ~]# telnet 172.16.1.41 873
Trying 172.16.1.41...
Connected to 172.16.1.41.
Escape character is ‘^]‘.
@RSYNCD: 30.0
证明服务器端配置没有问题
[root@web01 ~]# cat /etc/rsync.password
123456
[root@web01 ~]# ls -ld /etc/rsync.password
-rw------- 1 root root 7 Mar 14 19:25 /etc/rsync.password
[root@web01 backup]# rsync -avz /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
sending incremental file list
./
1
2
3
4
说明客户端推送成功
#!/bin/bash
##############################################################
# File Name: bak1.sh
# Version: V1.0
# Author: xinlibao
# Organization: www.oldboyedu.com
# Created Time : 2017-03-15 22:23:50
# Description:
##############################################################
IP=$(hostname -I|awk -F "[ :]+" ‘{print $2}‘)
mkdir -p /backup/$IP /var/html/www/ /spool/cron/root/ /app/logs/
cd / &&\:
#compress
tar zcfh /backup/$IP/sys_config_$(date -d "1 day ago" +"%Y-%m-%d").tar.gz var/spool/cron/ etc/rc.local server/scripts &&\
tar zcfh /backup/$IP/webdata_$(date -d "1 day ago" +"%Y-%m-%d").tar.gz var/html/www/ &&\
tar zcfh /backup/$IP/access_log_$(date -d "1 day ago" +"%Y-%m-%d").tar.gz app/logs &&\
#check finger
find /backup -type f -name "*.tar.gz"|xargs md5sum >/backup/$IP/flag_$(date -d "1 day ago" +"%Y-%m-%d").txt
#push info
rsync -az /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
#del data 7 days ago
find /backup -type f -mtime +7 ! -name "*week01.tar.gz"|xargs rm -f
#!/bin/bash
##############################################################
# File Name: bak.sh
# Version: V1.0
# Author: xinlibao
# Organization: www.oldboyedu.com
# Created Time : 2017-03-15 22:45:08
# Description:
#############################################################
IP=$(hostname -I|awk -F "[ :]+" ‘{print $2}‘)
mkdir -p /backup/$IP /var/html/wwww/ /spool/cron/root/ /app/logs/
cd / &&\
#compress
tar zcfh /backup/$IP/sys_config_$(date -d "1 day ago" +"%Y-%m-%d").tar.gz var/spool/cron/root etc/rc.local server/scripts &&\
#check finger
find /backup -type f -name "*.tar.gz"|xargs md5sum >/backup/$IP/flag_$(date -d "1 day ago" +"%Y-%m-%d").txt
#push info
rsync -az /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
#del data 7 days ago
find /backup -type f -mtime +7 ! -name "*week01.tar.gz"|xargs rm -f
#!/bin/bash
##############################################################
# File Name: mail.sh
# Version: V1.0
# Author: xinlibao
# Organization: www.oldboyedu.com
# Created Time : 2017-03-14 11:24:56
# Description:
##############################################################
#check data info
find /backup/*[0-9]*/ -type f -name "*.txt"|xargs md5sum -c>/tmp/mail.txt
mail -s "hello" 18518759167@163.com </tmp/mail.txt
#del data 180 days ago
find /backup -type f -mtime +180 ! -name "*week01.tar.gz"|xargs rm -f
[root@web01 backup]# crontab -l
00 00 * * * /bin/sh /server/scripts/bak1.sh >/dev/null 2>&1
标签:UI logs iba host www 站点 create end nginx web
原文地址:http://www.cnblogs.com/xinlibao/p/6697097.html