Keep local copy of nfs mount on computer
Solution 1
offline caches are one thing, but what you're asking for is more difficult. If a file is modified both on the server and on the client while the two machines are not connected, someone has to decide which version to keep, or to merge the two versions. Requiring this kind of user input when the two machines reconnect doesn't fit well into the filesystem model.
There are several NFS caching facilities, but most are designed for online caching, to speed up access. They require a communication between the server and the client when a file is modified on either side, so they're not suitable for offline scenarios. The same goes for AFS.
There are efforts to build a usable distributed filesystem supporting disconnected operation:
- Coda is a distributed filesystem with a number of advanced features, in particular support for disconnected operation. It is a relatively old project, reasonably mature, and integrated in the Linux kernel. When a client is offline, its modifications are stored in a queue. When the client reconnects, these modifications are integrated if possible, and Coda comes with tools to assist merges when conflicts occur.
- Tsumufs is a relatively new project. It adds disconnected operation on top of an existing distributed filesystem such as NFS. I don't think it's quite production-ready yet.
I'm not convinced that the filesystem is the right place to solve this problem. Conflict handling is difficult and requires user input.
For a low-tech solution, I recommend Unison, the bidirectional file synchronizer. Keep local copies of your files on both the server and the laptop. Immediately after connecting your laptop and immediately before disconnecting, run unison to synchronize the two sides. Unison will tell you if there's a conflict (and will operate silently if there isn't); as long as you always synchronize when connecting and disconnecting, there won't be a conflict.
A solution that provides more services, but does require some leearning, is to use some distributed version control software. Keep a repository on each machine, commit whenever you've changed a file, and don't forget to push/pull changes whenever possible.
Solution 2
If you want to keep the files and sync them just create a local copy and synchronize the NFS mount and your local copy using rsync.
Related videos on Youtube
user174084
Updated on September 18, 2022Comments
-
user174084 over 1 year
I mount all my home directories and what ever else on my laptop when it is on my home network. I was wondering if there is a way to keep a local copy of the nfs mount when my laptop is off the network.
A bonus would be the ability to merge changed folders and files etc.
-
tcoolspy almost 13 yearsCan you clarify if you really meant "when my laptop is on the network" or was that supposed to be off?
-
-
jmtd almost 13 yearsI think the OP is after something a bit like windows offline files; or Mac's file synchronisation, where the mechanics of this are all performed for the user, rather than by the user.
-
muffel almost 13 yearsSuch a script that does all the work can be created in minutes. Additionally something like Unison does cross-platform (bidirectional) synchronization but I would recommend using rsync any way.
-
user174084 almost 13 yearsThanks for the suggestions. I was just about to start hacking some scripts together to get my idea working but I think I can make once of these work. Thanks again.