I want a simple and working (multiple) exclude
option inside my rsync
command. Lets say i will exclude a file
and a directory
:
What i did is:
rsync -avz --exclude="/var/www/html/test.txt" --exclude="/var/www/html/images/" /var/www/html root@xx.xx.xx.xx:/var/www
or
rsync -avz --exclude=/var/www/html/test.txt --exclude=/var/www/html/images/ /var/www/html root@xx.xx.xx.xx:/var/www
or
rsync -avz --exclude /var/www/html/test.txt --exclude /var/www/html/images/ /var/www/html root@xx.xx.xx.xx:/var/www
..
But however, the --exclude
is NOT WORKING!
Everything is going out!
Note: I also don't want to use external exclusion list file. Just want all in one simple command.
The --exclude-from rsync option allows us to specify a file that contains a list of directories to be excluded. The file should be plaintext, so a simple . txt file will do. List one directory per line as you're compiling the list of directories that you want to exclude.
Using cp In this case, we get a list of files & folders to be copied using ls command, and use grep command to exclude files & folders. We pass this list to cp command for copying. Here exclusion is done by grep command and not cp command.
What is rsync –dry-run? “–dry-run” option allows the rsync command to run a trial without making any changes—most of the time, this process the same output as the real execution. The rsync command is combined with various options to specify what the rsync command will do before someone can execute it.
Using the rsync Command rsync is a powerful and convenient file-copying utility. It accepts two valuable options that allow us to include or exclude files during the copy: –include=PATTERN and –exclude=PATTERN. To skip hidden files and directories, we can pass the “. *” pattern to the –exclude option.
i got it solved by myself after i've learned and tested many times. The real problem was the understandable (for me) --exclude
option usage format.
I don't know how others are doing but i just found out that:
Because i was using the path(s) like: --exclude /var/www/html/text.txt
which caused the thing DOES NOT work. So i used like:
--exclude text.txt --exclude images/
.. and it WORKS!
I personnaly like the --exclude={text.txt,images/}
format.
/var/www/html
directory!!, so if you specify /text.txt
it will be only the file which is @ the root of your transfer directory not above in the tree. You can find more infos and examples here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With