-   Linux - Software (
-   -   rsync and find - how do I get the paths right? (

dormant 05-31-2010 09:56 AM

rsync and find - how do I get the paths right?
I have a problem using rsync and find together.

I want to use find to create a file list for rsync to use with the --files-from option. I need to do this because the files can be moved from the target directory at a later date, but may remain in the source directory. I can't get find to generate the right paths for rsync.

Here's a fragment of my bash script:


RSYNC="/usr/bin/rsync --archive --size-only --verbose"
find ${SOURCE} -mtime -7 > /tmp/rsync_files
${RSYNC} --files-from=/tmp/rsync_files / ${TARGET}
This recreates the full path under TARGET.

If I do this:

${RSYNC} --files-from=/tmp/rysnc_files ${SOURCE} ${TARGET}
This can't find the source files.

I need find to return the partial paths starting at the SOURCE directory, but can't see an easy way to do this.

David the H. 05-31-2010 10:15 AM

What does the path in your ${SOURCE} variable look like? Find seems to build it's output based on the directory string used. If you use an absolute path the output will have an absolute path, but if you use a relative one, it will have a relative path.

Another thing to look at, assuming you're using the GNU version of find, is the -printf option. It will allow you to format the output in various ways, so you might be able to build an appropriate output string with it.

Finally, you might want to simply use sed on your output file to change the paths to the format you want.

dormant 05-31-2010 10:23 AM

Thanks for the suggestions.

I actually just did it by cding to the source directory, then using "find .".

But I have another problem. Even though I now pass the file list to rsync, it tries to sync all the files in the source directory.

All times are GMT -5. The time now is 10:06 PM.