Reputation: 13356
I'm now implementing a file system back-up and restore program under Linux. The requirement is that all the operations must be taken online.
My problem is, currently, the program has no sense of the state of files to be restored. So it is possible that some file is being edited by other application when restoration occurs, in which case, modification on the file may be overwritten by backup.
One solution that I can come up with is testting whether the file is opened by other applications before restoration and postponing restoration to the time when the file is closed. However, to test the open state of a file, I think I should traverse the /proc
file system, i.e. checking all the running process and get an open file list for each process, which is time costy.
Is there a better or classic solution to this problem? Any hints will be highly appreciated.
Thank you and Best Regards.
Upvotes: 1
Views: 453
Reputation: 3286
You can try to listen for filesystem change and see if you are responsible of those or not. inotify framework is here to help you in such task. inotify is a userland api. see wikipedia... http://en.wikipedia.org/wiki/Inotify
Upvotes: 1