Rsync only synchronizes the specified directory method (measured) _ Server other

Source: Internet
Author: User
Tags rsync

rsync Sync specified directory
Rsync uses the –include parameter and the –exclude parameter to synchronize the specified directory, and the –exclude directory is left behind.
For example:
Linux file directory

Copy Code code as follows:

Ls/usr/local/apache/htdocs/site
Aa
Bb
Cc
Dd
Ee
..
Zz

Just want to sync aa,bb,ee these three directories, other different steps.

Implementation code:

Copy Code code as follows:

/usr/local/rsync/bin/rsync-azv--include "aa/"--include "bb/"--include "ee"--exclude "/*"--progress rsync://127.0. 0.1/site/work/backup/htdocs_bak/site

Description

–include "aa/" –include "bb/" –include "EE" contains the directories you want to sync –exclude the directories that contain the different steps are specified with "/*".
–exclude "/*" excludes other directories except for –include synchronized directories
Rsync://127.0.0.1/site for you. The directory where the server is to be synchronized
/work/backup/htdocs_bak/site for your client's directory

Rsync synchronization specifies regular files (including subdirectories)

The former to do log backup, the various servers on the log synchronization to the log server to do the backup, just started more violent, all the compressed *gz files are all transferred to the log backup server. Later, found that this way is very bad, once the backup of the directory changes, the server will be all of its *gz files again, that is, waste time and give service I/O unnecessary pressure, and then want to sync only one day *gz files.

Requirements Description:
There is a directory structure similar to this, the number of subdirectories is indeterminate

Copy Code code as follows:

[Root@ind_ tlbb]# Tree
.
|--ReadMe.txt
| | | |-AUDIT
| '--money_2013-09-10.tgz
|--Audit_2013-09-10.tgz
'--Install

I want to sync *.py the end of the stuff.

After synchronization completes

Copy Code code as follows:

[Root@ind_ tlbb]# Tree
.
|--Audit
| '--money_2013-09-10.tgz
'--audit_2013-09-10.tgz

Mode 1: (failure)
Rsync-auvz–include= "*${ydate}*gz"./192.168.137.22::TLBB

Result: All files will be synchronized, even the install is in sync with the past

Mode 2:
Rsync-aruvz–include= "*${ydate}*gz" –include= "*" –exclude= "*"./* 192.168.137.22::TLBB

Results: All today's GZ files can be passed the normal pass, first allow all the matching GZ files, and then allow all subdirectories, and finally reject all other.

See the friends here, we must have found that if the folder too much, certainly more tired, directly to get a TXT file will need to sync and do not need to sync are all better, the following method in the 4.10 version of the test normal

1, only synchronization to create a directory

If the current directory folder has AA,BB,CC,DD and many other folders, we only sync aa,bb,cc

Create a new TXT file first, such as Include.txt

Copy Code code as follows:

Aa
Bb
Cc

That's all you need to write, --files-from= "Include.txt."

Copy Code code as follows:

@echo off
RSYNC-VZRTOPG--progress--no-super--files-from= "Include.txt"--password-file=wtjb51.secrets/cygdrive/g/www/ Filesjb51net/web/jb51@ip::filesjb51

2, do not sync which sync

Create a new Exclude.txt file, different steps dd folder

Copy Code code as follows:

Dd

--exclude-from=exclude.txt

You can only exclude upload files/directories using Rsync-ap--exclude=upload.
What if you want to exclude multiple files/directories?
That can only build a exclude.list, fill in the directory to exclude (one file/directory), and then Rsync-ap--exclude-from= "Exclude.list"
such as: Rsync-ap--exclude-from=/root/exclude.list 192.168.113.118::web_bak/www//data/server/www/(sync data from 118 to native)
Add
--exclude=pattern Exclude Files matching pattern
--exclude-from=file read exclude patterns from FILE
--include=pattern don ' t exclude files matching pattern
--include-from=file read include patterns from FILE

Add:
Rsync-vau--files-from= "/root/syncto.txt"--exclude-from= "/root/excludefile.txt"/data/web/root@192.168.11.12:/ data/web/in this way, where Syncto.txt writes the file to be synchronized, execludefile.txt save files that do not need to be synchronized

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.