Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have gone thorough similar questions on stackoverflow but they dont cover the situation that I would like to ask here.

I have all my music files on my remote machine. I would like to sync them to my local devices. Lets say that I want to sync them over my two laptops. Initially both the laptops have none of the music files. I run a simple rsync on both of them and get all the music files.

  Laptop 1 [a.mp3,b.wav,c.mp4] {-------\
                                        \----|
                                             | Server [a.mp3,b.wav,c.mp4]
                                        /----|
  Laptop 2 [a.mp3,b.wav,c.mp4] {-------/

Now I would like to maintain following rules during syncing.

  • If I delete a file on any of the laptops, the files should not get deleted on the server.
  • If I delete a file on any of the laptops, it should not get added back just because its not deleted on server.
  • If I delete a file on any of the laptops, the files should not get deleted on the other laptops. The deletion of a file is specific only to the laptop on which I deleted.
  • If I add a new file on any of the laptops, Server should get the new file. And eventually every other laptop should get this new file.
  • If I delete a file on server, it should get deleted on all the laptops.

How can I achieve the above rules with rsync? I am ready to execute more than one command on all the devices/laptops to have syncing following above rules.

Do let me know if I have not made any point clear. I will edit the question to make it more clear.

share|improve this question

migrated from stackoverflow.com Jun 14 '13 at 5:08

This question came from our site for professional and enthusiast programmers.

    
Firstly this isn't a question for stackoverflow. Secondly you won't be able to do this with rsync because of the 2nd requirement. You'll need to come up with your own solution/script. –  tink Jun 13 '13 at 3:59

1 Answer 1

Youre going to have to manually keep track of an exclusion on the laptops and then run the commands only from the laptops.

So if on laptop1 you delete a.mp3 you would add the to a file we'll call it ~/.music_exclude

# this is the file .music_exclude on laptop1
a.mp3

So then to sync any added songs TO the server except those in .music_exclude:

laptop1$ rsync -azC --exclude-from=~/.music_exclude path/to/music/ user@server:path/to/music/

To get all new music FROM the server, and process any deletions:

laptop1$ rsync -azC --exclude-from=~/.music_exclude --delete user@server:path/to/music/ path/to/music/
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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