Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple RSync EXCLUDE option?

Tags:

linux

rsync

I want a simple and working (multiple) exclude option inside my rsync command. Lets say i will exclude a file and a directory:

  • /var/www/html/test.txt
  • /var/www/html/images/

What i did is:

rsync -avz --exclude="/var/www/html/test.txt" --exclude="/var/www/html/images/" /var/www/html [email protected]:/var/www

or

rsync -avz --exclude=/var/www/html/test.txt --exclude=/var/www/html/images/ /var/www/html [email protected]:/var/www

or

rsync -avz --exclude /var/www/html/test.txt --exclude /var/www/html/images/ /var/www/html [email protected]:/var/www

..

But however, the --exclude is NOT WORKING!
Everything is going out!

  • How to do it in this simple format please?

Note: I also don't want to use external exclusion list file. Just want all in one simple command.

like image 890
夏期劇場 Avatar asked Mar 13 '13 09:03

夏期劇場


People also ask

How does rsync exclude work?

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.

How copy and exclude files in Linux?

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 dry run in rsync?

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.

Does rsync ignore hidden files?

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.


2 Answers

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:

  • "--exclude" path CAN NOT be the full absolute path!

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!

like image 133
夏期劇場 Avatar answered Oct 05 '22 22:10

夏期劇場


I personnaly like the --exclude={text.txt,images/} format.

  • Remember that with rsync, all exclude (or include) paths beginning with / are are anchored to the root of transfer which in your example will be the /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
like image 30
Pipo Avatar answered Oct 05 '22 21:10

Pipo