The actual backup service project of the whole network backup project

first step: Prepare the environment

Here are three servers to achieve full network backup project as an example.
Backup Server nfs server storage web server
Hostname backup nfs01 web01
internal network IP address 172.16.1.41 172.16.1.31 172.16.1.7
external network ip address 192.168.127.41 192.168.127.31 192.168.127.7

The second step: Summary of the whole network backup needs to be achieved

1、所有服务器的打包压缩存储备份数据的目录均为/backup
mkdir -p /backup
2、要备份的文件有
	a 定时任务的配置文件(/var/spool/cron/root)【web服务器和nfs服务器】
	b 开启自启动的配置文件(/etc/rc.local)【web服务器和nfs服务器】
	c 日常脚本的目录(/server/scripts)
	d 防火墙iptables的配置文件(/etc/sysconfig/iptables)
	e 自己还想备份的文件加入()
tar -zchf /backup/system_backup_$(date +%F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables
3、web服务器站点目录假定为(/var/html/www)
tar -zchf /backup/system_backup_$(date +%F_week%w).tar.gz ./var/html/www/
4、web服务器01访问日志路径假定为(/app/logs)
tar -zchf /backup/system_backup_$(date +%F_week%W).tar.gz ./app/logs/
-h,--dereference   follow symlinks; archive and dump the files theypoint to
							将链接文件所指向的原文件进行保存备份
%w,					将日期以周几的方式记录

5、web服务器保留打包后的7天的备份数据即可(本地保存不能多于7天,清除磁盘存储)
find /backup/ -type f -mtime +7 | xargs rm 2>/dev/null
6、备份服务器上,保留每周一的所有数据副本,其他要保留6个月的数据副本
find /backup/ -type f -mtime +180 ! -name "*week1.tar.gz" | xargs rm 2>/dev/null
7、备份服务器上要按照备份数据服务器的内网ip为目录保存备份,备份的文件按时间名字保存
mkdir -p /backup/`hostname -i`
8、*需要确认备份的数据尽量完整正确,在备份服务器上对备份的数据进行检查,把备份成功或者失败的信息发给系统管理者
客户端:find /backup/ -type f -mtime -1 ! -name "finger*" | xargs md5sum > /backup/finger.txt
服务端:find /backup/ -type f -name "finger.txt" | xargs md5sum -c >/tmp/check.txt
	   mail -s "$(date +%F)备份结果." [email protected] < /tmp/check.txt
==服务端需要配置好邮件发送的功能==
ps:注意以上要求备份的目录没有的话手动创建模拟生产环境

third step, Configured to send e-mail function

Set mailbox agent sends the message:
A configuration of 163 E-mail
Settings -> POP3 / SMTP / IMAP-> Check the IMAP / SMTP service, do not check the POP / SMTP services -> Save
remember client license key
b for linux mail service Related profiles
Vim /etc/mail.rc
SET [email protected] SMTP = smtp.163.com
SET [email protected] the auth-password = SMTP-SMTP-yxb19991216 the auth = Login
Here Insert Picture Description
Here Insert Picture Description

the fourth step: Write the whole network backup script

Client

#!/usr/bin/env bash

Backup_dir="/backup"

#Ip_info=$(hostname -i)
Ip_info=`hostname -i`


#create backup dir
mkdir -p $Backup_dir/$Ip_info

# tar backup data
cd /
tar -zchf $Backup_dir/$Ip_info/system_backup_$(date +%F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables

# del 7 day ago info
find $Backup_dir -type f -mtime +7 | xargs rm 2>/dev/null

# create finger file
find $Backup_dir/ -type f -mtime -1 ! -name "finger*"|xargs md5sum > $Backup_dir/$Ip_info/finger.txt

# backup push data info
rsync -az $Backup_dir/ [email protected]::backup --password-file=/etc/rsync.password


定时执行脚本:
crontab -e
0 0 * * * /usr/bin/bash /server/scripts/backup.sh

Server

#!/usr/bin/env bash

# del 180 day ago data
find /backup/ -type f -mtime +180 ! -name "*week1.tar.gz" | xargs rm 2>/dev/null

# check backup data
find /backup/ -type f -name "finger.txt" | xargs md5sum -c >/tmp/check.txt

# send check mail
#mail -s "check backup info for $(date +%F)" [email protected] </tmp/check.txt
mail -s "$(date +%F)备份信息。" [email protected] < /tmp/check.txt

crontab -e
0 0 * * * /usr/bin/bash /server/scripts/server_backup.sh

Note: No mail function, then you can download and install
yum -y install mailx-12.5-19.el7.x86_64
premise: the need to deploy a good way to back up rsync daemon, configure profiles.
yum -y install rsync-3.1.2-6.el7_6.1.x86_64

Published 10 original articles · won praise 1 · views 198

Guess you like

Origin blog.csdn.net/yang_x_b/article/details/104253831