Linux-rsync Project Combat (verbose) Backup full-network server data Production architecture scheme

Source: Internet
Author: User
Tags naming convention rsync

Requirements are as follows:
Every night 0 o'clock on NFS Server A (rsync client), package the backup Site Program directory (/var/www/html)
Push to Server B by using the rsync command to save the backup
Specific requirements:
1.NFS servers and backup servers their backup directories are backups.
2.NFS Server site assumed to be/var/www/html
3.NFS server locally reserved for 7 days of backup
4. Check the backup results on the backup server send daily results to the administrator (no mailbox software required) SendMail
5. Every Saturday data on the backup server retains the remaining 180 days
1. First deploy NFS, share the/var/www/html directory to the Web Administrator (WebAdmin)



Mount succeeded: (NFS Deployment succeeded)

2. Create a backup directory on the backup server and on the NFS server

3, NFSServer/var/www/html Packaging compression synchronization to the/backup directory, each backup of the packaged backup file only for seven days:
tar-zchf/backup/html.$ (date +%f%w-d ' -1day '). tar.gz/var/www/html/

Note:The tar h parameter is to treat the symbolic link file as a normal file or directory, thus packaging the source file,%F the full date format%w the day of the Week (0-6), 0 for Monday, $ read the specific number of days as the backup file name, so that the purpose is to do not duplicate names,-d '-1 Day ' If it's a backup today, it's also today, so get rid of it.
Find/backup-name ". tar.gz" –mtime +7-type F |xargs rm–f
Note: –mtime parameter: The last modification occurred within n days, the current time is within N24 hours
Find the/backup directory with the suffix. tar.gz to create a file that reaches 7 days, delete this file, Xargs command is a filter that passes parameters to other commands, line breaks and whitespace will be replaced by spaces.

4, before the backup directory push, add fingerprint information to facilitate the verification of the service side, provided that the client path to create the fingerprint and the server side path is the same can be
Why to add a fingerprint: to generate logs, the administrator will see the results of the backup more visually
[Email protected] backup]# find/backup/-name '. tar.gz ' |xargs md5sum >/backup/check.txt
[Email protected] backup]# md5sum-c check.txt

Isn't it intuitive to see OK

5. Push back the compressed file to the Rsync backup server, push the complete data to the directory specified by the module
rsync-avz/backup/[Email Protected]::backup--password-file=/etc/rsync.password

View push on Backup server: (Push succeeded)

Automation: After testing the command on the client, you need to write a script to automate operations!
The script is as follows:

Configure Cycle Jobs: (Automatically execute scripts for backup every 0 o'clock in the evening)
Crontab–e//write cycle jobs

Next is the backup server side:
1, the backup server [every Saturday of data is retained], the other backup only keep 180 days backup

find/backup/-name ". tar.gz"! "6.tar.gz"-mtime +180–type F |xargs rm–rf

Note:
remove all suffixes that are not 6.tar.gz (because the previous backup file naming convention is%f%w so that 6 represents each Saturday) and the file has a backup file with a number of days greater than or equal to 180 days.

2, the backup server to check the backup results are normal, and the daily backup results sent to the administrator mailbox
(1) First modify the local send-mail configuration file to all:

(2) Restart mail Service
Systemctl restart Postfix

(3) Send mail to admin
-S indicates the message header
Root accepted user @ behind can be followed by IP address or domain name
If sent to QQ mailbox format: [email protected]
Test success:

3, finally in the backup server to achieve automated operation and maintenance:
(1) Writing Automation scripts:

(2) Configuration cycle operation:
Crontab-e

Summarize this experiment:
Problem encountered: Date +%f%w-d ' -1day ' named file has failed to get time correctly
Workaround: After several tests, it was finally found that a $ sign was required to read the time taken by this function.
If the rsync configuration file will not do, please see my previous blog, the wrong place also please review the guidance, thank you here!

Linux-rsync Project Combat (verbose) Backup full-network server data Production architecture scheme

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.