Linux full-network backup project

Source: Internet
Author: User
Tags rsync webfile

Linux full-network backup project

Requirements

1. Basic Backup requirements
It is known that the host names of 3 servers are web01, backup, NFS01, and the host information is shown in the following table:
Server Description External Network IP (NAT) Intranet IP (NAT) host name
Nginx Web server 10.0.0.8/24 172.16.1.8/24 web01

NFS Storage Server 10.0.0.31/24 172.16.1.31/24 nfs01

Rsync back up server 10.0.0.41/24 172.16.1.41/24 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 the first local by day
Server Backup), the NFS storage server is the same as the WEB server, and the actual work is all the servers.
The specific requirements are as follows:
1) The backup directory for all servers must be/backup.

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

A. Scheduled Task service configuration file (/var/spool/cron/root) (for Web and Server for NFS).

B. Boot-up configuration file (/etc/rc.local) (for Web and NFS servers).

C. Directory of daily Scripts (/server/scripts). D. Firewall iptables configuration file (/etc/sysconfig/iptables).

3) WEB Server Site Directory (/var/html/www).

4) WEB Server A Access log path (/app/logs)

5) The WEB server retains the packaged 7 days of backup data (local retention cannot be more than 7 days, because too many hard drives are full)

6) 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.

7) on the backup server to the backup data server on the intranet IP for the directory to save the backup, the backup file is saved by the time name.

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.

The specific code is as follows

Client

#!/bin/bash

#---------------------------------------------------------------------

#定义变量
Hostip= ' Hostname-i|awk ' {print $} '
CD/
Varfile= "./var/spool/cron/root./etc/rc.local./server/scripts./etc/sysconfig/iptables"
Date= ' Date +%f-%a '
Webfile= "/var/html/www"
Weblog= "/app/logs"
Mkdir/backup >/dev/null 2>&1
Mkdir-p/backup/$hostip
#-------------------------------------------------------------------
#打包系统配置文件, Web site Directory, log access path
Tar-zchf/backup/${hostip}/${date}.gz.tar./$varfile
Tar-zcf/backup/${hostip}/webfile_${date}.gz.tar./$webfile
Tar-zcf/backup/${hostip}/weblog_${date}.gz.tar./$weblog
md5sum/backup/${hostip}/* >/backup/${hostip}/md5${date}.txt
#--------------------------------------------------------------------
#清理包, because you've transferred the content, and it doesn't make sense to keep it.
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
#---------------------------------------------------------------------
#通过rsync发送到备份服务器上
Rsync-a./backup/${hostip} [email protected]::backup--password-file=/etc/rsync.password >/dev/null 2>&1
If [$?-ne 0];then
echo "Backup Failed" |mail-s "NFS Backup condition" [email protected] >/dev/null 2>&1
Fi

Scheduled Tasks

Crontab-e

XX * * * */bin/bash file >/dev/null 2>$1

Service-side code

#!/bin/bash
CD/
A= (' ls backup|xargs-n1 ')
For ((i=0;i<${#A [*]};i++));d o
/usr/bin/md5sum-c/backup/${a[i]}/md5 ' date +%f-%a '. txt >>./ceshi 2>/dev/null
A= $a [a+1]
Done
/bin/mail-s "Backup Data" [email protected] <./ceshi >/dev/null 2>&1
Rm-f./ceshi
find/backup/-type f-mtime +180! -name "*mon*" | Xargs rm-f

#自动获取 the directory under/backup and is more suitable for more than one server

Scheduled Tasks

Crontab-e

XX * * * */bin/bash file >/dev/null 2>$1


Linux full-network backup project

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.