rsync files from subfolders on source to root of a folder on destination

James Robertson j at mesrobertson.com
Mon Apr 23 00:50:24 MDT 2012


I wish to sync a bunch of flac files that reside in various subfolders
to the root of a folder on a destination.

An example of the directory structure on the source is:

source> tree Music/
Music/
├── R
│   ├── Radiohead
│   │   └── OK Computer
│   │       ├── 01 - Radiohead - Airbag.flac
│   │       ├── 02 - Radiohead - Paranoid Android.flac
│   └── Red Hot Chilli Peppers
│       └── Greatest Hits
│           ├── 01 - Red Hot Chili Peppers - Under the Bridge.flac
│           ├── 02 - Red Hot Chili Peppers - Give It Away.flac

I am using this command which syncs fine but includes the directory
paths on the destination:

rsync -rltDzvh --delete -e ssh Music/ user at 192.168.1.1:/Destination/
--include="*/" --include="*.flac" --exclude="*"

So on the destination the structure is:

destination> tree /Destination/
/Destination/
├── R
│   ├── Radiohead
│   │   └── OK Computer
│   │       ├── 01 - Radiohead - Airbag.flac
│   │       ├── 02 - Radiohead - Paranoid Android.flac
│   └── Red Hot Chilli Peppers
│       └── Greatest Hits
│           ├── 01 - Red Hot Chili Peppers - Under the Bridge.flac
│           ├── 02 - Red Hot Chili Peppers - Give It Away.flac

I want to prune all directories so only the files are placed into the
root of /Destination/ e.g.

destination> tree /Destination/
/Destination/
├── 01 - Radiohead - Airbag.flac
├── 02 - Radiohead - Paranoid Android.flac
├── 01 - Red Hot Chili Peppers - Under the Bridge.flac
├── 02 - Red Hot Chili Peppers - Give It Away.flac

All the files have different names so that's ok and I have reviewed
the various options in rsync such as --no-relative but have been
unable to get it working as desired.

I also came up with:

find ./Music/ -name "*.flac" -exec rsync -ltDzvh {} -e ssh
user at 192.168.1.1:/Destination/ \;

But this means using ssh keys and is probably inefficient and if I
want to use the --delete it would likely break everything.

So how would I achieve this whilst still being able to use --delete or
--delete-excluded for times when I add, remove or rename items on my
Music library on the source and have those changes sync to the
destination?


More information about the rsync mailing list