Rsync How to exclude file synchronization-specified folders

Source: Internet
Author: User
Tags centos rsync


Very common situation: I want to sync//usr/boot/, but do not want to copy/proc/tmp these folders

If you want to avoid a path directly add –exclude

Like –exclude "Proc."

–exclude ' Sources '

Note:the directory path is relative to the folder and you are 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 root 4096 Aug 09:14 Checkou

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

Target Server execution


Rsync-av--exclude "Checkout" yjwan@172.16.251.241:/home/yjwan/bashshell/tmp
This folder will not be copied

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

LS:/tmp/bashshell/checkout:no such file or directory
Attention:
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" such absolute path

This writing will not prevent checkout from being copied

Like what

[root@free/tmp/bashshell]# rsync-av–exclude "/checkout" yjwan@172.16.251.241:/home/yjwan/bashshell/tmp

Receiving file list ... done

bashshell/checkout/
4 You can use wildcard characters to avoid content that you don't want to copy

Like-exclude "fire*."

Then the fire file or folder will not be copied.

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

--exclude-from=/exclude.list
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 must be written as a relative path.
Like I want to avoid checkout folders and fire files.
So/exclude.list is written as

Checkout

fire*

Then execute the following command, note that writing as –exclude-from or –exclude-from= can be

But not for –exclude.

Rsync-av–exclude-from= "/exclude.list" yjwan@172.16.251.241:/home/yjwan/bashshell/tmp

Check results: Really avoids the checkout folder and the fire file

Question: How do you calculate the correct number of files after replication?
1 Check the error log to see if there is something wrong with the copy

2 The total number of specific files and folders that can be performed at the source server

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

The target server then calculates the number of times

Let's see if the numbers are right.

No, no, no, look again.

3 The question now 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

Executing on the server side

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

62 310 4249

Consistent with the results of LS.

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

62 558 3731

So, for example, I don't want to 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

And then copy the past.

The number of files and folders to look at the target machine is

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

44 396 2554

You know, 2 are synchronized.

Problem: Several other common parameters of rsync
1

-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

Compressed transmission, if the network bandwidth is not enough, then should be compressed later transmission, 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.

2

–password-file=file

As mentioned 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 back and forth to my servers, so knowing how long the transfer has remaining is very useful.


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

Check the error log to see if there is a problem with replication
The total number of specific files and folders that can be performed at the source server
Ls–alr|grep "^[d]" |WC
The target server then calculates the number of times
Let's see if the numbers are right.
No, no, no, look again.
Now the problem 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 way of writing is only the source address does not have the target address of the writing can be used to list all the files should be copied

Then use this command to calculate the number of files and folders under this/root/bashshell

Executing on the server side

[Root@centos bashshell]# rsync av/root/bashshell/|grep "^[d]" | Wc

Consistent with the results of LS.
[Root@centos bashshell]# ls AlR |grep "^[d]" |WC

So, for example, I don't want fire. The first file can be used to compute the file to be copied on the server side
[Root@centos bashshell]# rsync av exclude "fire*"/root/bashshell/|grep "^[d]" | Wc

And then copy the past.
The number of files and folders to look at the target machine is
[root@free/tmp]# ls alr/tmp/bashshell/|grep "^[d]" |WC

Can know that the person is 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.