0

I have two identical folders with subfolders for development and live like:

/development/subdirectory1
/development/subdirectory1/subsub1
/development/subdirectory2
/development/subdirectory2/subsub2
/development/subdirectory2/subsub2/subsubsub2

/live/subdirectory1
/live/subdirectory1/subsub1
/live/subdirectory2
/live/subdirectory2/subsub2
/live/subdirectory2/subsub2/subsubsub2

And I want to rsync all recent work done after a specific from development folder to live folder.

To do this, I am using

find development/ -type f -newermt '2/2/2020 0:00:00' -exec rsync -avz {} live/ \;

But what's happening is that all files from development are being copied to live folder's root even the files are in subfolders of development folder. But what I want is rsync to sync files in their exact subfolders on destination.

So, basically what I want is to perform 'rsync -avz' to update files after a specific date.

I have tried multiple solutions also to find solution, but could not. Tried with --files-from. Any thought on this?

  • Do you need a date cutoff? If you copied all files why would that be a problem? (Are there files that must not be copied, or do they get updated in the live system, or...?) – roaima Feb 12 at 10:31
  • 1
    Because there are alot of files in development folder which are not required and are there for testing only and they I do not want to copy. – Hashmi Feb 12 at 10:55
0

You can feed the set of files to be copied into a single instance of rsync. The missing part of the puzzle is to retain the source path in the destination:

find development/./ -type f -newermt '2/2/2020' |
    rsync --dry-run -vtpR --files-from - . live/

The . in the source path for find marks the point from which the path is to be retained in the destination. I've omitted your -z flag because compression is not performed when copying locally. Remove the --dry-run when you're happy it's going to do what you hope it will.

Note that rsync is not really doing anything clever here. You could equally use tar (or pax):

tar cf - -C development --newer-mtime='2020-02-02' . | tar xvf - -C live
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.