1. Description of the project requirements
A company has more than one server, the data is very important, if the disk is broken, the data will be lost, so the company required to backup important server data in case of problems can be restored, requirements: Every night 00 o'clock on all servers packaged backup system configuration files, Web site program directory and access log and push backup server backup with rsync command (backup ideas can be packaged locally by date and then pushed back to backup servers)
2. Specific Requirements Planning
The backup directory for all servers must be consistent/backup/
The system configuration files to be backed up include, but are not limited to:
One, the configuration file of the Scheduled task server (/var/spool/cron/root for Web server and NFS server)
Second, boot from the service configuration file (/etc/tc.local for Web and NFS server)
Iii. Daily Script directory (/server/scripts)
Iv. configuration files for firewall iptables (/etc/init.d/iptables)
1. Web Server Site Directory for example (/VAR/HTML/WWW)
2. Web server access log path for example (/app/logs)
3, the Web server retains the packaged 7 days of backup data (because the local server disk will be full)
4, the backup server, the retention of nearly 180 days of backup data, 6 months ago the data purged every Monday of data to retain
5, the backup server, to follow the backup server's intranet IP for the directory to save the backup, the backup file is saved by the time name
6, need to save the data as complete and correct as possible, the backup server on the backup data to check, the success and failure of the results of the information sent to the system administrator mailbox
3. Server Information
External network IP
Server description |
Intranet IP |
Server 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 |
tr>
rsync Backup server |
10.0.0.41/24 |
172.16.1.41/24 |
Backup |
4. Project Deployment-Build rsync server (Backup)
1. rsync Master configuration file
Cat >/etc/rsyncd.conf<<eof#rsync server# #created by Yanxinjiang .-8- the# #rsyncd. conf start# #uid=Rsyncgid=Rsyncuse chroot=Nomax Connections= $Timeout= -pid File= /var/run/Rsyncd.pidLockFILE =/var/run/rsync.Locklog File= /var/log/Rsyncd.logignore Errorsread only=falseList=falsehosts allow=172.16.1.0/ -hosts Deny=0.0.0.0/ +Auth Users=rsync_backupsecrets File=/etc/Rsync.password[backup]path= /backupeof
2, create a directory of unified backup data, add backup directory management users
Mkdir/backup-R rsync.rsync/backup/-s/sbin/nologin-m rsync
3. Create User authentication files
" rsync_backup:123456 " >/etc/ /etc/rsync.password
4. Start the Rsync service and set up boot
-I:873"rsync--daemon" >>/etc/rc.local
5. rsync client creates user authentication file
" 123456 " >/etc/ /etc/rsync.password
6, the client to verify the Rsync service push function
①nfs01 Server Authentication -avz/etc/hosts [email protected]172.16. 1.41:: Backup--password-file=/etc/rsync.passwordsending incremental file listhosts ②WEB01 Server Authentication ~] #rsync-avz/etc/hosts [email protected]172.16. 1.41:: Backup--password-file=/etc/rsync.passwordsending incremental file listhosts
5, rsync Client Write backup script (WEB01)
#!/bin/bash# name:web_backup.sh# desc:backup rsync client data info#no.1Create backup Dirbackup_dir=/Backupip= '/sbin/ifconfig eth1|awk-f"[ :]+" 'Nr==2{print $4}'' mkdir $Backup _dir/$IP-P #no.2Compress system data to BACKUP_DIRCD/&&tar zchf $Backup _dir/$IP/systemfile_info_$ (Date +%f). tar.gzvar/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables &&tar zchf $Backup _dir/$IP/www_info_$ (Date +%f). tar.gzvar/html/www &&tar zchf $Backup _dir/$IP/www_log_$ (Date +%f). tar.gz app/logs &&#no.3Create data finger info filefind $Backup _dir/$IP/-type F-name"*.tar.gz"|xargs md5sum > $Backup _dir/$IP/finger_$ (Date +%F). Txt#no.4Push data info to Rsync_server's Backup_dirRsync-az $Backup _dir/$IP [email protected]172.16.1.41:: Backup--password-file=/etc/rsync.password#no.5Delete7Day ago Data infofind $Backup _dir/$IP-type F-name"*.tar.gz"-mtime +7|xargs rm-f
6. RsyncClient Write backup script (NFS01)
#!/bin/bash# name:nfs_backup.sh# desc:backup rsync client data info# author:yanxinjiangbackup_dir=/Backupip= '/sbin/ifconfig eth1|awk-f"[ :]+" 'Nr==2{print $4}'' Date_info= ' Date +%f_%W ' #no.1Create backup Dirmkdir $Backup _dir/$IP-P #no.2Compress system data to BACKUP_DIRCD/&&Tar zchf backup/$IP/systemfile_info_${date_info}.tar.gzvar/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables#no.3Create data finger info filefind $Backup _dir/$IP/-type F-name"*${date_info}.tar.gz"|xargs md5sum > $Backup _dir/$IP/finger.txt#no.4Push data info to Rsync_server's Backup_dirRsync-az $Backup _dir/$IP [email protected]172.16.1.41:: Backup--password-file=/etc/rsync.password#no.5Delete7Day ago Data infofind $Backup _dir/$IP/-type F-name"*.tar.gz"-mtime +7|xargs rm-f
7. RsyncServer-Side Write inspection script (backup)
#!/bin/bash# name:backup_server.sh# Time: ./ ,/ the -:xx# desc:backup rsync server data info# author Yanxinjiang#no.1check data Infofind/backup/-type F-name"Finger.txt"|xargs md5sum-c >/backup/check_info.txt#no.2Send mail to Samail-S"Check_data Mail" 774181401@qq. com </backup/check_info.txt &>/dev/NULL#no.3Delete theDay ago unless Week01find/backup/-type F-name"*.tar.gz"-mtime + the! -name"*1.tar.gz"|xargs rm-f
8, write the whole network backup scheduled task1.NFS01 Server timed task authoring
#nfs01 backup Data info-cron * * */bin/sh/server/scripts/nfs_backup.sh &>dev/ NULL
2.WEB01 Server timed task authoring
#web01 backup Data info-cron * * */bin/sh/server/scripts/web_backup.sh &> dev/NULL
3.backup Server timed task writing
# Backup:backup Data Info cron xx * * * */bin/sh/server/scripts/backup_server.sh &>/dev/null
Linux operation and architecture--full-network backup project Solution