LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Duplicating a directory tree with rsync (https://www.linuxquestions.org/questions/linux-software-2/duplicating-a-directory-tree-with-rsync-4175511183/)

AnalBeard 07-15-2014 01:24 PM

Duplicating a directory tree with rsync
 
I'm currently duplicating a directory tree with hard links with this command:

Code:

cp -aluv /path/to/sourcedir/* /path/to/destdir/
Now for the most part, all files are in subdirs under the sourcedir, but there are a few pesky files in the root of sourcedir - I'd like to exclude duplicating those. These files are all of the same type (pdf) so I could exclude .pdfs, but there will be some deeper in the directory tree which needs to be copied. Is there any way I could achieve this? I know you can provide rsync with an exclude list, but I can't see any way of achieving this with cp.

AnalBeard 07-15-2014 01:31 PM

Ok, I feel a bit daft now as I may well have sussed it:

Code:

find /path/to/sourcedir/ -mindepth 1 -exec cp -aluv {} /path/to/destdir/ \;
how does that look?

edit: ok, just tried that out, it doesn't work (and should have been obvious). Obviously it just copies all files it finds to the the root of destdir - doh. Just noticed the --parents flag, but that creates the entire directory path in destdir (so /path/to/destdir/path/to/sourcedir/)

further edit: right, so to wrap this up, I realised this was partially due to my stupidity. By changing to the sourcedir and then specifying the correct mindepth (2), I ended up with a working solution:

Code:

cd /path/to/sourcedir && find . -mindepth 2 -exec cp -aluv --parents {} /path/to/destdir/ \;


All times are GMT -5. The time now is 08:11 PM.