0

I want to rSync some files / folders but i have problems with filters. This is what my source FS looks like:

.
|_ Invent/
|  |+ Comps/
|  |+ Prod/
|  |_ Other/
|_ Archive/
|  |_ Comps/
|  |_ Prod/
|  |_ Other/
|+ Comps.csv

As you've noticed, I want to sync 2 dirs and 1 file. I also want to save the dir&file structure:

./Invent/Comps/*
./Invent/Prod/*
./Comps.csv

I've tried the following command:

rsync -avze "ssh -i key_file" 
    --include "Comps.csv" 
    --include "/Invent/Comp/*" 
    --include "/Invent/Prod/*" 
    --exclude "*" 
    /source/path/ rsync@srv:/target/path/

As a result i've got a lot of trash files even not from /source/path/. What is wrong?

2 Answers 2

0

After some brain storm i found the right solution:

--exclude 'Archive' 
--include 'Invent/Comp/' 
--include 'Invent/Prod/' 
--exclude 'Invent/*'
0

Using inclusion and exclusion patterns is usually what you want to do when you are not quite sure where the files or directories are that you need to copy or avoid copying, or when you have too many pathnames to list conveniently on the command line.

Since you know exactly what paths to copy, and since it's not too many of them, I would suggest not using inclusion and inclusion patterns at all, but instead just list the paths and let rsync write them with their relative path to the destination directory using -R (or --relative):

cd /source/path || exit
rsync -av -R Invent/Comps/ Invent/Prod/ Comps.csv rsync@srv:/target/path/

Note that we need to change our working directory to the source directory first so that the paths sent to the destination are relative to the current directory.

2
  • Thx for answer. One thing i want to know is why --exclude "*" forces rsync to sync trash files not from /source/path? How it works? May be this problem is from cwRsync (rSync through cygwin in Windows). Commented Feb 25, 2022 at 7:59
  • @Kryptonit364 Using --exclude "*" would not cause rsync to include anything. It would prevent rsync from including things that have not been explicitly included by an inclusion pattern. Your question does not mention Cygwin, and I haven't used Cygwin for more than 20 years, so I can't comment on that particular variant of Unix environment. I also can't see your actual command as you have masked the source and target paths, and you never mention what "trash files" means or show any examples.
    – Kusalananda
    Commented Feb 25, 2022 at 8:38

You must log in to answer this question.

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