0

I am trying to create an rsync job that syncs src /foo/bar/.jpg to dest /foo/.jpg, skipping mid level directories but preserving the top level. i'm sure there is a way to do this with --include --exclude options but i haven't been able to to figure it out.

This is the src structure;

   /Volumes/ExtHDD
└── YYMMDD
    ├── foo1
    │   └── bar
    ├── foo2
    │   └── bar
    └── foo3
        ├── image1.jpg
        ├── image2.jpg
        ├── image3.jpg
        └── image4.jpg

This is what I'm aiming for at the dest;

   /Volumes/OS/Users/user/Dropbox
└── YYMMDD
        ├── image1.jpg
        ├── image2.jpg
        ├── image3.jpg
        └── image4.jpg

I have tried;

rsync -avhW --include='*.jpg' --exclude='*' src dest

but it's not even finding the .jpg files so i guess the exclude option is overriding it, however i thought there was an order of operation to the filters.

1 Answers1

0

You could just copy up the files.

src='/Volumes/ExtHDD'
dst='/Volumes/OS/Users/user/Dropbox'
dir='YYMMDD'

mkdir -p "$dst/$dir" rsync -av "$src/$dir"//.jpg "$dst/$dir/"

If YYMMDD represents a series of directories use a loop to iterate across them

for dir in "$src"/??????
do
    mkdir -p "$dst/${dir##*/}"
    rsync -av "$dir"/*/*.jpg "$dst/${dir##*/}/"
done
Chris Davies
  • 116,213
  • 16
  • 160
  • 287