0

Im trying to rsync all the .PHP and .HTML files from any directory inside of /home/ . However in /home/site2/public_html/cache_old/ there are .html files that i do not want to include in the sync (thus i want to exclude that directory and any of its sub-directories)

Here is the best rsync command i can come up with (after lots of testing and failures):

rsync -avv /home/ /ssd/rsyncPHPsFORmtree/ --include '*/' --include '*.html' --include '*.php' --exclude /site2/public_html/cache_old/* --exclude '*'

Im convinced that my rsync command is not formatted properly based upon this output from when rsync is running:

[sender] showing file site2/public_html/cache_old/total_pages/s/e/a/r/c/page99.html because of pattern *.html

[sender] showing file site2/public_html/cache_old/total_pages/s/e/a/r/c/Page4.html because of pattern *.html

[sender] showing file site2/public_html/cache_old/total_pages/s/e/a/r/c/searchHe107.html because of pattern *.html

[sender] showing file site2/public_html/cache_old/total_pages/s/e/a/r/c/page18.html because of pattern *.html

Thanks

2
rsync -avv /home/ /ssd/rsyncPHPsFORmtree/ --exclude '/site2/public_html/cache_old/' --include '*.html' --include '*.php' --include '*/' --exclude '*'  

This should do it.
The order of the filers is important. The 1st matching rule applies. So you exclude the folder 1st, then include the files you want, then include directories that weren't previously excluded, then exclude everything else.

  • Thanks for the fast reply, however re-ordering did not make any difference. When running its still "showing" sub directories of directoryes that --excluded.... also in your reply you didnt have --include '*/' (running the command without it, it quickly just eliminates every folder and transfers / does nothing) – James Gaul Dec 25 '15 at 8:56
  • rsync is a tool designed to backup things, so I don't think it's necessary to tell it --include '*/'. I've tested the command here and seemed to work just fine. maybe you can just copy the command from my reply and see if it makes a difference? besides reordering the arguments, I also made some minor changes(quotes, * at the end of the path etc. ) – David Dai Dec 25 '15 at 9:07
  • I was able to get it to work properly by following your exact rsync command in your answer. One important change i also made that seemed to help was to use --exclude '*/cache/' versus before i was trying to directly --exclude each cache folder (there are about 5 i need to have excluded)... With this change and following your example, my own rsync command is properly ignroing the folders i need it to and syncing just the PHP and HTML files Thanks! (btw i did still need the --include '*/' else rsync wouldn't recourse past the first folders in /home) – James Gaul Dec 25 '15 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.