Very common situation: I want to sync some php files under/myweb, but do not want to copy some of the/myweb/log/inside the log files, because these files are too large, backup is meaningless. Now if you want to avoid a path directly add-exclude can be like-exclude "./log" –exclude './log/file '
Note: The directory path is relative to the folder backing up.
Exclude specified directories or files during rsync backup
To exclude a specified directory, you can use the –exclude-from command on the client command line
For example
rsync-vzrtopg–progress–delete–exclude-from=/home/pcfile [email protected]/back/xxx
One row for each record in the Pcfile file, with wildcard characters supported
/tmp # # Exclude root directory named TMP
. [A-z]* # # # # of hidden files that start with a point
Note: This path must be a relative path and cannot be an absolute path
Example: Source Server /home/yjwan/bashshell have a Checkout folder
[Email protected] bashshell]# LS-DL Checkout
Drwxr-xr-x 2 root root 4096 09:14 Checkou
Now want to completely avoid copying this folder content what to do?
Target Server execution
Rsync-av–exclude "Checkout" [Email protected]:/home/yjwan/bashshell/tmp
This folder will not be copied
[Email protected]/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, if Checkout is a file that does not replicate as
2 If you want to avoid copying Checkout the contents of the inside can be so written -exclude "checkout/123"
3 remember not to write the absolute path as-exclude "/checkout"
Writing this will not prevent checkout from being copied
Like what
[Email protected]/tmp/bashshell]# rsync-av–exclude "/checkout" [Email protected]:/home/yjwan/bashshell/tmp
Receiving file list ... done
bashshell/checkout/
4 You can use a wildcard character avoid content that you don't want to copy
like -exclude "fire*."
Then the fire head file or folder will not be copied.
5 If you want to avoid copying too many files, you can write this
–exclude-from=/exclude.list
exclude.list is a file that is placed in an absolute path. /exclude.list , to avoid problems, it is best to set the absolute path.
The contents must be written as relative paths.
like I want to avoid Checkout folders, and Kindle the file that preceded it
so /exclude.list 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" [Email protected]:/home/yjwan/bashshell/tmp
Check results: Did avoid the checkout folder and fire head files
Question: How do I calculate the correct number of files to compare after copying?
1 Check the error log to see if replication is a problem
2 The total number of specific files and folders that can be known in the source server execution
Ls–alr|grep "^[-d]" |WC
The target server then calculates the number of times
Let's see if the numbers are right.
Yes, no, no, no, no, look.
3 now the question is: if I use the -exclude the parameters are in trouble.
How do I know how many files to copy?
First of all, the previous command mentioned a way of writing, that is, only the source address, there is no target address of the wording, this can be used to list all the files should be copied
So with this command, you can figure out the number of files and folders under this/root/bashshell
Execute on server side
[Email protected] bashshell]# rsync-av/root/bashshell/|grep "^[-d]" | Wc
62 310 4249
and LS get the same result
[Email protected] bashshell]# ls-alr |grep "^[-d]" |WC
62 558 3731
So, for example, I don't Kindle starting file, you can calculate the file to be copied on the server side .
[Email protected] 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 on the target machine
[Email protected]/tmp]# ls-alr/tmp/bashshell/|grep "^[-d]" |WC
44 396 2554
You know 2 of them are in sync.
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, consumption of course is machine resources, but if the intranet transmission, the number of files is not many, this parameter is not necessary.
2
-password-file=file
As mentioned earlier, only the remote machine is the rsync server to use this parameter
If you think a FILE it's written. SSH login password, it is a big mistake, a lot of prisoners made this mistake.
3
–stats: Adds A little more output regarding the file transfer status.
4
–progress: Shows the progress of each file transfer. Can is useful to know if you had large files being backup up.
About this parameter:
I frequently find myself adding the-p option for large transfers. It preserves partial transfers in case of interuption, and gives a progress the report on each file as it's being uploaded.
I move large media files back and forth in my servers, so knowing how long the transfer have remaining is very useful.
Http://fukun.org/archives/09081402.html
Rsync excludes specified directories or files for synchronization