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


http://articles.slicehost.com/2007/10/10/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@172.16.251.241:/home/yjwan/bashshell/tmp


will not replicate this folder


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


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





Note:

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


like
.

[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 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-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 of
must be written as relative paths





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





so/exclude.list written as


Checkout


fire*


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@172.16.251.241:/home/yjwan/bashshell/tmp


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





executes
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
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


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.


2


--password-file=file


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.


3


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


4


–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

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.