Rsync detailed exclude exclusion file

Source: Internet
Author: User
Tags relative rsync
This article details the implementation of the exclude exclusion file in rsync, the need for friends can refer to the

question: How to avoid synchronizing the specified folder? --exclude

rsync--exclude files and folders

is a common situation: I want to sync/under/usr/boot/, but do not want to replicate/proc/tmp these folders

If you want to avoid a path to add--exclude directly

like--exclude "proc"

--exclude ' sources '

note:the directory path is relative to the folder for you are backing up.

Note: This path must be a relative path, not an absolute path

Example: The source server/home/yjwan/bashshell has a checkout folder

[root@centos5-4 bashshell]# ls-dl Checkout

drwxr-xr-x 2 root 4096 Aug 09:14 Checkou

now want to completely avoid copying the contents of this folder?

Target Server Execution

rsync-av--exclude "Checkout" Yjwan@

will not replicate this folder

[root@free/tmp/bashshell]# ls-d/tmp/bashshell/checkout

ls:/tmp/bashshell/checkout:no such file or directory


1 In fact, the system treats files and folders equally, and if checkout is a file, it will not replicate

2 If you want to avoid copying the contents of checkout, you can write--exclude "checkout/123"

3 Remember not to write as--exclude "/checkout" absolute path

This writing will not prevent checkout from being replicated


[root@free/tmp/bashshell]# rsync-av--exclude "/checkout" Yjwan@

receiving file list ... done


4 You can use wildcard characters to avoid content that you don't want to replicate

like--exclude "fire*"

so fire files or folders will not be copied

5 If you want to avoid duplication of files too much, you can write this


Exclude.list is a file, the placement of the location is the absolute path of the/exclude.list, in order to avoid problems, it is best to set the absolute path.

The contents of
must be written as relative paths

For example, I want to avoid checkout folders and fire files

so/exclude.list written as



then execute the following command, note that it can be written as--exclude-from or--exclude-from=

but not for--exclude

rsync-av--exclude-from= "/exclude.list" Yjwan@

Check results: Did avoid the checkout folder and Fire file

question: How do you calculate the correct number of files after replication?

1 Check the error log to see if there is a problem with replication

2 can know the total number of specific files and folders at the source server

ls–alr|grep "^[-d]" |WC

then the target server calculates the number of times

See if the numbers are right.

not to study what's going on

3 Now the question is: if I use the--exclude parameter, I'm in trouble

How do I know how many files to copy?

first of all, the previous command mentioned a writing, that is, only the source address, there is no target address, this method can be used to list all the files should be copied

so with this command, you can calculate the number of files and folders under this/root/bashshell

on the server side

[Root@centos5-4 bashshell]# rsync-av/root/bashshell/|grep "^[-d]" | WC

62 310 4249

The results of
and LS are consistent with the

[root@centos5-4 bashshell]# ls-alr |grep "^[-d]" |WC

62 558 3731

So, for example, I don't fire the first file, you can compute the file to be copied on the server side

[root@centos5-4 bashshell]# rsync-av--exclude "fire*"/root/bashshell/|grep "^[-d]" | WC

44 220 2695

then copy the past

look at the number of files and folders for the target machine is

[root@free/tmp]# ls-alr/tmp/bashshell/|grep "^[-d]" |WC

44 396 2554

can know that 2 is synchronized

problem: Several other common parameters of rsync

-z–compress compress file data during the transfer

--compress-level=num explicitly set compression level

--skip-compress=list skip compressing files with suffix in LIST

compression transmission, if the network bandwidth is not enough, then the transmission should be compressed, the consumption of course is machine resources, but if the intranet transmission, the number of documents is not a lot of words, this parameter is unnecessary.



said earlier, only the remote machine is an rsync server to use this parameter

If you think that file is an SSH login password, that's a big mistake.


–stats:adds a little more output regarding the file transfer status.


–progress:shows the progress of each file transfer. Can be useful to know if your have large files being backup up.

about this parameter:

I frequently find myself adding the-p option for large transfers. It preserves partial transfers in the case of interuption, and gives a progress the on each file as it ' s being uploaded.

I move large media files forth to my servers, so knowing how long transfer has remaining are very .

previous Entry:nginx The script to cut the Nginx log every day

Next Entry: How to open a MySQL remote account

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.