Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

"Short version": When a user opens a file on a local share, other users can open only in read-only, until it is closed. I want this to be true for the remote copy of the file: read-only when the local file is opened.

"Details": I have two (to begin) remote file servers (ubuntu) with windows clients (many files and directories) to automatically sync over the internet, in an ssh tunnel (the ADSL connection is pretty bad, and sometimes cut), the file system is ext4. For now I use unison at night, with force newer option and backups to avoid losing data.

I want to get synchronisation (almost) real time by avoiding conflicts, I do not want to resolve conflicts by hand, or as little as possible, because there are multiple users...

I tested unison -repeat watch locally, he forgets changes, so it is not appropriate.

But why not start unison repeatedly by cron, because its performance is fast enough when there are few files change ... My idea: if a file is opened by a user on the LAN A on server A, sends a command (chattr +i ?) that will block the same file on the server B to prevent users from network B to open it (and so to change it)

Unlock the file on server B when it is closed on A by sending a command (chattr -i ?)

And vice versa from B to A

Unlock everything locally by cron (chattr -R -i ?) to 12 h and 19 h for example, a half-day lock is acceptable

Problems: how to run the blockade? must retrieve the name and the file path with inotify... lsyncd? pyinotify? other? (monitoring must be recursive)

What if the connection is out when opening a file?

There exists a "ready-made"? Thank you for any help

share|improve this question

Why is same file access concurrently by 2 users?

If you cannot use Samba which can do some locking, then do not make it complicated and educate your users to use a VCS[1] and always "push" changes or new files to the VCS. If they work with plain-text files they would get benefit to see easily differences betweeen versions.


share|improve this answer
thanks but The users work on word, excel ... not plain-text files For example, there are several to fill a large excel file entry presences ... I use samba, but there are two different servers on two remote sites there must be the same files on each server, and it should not be any parallel versions of files, so a VCS is not the case – Klingel Feb 21 '12 at 19:04
how to samba to prevent the user at site B to modify the server B copy of the open file on server A at Site A? – Klingel Feb 21 '12 at 19:16

Your Answer


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.