Linux configuration file, log file full backup
1, respectively set up two host to meet the test requirements
Server |
IP |
host name |
nginx-web server |
192.168.10.150 |
 WEB1 |
&NB Sp Backup Server |
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# defines the variable 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>&1mkdir -p /backup/$hostip # Package system requirements for configuration files, Web site directories, Log directory tar -zcf /backup/$hostip/${date}.tar.gz ./$varfiletar -zcf /backup/$hostip/ webfile_${date}.tar.gz ./$webfiletar -zcf /backup/$hostip/weblog_${date}.tar.gz ./$ weblogmd5sum /backup/$hostip/* > /backup/$hostip/md5${date}.txt# sent to the backup server via Rsync rcyns - avz ./backup/$hostip [email protected]::backup --password-file=/etc/rsync.password > /dev/null 2>&1if [ $? -ne 0 ];then echo "Backup Failed" | mail -s "Backup condition" [email protected]fi# Clean up files packaged 7 days ago find /backup/$hostip/ -type f -mtime +7 -name "*.tar*" | xargs rm -ffind /backup/$hostip/ -type f - mtime +7 -name "Md5*.txt" | xargs rm -f
Scheduled Tasks
[Email protected]/]# crontab-e00 * * */bin/bash backup.sh >/dev/null 2>&1
[[email protected]/]# vim jiaoyan.sh#!/bin/bashdate= ' 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 ##-c option to verify file MD5. Checksum, the checksum is based on the generated MD5. Generate the MD5 of the current file, compare it to the previously generated MD5, return OK if it is consistent, or return an error message Done/bin/mail-s "Backup Data" [email protected] <./jiaoyanjieguo >dev /null 2>&1rm-rf./jiaoyanjieguofind/backup/-type f-mtime +180! -name "*mon*" | Xargs rm-f
Scheduled Tasks
[Email protected]/]# crontab-e00 * * */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 ...
Reference Document: http://caojiaoyue.blog.51cto.com/11798573/1923404
This article is from the "Mq_douer" blog, make sure to keep this source http://douer.blog.51cto.com/6107588/1928295
Linux configuration file, log file full backup