Linux configuration file, log file full backup Tutorial-collector edition

Source: Internet
Author: User
Tags rsync webfile

Today Spring Brother Technology blog on the Linux configuration files and log file full backup of the tutorial to share, I hope to help everyone.

1, respectively set up two host to meet the test requirements

            服务器                       IP                      主机名     nginx-web服务器               192.168.10.150                     web1         备份服务器        192.168.10.20                      backup

Requirements: Every night at 00 o'clock on the WEB server packaging backup system configuration files, Web site program directory and access logs and push the backup server via the rsync command back up backup retention (backup ideas can be local by date packaging, and then pushed to backup server back up), Nginx-web server is the actual working server, the specific requirements are as follows:

1) The backup directory for the server must be/backup.

2) The system configuration files to be backed up include, but are not limited to:

A. The configuration file for the Scheduled task Service (/var/spool/cron/root).

B. Boot-up configuration file (/etc/rc.local).

C. Directory of daily Scripts (/server/scripts).

D. Firewall iptables configuration file (/etc/sysconfig/iptables).

3) WEB Server Site Directory (/home/www).

4) WEB Server access log path (/app/logs)

5) The WEB server retains 7 days of backup data after packaging (local retention cannot be more than 7 days)

6) on the backup server to the backup Web server's IP for the directory to save the backup, the backup file is saved by the time name.

7) on the backup server, keep all copies of the data for every Monday, and the other to retain a copy of the data for 6 months.

8) need to ensure that the backup data is as complete and correct as possible, check the backup data on the backup server, and send the success and failure information of the backup to the system administrator's mailbox.

2, Nginx-web service side Backup code

[[email protected]/] #vim backup.sh
#!/bin/bash
#定义变量
hostip=hostanme -I
CD/
Varfile= "./var/spool/cron/root./etc/rc.local./server/scripts./etc/sysconfig/iptables"
Date=date +%F-%a
Webfile= "/home/www"
Weblog= "/app/logs"
Mkdir/backup >/dev/null 2>&1
Mkdir-p/backup/$hostip

#打包系统要求的配置文件, Web site Directory, log directory
tar-zcf/backup/$hostip/${date}.tar.gz./$varfile
tar-zcf/backup/$hostip/webfile${date}.tar.gz./$webfile
tar-zcf/backup/$hostip/weblog
${date}.tar.gz./$weblog
md5sum/backup/$hostip/* >/backup/$hostip/md5${date}.txt

#通过rsync发送到备份服务器上
Rcyns-avz./backup/$hostip [email protected]::backup--password-file=/etc/rsync.password >/dev/null 2>&1
If [$?-ne 0];then
echo "Backup Failed" | Mail-s "Backup Status" [email protected]
Fi

#清理7天以前打包的文件
find/backup/$hostip/-type f-mtime +7-name ". Tar" | Xargs rm-f
find/backup/$hostip/-type f-mtime +7-name "Md5*.txt" | Xargs rm-f
Scheduled Tasks

[Email protected]/]# CRONTAB-E
XX */bin/bash backup.sh >/dev/null 2>&1
3. Back up server-side code

[Email protected]/]# vim jiaoyan.sh
#!/bin/bash
Date=date +%F-%a
CD/
A= ( ls /backup | xargs -n1 )
For (i=0;i< ${#A []};i++)
Do
/usr/bin/md5sum-c/backup/${a[i]/md5${date}.txt >>/jiaoyanjieguo 2>/dev/null
The ##-c option to verify the file MD5. Checksum, the checksum is based on the generated MD5. Generates the MD5 of the current file and compares it to the previously generated MD5, returns OK if it is consistent, or returns an error message
Done
/bin/mail-s "Backup Data" [email protected] <./jiaoyanjieguo >dev/null 2>&1
Rm-rf./jiaoyanjieguo
find/backup/-type f-mtime +180! -name "
mon*" | Xargs rm-f
Scheduled Tasks

[Email protected]/]# CRONTAB-E
XX */bin/bash jiaoyan.sh >/dev/null 2>&1

Note: Installation of the Rsync service in the trial reference: http://douer.blog.51cto.com/6107588/1914098

The implementation of scripting features is further optimized, such as having good ideas to share ...

This article from the Spring Brother Technology blog Official website, reproduced please indicate the source, thank you!

Linux configuration file, log file full backup Tutorial-collector edition

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.