Is it possible with rsync to not create directories on destination?

Imagine I have that source :

a/
a/x.txt
b/
b/y.txt

And that I have this destination :

a/
a/z.txt

The wanted result of rsync source destination :

a/
a/x.txt
a/z.txt

Of course my real situation involves thousand files/folders structure and I don't want solutions involving explicit list of synced folders, which I can do. I'm looking for a clean way just to prevent any folder creation on destination. By exclude or filtering... That could even be something outside rsync, like a hack with permissions if rsync can't do this...


For information, this is really easy to get this kind of situations, in my case I have:

  • A server with 2 disks, let's say A & B. And a local drive C.
  • I usually use rsync to sync (and merge) remote A & B into local C.
  • Then sometimes I just want to sync back some C files into A and B. (Just new Files... not non-existing folders on destination)
link|improve this question
rsync alone cant do this, I think (the option --ignore-non-existing would skip files and folders). You need to execute multiple steps to achieve that. – mana Jul 28 '11 at 10:31
that's what I'm afraid of... but that reallly sounds strange that rsync can't do this. I do not think it is technically hard to implement and that it is a common need. But maybe I'm wrong. Next step w/o an answer > rsync mailing list... – Vincent Jul 28 '11 at 11:17
I'd be interested in seeing the solution if you find one. I'm out of ideas myself atm. – jw013 Aug 3 '11 at 10:01
feedback

1 Answer

maybe do a normal rsync and then in a second step delete all newly created folders ... sound dangerous.

To increase the safety of this operation you can use another user than the one on the destination system:

rsync $src $specialuser@server:$destination

Deleting the remotely created folders by that user:

ssh $normalUser@destination "find $destination -type d -user $specialuser -exec rm -r {} \;"

And then set the permissions back to normal:

ssh $normalUser@destination "chown -R $defaultUser:$defaultGroup $destination"

damn, this looks dirty ... this needs some serious improvements :D

link|improve this answer
good idea, but as you said, and as I was expecting from these kind of solutions... looks a bit dirty/dangerous! :) I'm really surprised that rsync does not look like capable of this OTB. – Vincent Jul 28 '11 at 17:43
feedback

Your Answer

 
or
required, but never shown

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