![]() |
Auto-synchronizing a user's document directory.
Hello,
I have a user who has used one Fedora 17 workstation. Now she will use one of two machines. I currently do not have a server where both machines could have a share to. They machines might not be up at the same time, so I don't want to symbolic link the directories together. I would like to automatically synchronize the two directories by a cron job. If a file is created on one machine, I would like to see it show up on the other machine. If a file is updated on one machine, I would like to see the new version propagated to the other machine and vice versa. If a file is deleted on one machine, I don't necessarily want it deleted (right away) on the other machine in case it was accidentally deleted. Do you think I can do this with RSYNC from one machine? Anyone with experience doing this? - Raj Upadhyaya |
This is trivially easy to do, but you should take the time to read the rsync documentation so that you understand what's going on. You can always resort to google for many examples of how others do this.
|
Looks like I might have it.. I mounted the Workstation 1 file system home share under the /home/raj/c directory. Here is what I have. First, I will sync from workstation 2 to workstation 1.
Code:
rsync -a -s -t -u --numeric-ids --no-owner --no-group --progress /home/virginia/Documents /home/raj/c/virginiaCode:
rsync -a -s -t -u --numeric-ids --no-owner --no-group --progress /home/raj/c/virginia/Documents /home/virginia- Raj |
Add the Documents directory onto the end of the command:
Code:
rsync -a -s -t -u --numeric-ids --no-owner --no-group --progress /home/virginia/Documents/ /home/raj/c/virginia/Documents/Also, make sure your user knows that if they ever want to delete OR RENAME a file, they must do so on BOTH workstations in between cron jobs. You'll also want a check to make sure the remote mount is up before running these commands. |
From my root crontab.
Code:
5 0 * * * /bin/rsync -a -s -t -u --numeric-ids --no-owner --no-group /home/virginia/Documents/ /home/raj/c/virginia/Documents/- Raj |
I would put both rsync commands in a single script and run that from the cron, that way you don't run into any race condition where the second rsync starts before the first has finished. Depending on usage, you may want to run it more often than that, especially if the user will be modifying documents in both places during the day.
|
I got up early this morning, and took your advice. Instead of just wrapping the two rsync lines in a simple script, I made it more robust.. You can now execute it from the command line and increase its verbosity. Uggh. I have to get more sleep or a better hobby. Here it is. If you have a suggestion for improvement, I would appreciate it.
- Raj Code:
#!/bin/bash |
You might want to read this discussion of rsync vs unison.
(its quite short; see the latter posts) |
Chris,
I found this discussion on http://www.linuxquestions.org. http://www.linuxquestions.org/questi...8/#post4509973 I installed Unison to test it out, and it is very nice. The only difference that I saw with the RSYNC option is I could create a cron job to execute the above script a few times a day. The Unison product is a GUI implementation which nice and easy to set up. The difference that I saw that was cool was if a file was updated on both sides. If you use Unison, it prompts you to resolve the conflict and it won't automatically copy either side over the other. The RSYNC option will find the newer file (even if it is by a second) and choose that version to sync with both sides. I think given the use case of one user using one of two workstations at a time, this shouldn't happen. Well, I learned alot about Rsync, and created a BASH script that is probably 104 lines too long, but what the hey. :cool: - Raj |
Well done; sorry I seem to have dropped the link there ... ;)
Anyway, it sounded like something that might be applicable and certainly worth knowing for future ref |
Looks like you can run Unison from the command line as well without the GUI.
Quote:
I will look into this and document my findings for others reference. - Raj |
Looks like it will work as a cron job. Here is my output of the first run.
Code:
Videos$ unison -ui text -auto -batch batchpref |
Looks good; try amending a file and creating a new one and see what happens.
Also try deleting a test(!) file... |
| All times are GMT -5. The time now is 12:49 AM. |