I'm trying to figure out a way to use rsync (one or more times) and possibly other commands (such as cp -lr) to accomplish the following:
- Synchronize remote folder A to local folder B
- I already have a local folder C which is a previous synchronization of A
- I want files that are unchanged between C and A to be created in B as a hard-link
- I want new files in A to be transfered back to B
- I want files that have been deleted in A, not to be hard-linked in B or hard-linked and later deleted.
- I want files that have been modified (by appending data) in A copied locally from C to B and to have only the appended bytes transfered and appended to the new copy.
A few constraints that I know to be true that may help finding a solution:
- There are 2 kinds of files in A:
- Immutable ones, which are either created new, or deleted.
- Mutable ones, which are always modified by appending data, and can also be deleted.
- These two kinds of files can be easily distinguished since each group has a fixed prefix so any commands can target either group or both.
My current solution is to use
rsync -av --link-dest C remote:A B
But this has the drawback that appended files are fully transferred increasing the volume by more than 10X.
Any improvements over this solution are welcome, and even better if all transfers are done with rsync.
NOTE: it is OK to use several rounds of rsync to achieve it, lack of atomicity in that sense is not an issue as long as C is not altered.