Full network data backup solution

1 project backup environment

Known 3 server host names are web01, backup, nfs01, host information in the table below:

Server Description WAN IP IP network Host Name
web server 10.0.0.7/24 172.16.1.7/24 web01
nfs server storage 10.0.0.31/24 172.16.1.31/24 nfs01
rsync backup server 10.0.0.41/24 172.16.1.41/24 backup

2 Project Backup Requirements

Specific requirements are as follows:
(1) the backup directory must all servers are / backup.
Profile system (2) to be backed up include, but are not limited to:
    A regular tasks and services configuration file (/ var / spool / cron / root) ( for web server and nfs).
    b. boot from the startup configuration file (/etc/rc.local) (suitable web server and nfs).
    c. daily scripts directory (/ server / scripts) (suitable web server and nfs).
    D. iptables firewall or firewalld profile (/ etc / sysconfig / iptables or / etc / firewalld) (for web server and nfs).
    e. Under think for themselves what need to back it?
(3) Web site directory server is assumed to be (/ var / html / www) ( suitable web server).
(4) Web server access logs path is assumed to be A (/ app / logs) (for web server).
(5) Web server after seven days of backup data can be packed (local retained no more than seven days, because too much hard disk will be full)
on (6) backup server, the backup data to retain the last six months, while retaining All of the data a week before six months
on (7) according to the backup server to back up data IP network server to save the backup directory, the backup file is saved in chronological name.
(8) the need to ensure as complete backup of the data is correct, the backed up data to check on the backup server, the backup success and failure result information to the system administrator mailbox
(9) set up NFS storage server to achieve web site pictures, accessories shared
(10) NFS to store real-time data backup
 
requirements summary
(1) 00 o'clock every night the whole package backup system configuration files, website access logs and program directory and push backup retention on the backup server backup via rsync command on the web server.
(2) 00 o'clock every night, the whole package on the nfs server backup system configuration files, and backup retention on the backup server backup via rsync push command.
Ideas:
Backup idea can be the first packaged locally by date, and then pushed to the backup server backup, the backup is complete to enter extracting file, check to see if there is content, nfs storage server with a web server, the actual work is all servers .

3 project backup logic chart

1.jpg

4 implementation of the project configuration

(1) First, the backup directory of every three servers as backup

mkdir /backup       #web01,nfs01,backup服务器都要创建backup

Profile system (2) include, but are not limited to be backed up to
    a. A timing task service profile (/ var / spool / cron / root) ( for web server and nfs).
    b. boot from the startup configuration file (/etc/rc.local) (suitable web server and nfs).
    c. daily scripts directory (/ server / scripts) (suitable web server and nfs).
    D. iptables firewall or firewalld profile (/ etc / sysconfig / iptables or / etc / firewalld) (for web server and nfs).
     

cd /
tar zchf $Dir_info/$IP_info/system_backup_$(date +%F_星期%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables
# h:表示将源文件也压缩

(3) Web site directory server is assumed to be (/ var / html / www) (suitable web server).

[root@web01 ~]# mkdir /var/html/www -p

(4) Web server access logs path is assumed to be A (/ app / logs) (for web server).

[root@web01 ~]# mkdir /app/logs -p

(5) Web server after seven days of backup data package.

find /backup -type f -mtime +7 -name "*.tar.gz"|xargs rm 2>/dev/null
2>/dev/null:如果没有7天之前的数据会产生错误报告信息,因此将错误信息追加到/dev/null,不会产生错误信息。

(6) the backup server, keep the last six months of backup data, while retaining all the data a week before six months.

find /backup -type f -mtime +180 -name "*.tar.gz"|xargs rm
#   方法一:在文件名称中显示星期信息
#   data+%A/date +%w
find /backup/ -type f -name "*.tar.gz" -mtime +180 ! -name "*星期1.tar.gz"|xargs rm 2>/dev/null
#   方法二:将周一数据单独保存
#   今天是周一
mkdir /backup/week01
rsync -avz /backup/week01 [email protected]::backup/week01/
find /backup/ -path "/backup/week01" -prune -o -type f -name "*.tar.gz" -print |xargs rm

(7) according to the backup server to back up data IP network server to save the backup directory, the backup file is saved in chronological name.

[root@backup ~]#    mkdir /backup/172.16.1.7 172.16.1.31

(8) the need to ensure as complete backup of the data is correct, the backed up data to check on the backup server, the backup success and failure result information to the system administrator mailbox
 

rsync -avz /backup/ [email protected]::backup --password-file=/etc/rsync.password
md5sum /backup/172.16.1.31/system_backup_2019-07-18_星期4.tar.gz >/backup/172.16.1.31/finger.txt
####    md5值追加给finger.txt(指纹文件)
md5sum -c finger.txt        ### 自动对比md5值

 

vim /etc/mail.rc
set [email protected] smtp=smtp.163.com 
set [email protected] smtp-auth-password=ichn123456 smtp-auth=login
#   将这两条命令添加到最后一行
systemctl restart postfix.service   #   重启邮件
echo "linux ichn62"|mail -s "test_mail" [email protected] #   测试邮件是否能发送
mail -s "test_mail" [email protected] </etc/hosts                     # 测试邮件是否能发送

Scripting finishing above command
 

mkdir /server/scripts/  #创建脚本目录
[root@web01 scripts]#vi system_backup.sh 
#!/bin/bash

Dir_info="/backup"
IP_info="$(hostname -i)"

# 创建本地备份目录
mkdir -p $Dir_info/$IP_info

# 创建本地备份压缩文件,备份站点目录和日志目录
cd /
tar zchf $Dir_info/$IP_info/system_backup_$(date +%F_星期%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables
tar zchf $Dir_info/$IP_info/web_backup_$(date +%F_星期%w).tar.gz ./var/html/www/
tar zchf $Dir_info/$IP_info/web_log_$(date +%F_星期%w).tar.gz ./app/logs/

# 生成数据指纹信息
find $Dir_info/$IP_info/ -type f  -name "*.tar.gz" -mtime -1|xargs md5sum >$Dir_info/$IP_info/finger.txt

# 传输备份数据
rsync -az $Dir_info/ [email protected]::backup --password-file=/etc/rsync.password

# 删除七天以前备份数据
find $Dir_info -type f -mtime +7 -name "*.tar.gz"|xargs rm 2>/dev/null

 

mkdir /server/scripts/  #创建脚本目录
[root@nfs01 scripts]#vi system_backup.sh 
#!/bin/bash

Dir_info="/backup"
IP_info="$(hostname -i)"

# 创建本地备份目录
mkdir -p $Dir_info/$IP_info

# 创建本地备份压缩文件
cd /
tar zchf $Dir_info/$IP_info/system_backup_$(date +%F_星期%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables

# 生成数据指纹信息
find $Dir_info/$IP_info/ -type f  -name "*.tar.gz" -mtime -1|xargs md5sum >$Dir_info/$IP_info/finger.txt

# 传输备份数据
rsync -az $Dir_info/ [email protected]::backup --password-file=/etc/rsync.password

# 删除七天以前备份数据
find $Dir_info -type f -mtime +7 -name "*.tar.gz"|xargs rm 2>/dev/null

  

mkdir /server/scripts/  #创建脚本目录
[root@backup scripts]#vi backup_check.sh 
[root@backup scripts]#cat backup_check.sh 
#!/bin/bash

#验证数据完整性
find /backup/ -type f -name "finger.txt"|xargs md5sum -c &>/tmp/check_info.txt

#发送邮件信息通知
mail -s "backup_check_info" [email protected] </tmp/check_info.txt

#删除6个月之前数据
find /backup/ -type f -name "*.tar.gz" -mtime +180 ! -name "*星期1.tar.gz"|xargs rm 2>/dev/null

Write regular tasks
WEB server:

[root@web01 /]#crontab -e
# backup data
00 00 * * * /bin/sh /server/scripts/system_backup.sh &>/dev/null

Question: How to back up data to back up Monday
July 18 Thursday, one day generate data on Thursday July 19 Friday 0:00 backup system_info_2019-07-19_ Friday .tar, gz
July 19 Friday, one day generate data on Friday Saturday, July 20 0:00 backup system_info_2019-07-20_ Saturday .tar, gz
July 20 Saturday, one day generate data Saturday July 21 Sunday 0:00 Sunday system_info_2019-07-21_ backup .tar, gz
July 21 Sunday, one day generate data on Sunday July 22 Monday 0:00 Monday system_info_2019-07-22_ backup .tar, gz
two ways:
Method 1: exclude Tuesday
Second way: $ (date% F - -1day D)
the NFS client:

[root@nfs01 /]#crontab -e
# backup data
00 00 * * * /bin/sh /server/scripts/system_backup.sh &>/dev/null

backup server:

[root@backup /]#crontab -e
0 6 * * * /bin/sh /server/scripts/backup_check.sh &>/dev/null

You can modify the system time to verify the script, the timing was successful.
webwxgetmsgimg.jpg

5 additional knowledge

5.1 How to kill the process

The first way: kill

ps -ef|grep sshd    #查看进程号
[root@web01 ~]#ps -ef|grep sshd
root       1537   1229  0 09:06 ?        00:00:00 sshd: root@pts/0
kill 1537       # 杀掉sshd服务,有提示信息

 The second way: killall

yum install -y psmisc       # 安装killall
ps -ef|grep sshd    #查看进程号
[root@web01 ~]#ps -ef|grep sshd
root       1537   1229  0 09:06 ?        00:00:00 sshd: root@pts/0
killall sshd    #   杀掉sshd  有提示信息

The third way: pkill (blurred killer)

ps -ef|grep sshd    #查看进程号
[root@web01 ~]#ps -ef|grep sshd
root       1537   1229  0 09:06 ?        00:00:00 sshd: root@pts/0
pkill sshd  # 模糊杀掉与有sshd关系的服务       没有提示信息

 

Guess you like

Origin www.cnblogs.com/basa/p/11220190.html