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
--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
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@172.16.251.241:/home/yjwan/bashshell/tmp
receiving file list ... done
4 You can use wildcard characters to avoid content that you don't want to replicate
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@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
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