LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using rsync to copy only certain folders within a directory structure (https://www.linuxquestions.org/questions/programming-9/using-rsync-to-copy-only-certain-folders-within-a-directory-structure-886603/)

Ryanjon7 06-15-2011 05:38 PM

using rsync to copy only certain folders within a directory structure
 
Hello,

I am trying to create a simple bash script to rsync some folders within a directory stucture. I am using wild cards, in the rsync source directory structure, but my command always fails. I believe it is the way I am using wild cards within my for loop. Here is my command ;

Code:

for seq in `cat test.txt` ; do rsync -nvP /folder/folder/folder/folder/folder/**/$seq /folder/folder/folder/ ; done
This always fails, where if I do a ls to the destination, to test the path, it always works. Any help and suggestions would be appreciated

Thanks,

ryjguy7

Reuti 06-16-2011 05:01 AM

Do you expect ** to behave different from a plain *?

To get a list of source directories you could also build them beforehand by a find command. You want to have something like:
Code:

$ find /folder/folder/folder -path "*suffix1" -o -path "*suffix2"
to get a list of directories.

colucix 06-16-2011 05:15 AM

You might also consider the --exclude and --include options of rsync (or --exclude-from and --include-from if you keep the pattern in a file). If you want to sync only some of the existing directories in a path, you can do something like:
Code:

rsync -av --exclude=* --include=dir1/ --include=dir2/ --include=dir3/ source destination
otherwise if you want to list the directories to exclude, use multiple --exclude options:
Code:

rsync -av --exclude=dir1/ --exclude=dir2/ --exclude=dir3/ source destination

impert 06-16-2011 06:05 AM

If you really want to use a text file awk is probably the answer.

Ryanjon7 06-20-2011 01:02 PM

. . . Thanks for your responses and help guys.

Is there a way to tell the find command to search only for directories, and if so to create the directory structure it finds.

Thanks,

ryjguy7

colucix 06-20-2011 02:34 PM

The find command has a -type option. Using type -d you can search only directories. If you want to re-create a directory structure, you can use rsync, e.g.
Code:

rsync -av --include '*/' --exclude '*' source destination
Note the --include option with the slash after the wildcard: it includes only directories, whereas the --exclude option excludes all the rest, that is the files. Hope this helps.


All times are GMT -5. The time now is 09:00 AM.