rsync explains the exclude exclusion file

  • 2020-05-09 19:43:27
  • OfStack

Question: how do I avoid synchronizing a specified folder? - exclude

rsync --exclude files and folders
http://articles.slicehost.com/2007/10/10/rsync-exclude-files-and-folders
Very common situation: I want to synchronize/down /usr /boot/, but I don't want to copy /proc /tmp these folders
If you want to avoid a path, just add --exclude
For example, exclude "proc"
- exclude 'sources'
Note: the directory path is relative to the folder you are backing up.
Note: this path must be a relative path, not an absolute path

Example: the source server /home/yjwan/bashshell has an checkout folder
[root@CentOS5-4 bashshell]# ls -dl checkout
drwxr-xr-x 2 root root 4096 Aug 21 09:14 checkou
Now what if you want to avoid copying the contents of this folder entirely?
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

Note:

1 in fact, the system will treat files and folders 1 as colleagues. If checkout is 1 file, 1 will not be copied

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

Remember not to write the absolute path as --exclude "/checkout"
Writing this way will not prevent checkout from being copied
Such as
root @ free/tmp/bashshell # rsync - av - exclude/checkout yjwan@172.16.251.241: / home yjwan/bashshell/tmp
receiving file list... done
bashshell/checkout/

You can use wildcards to avoid things you don't want to copy
Such as "fire - exclude *"
All files or folders that start with fire will not be copied
If you want to avoid copying too many files, 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 it to an absolute path.

I'm going to write 1 as a relative path

For example, I want to avoid the checkout folder and fire files

So/exclude.list is written as
checkout
fire*
Then execute the following command, noting that either -- exclude-from or -- exclude-from = is fine
But not for --exclude
rsync - av -- exclude - from = "/ exclude. list" yjwan@172.16.251.241: / home yjwan/bashshell/tmp
Check results: checkout folder and fire header files were avoided

Question: how do you calculate the number of copied files correctly?

Check the error log to see if there is any problem with replication
The total number of specific files and folders can be known when executing on the source server
ls � AlR | grep "^" [- d] | wc
Then the target server counts the number of times
Let's see if we can get the Numbers right. ok
What's going on
3 now the problem is: if I use the --exclude parameter, I will be in trouble

How do I know how many files to copy?

First of all, as mentioned in the previous command, there is a way to write only the source address and no target address, which can be used to list all the files that should be copied

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

Execute on the server side

[root@ CentOS5-4 bashshell]# rsync-av /root/bashshell/ |grep "^[-d]" | wc
62 310 4249
And ls got a result of 1
[root@ CentOS5-4 bashshell]# ls-AlR |grep "^[-d]" |wc
62 558 3731
So instead of, say, fire files, I can do this on the server side first
[root@ CentOS5-4 bashshell]# rsync-av --exclude "fire*" /root/bashshell/ |grep "^[-d]" | wc
44 220 2695
And then copy that
Look at the number of files and folders on the target machine
[root@free /tmp]# ls-AlR /tmp/bashshell/ |grep "^[-d]" |wc
44 396 2554
You know that the two are in sync

Question: 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 should be compressed after transmission, of course, the consumption of machine resources, but if the internal network transmission, the number of files is not very much, this parameter is not necessary.
2
--password-file=FILE
As mentioned earlier, this parameter can only be used if the remote machine is an rsync server
If you think an FILE is the password to log in to ssh, think again. Many people make this mistake.
3
En: Adds a little more regarding the file transfer status
4
progress: shows the of transfer transfer being files being files 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 report on each file as it's being uploaded.
I move large media files back and forth on my servers, so knowing how long the transfer has remaining is very useful.
The & # 8226; Previous Entry: nginx daily timing cut Nginx log script
The & # 8226; Next Entry: how do I open a remote account for MySQL

Related articles: