2

First of all, I really read a lot about this topic (including Rsync filter: copying one pattern only), but I still don't understand, or I have a problem with my installation...

My structure "from" is something like this:

Windows
Users
  User1
    Documents
      doc1.txt
      doc2.txt
    AppData
    Downloads
  User2
    Documents
      doc3.txt
      doc4.txt
    AppData
    Downloads

I want to backup all Documents folders and subfolders from all users, but not AppData and Downloads structures.

On the destination I want:

Users
 User1
  Documents
   doc1.txt
   doc2.txt
 User2
  Documents
   doc3.txt
   doc4.txt

I did tried many patterns, but none are working well. Let's start with this one:

rsync -av --include="*/" --exclude="*/AppData" --exclude="*/Downloads" /source/Users /destination

What should I do to exclude AppData and Downloads folders and subfolders for each user ?

Thanks

There is another thread discussing almost the same thing (if I well understand it): rsync with absolute paths and excluding subpaths

I adapted the answer to my situation, but the AppData and Downloads are still present on the destination path.

rsync -av --no-p  --include="*/" --include="*/Documents/**" --exclude="** /source/Users /destination
5
  • Try ** instead of *.
    – muru
    Feb 16, 2015 at 16:58
  • exclude="**/AppData" gave me the same result. (by the way, I'm using rsync 3.1.1). I'm also quite confused this the usage of *. I even saw in some command lines test/***...
    – huotg01
    Feb 16, 2015 at 17:10
  • rsync -avr --exclude="AppData" --exclude="Downloads" /source/Users /destination
    – Costas
    Feb 16, 2015 at 18:12
  • @Costas What the hell! That simple ? It works as expected...Thanks. One more question: in this specific case, if I want to obtain the same result (copying Documents folders for all users), could I exclude everything but Documents ?
    – huotg01
    Feb 16, 2015 at 19:10
  • I think much easy to select Documents directly by rsync -av /source/Users/User*/Downloads /destination
    – Costas
    Feb 16, 2015 at 21:05

1 Answer 1

2

In many shell * do not include / symbol (rather than ahead .) (see man 7 glob and globstar|dotglob options in shopt) , so if you want to exclude AppData and Downloads you should provide full path from source (--exclude="*/*/AppData" --exclude="*/*/Downloads") or just remain name only (--exclude="AppData" --exclude="Downloads") if does not matter on which level directories is situated.

rsync -av --exclude="AppData" --exclude="Downloads" /source/Users /destination

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .