Results 1 to 4 of 4
I have custom software that writes to a sensitive large file when the user does something. I would like to make backup copies of The file that gets written to, ...
- 03-03-2009 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 7
Detect if a program is writing to a file.
I have custom software that writes to a sensitive large file when the user does something. I would like to make backup copies of The file that gets written to, but if I make a gzip of the file at the same time someone is changing something, it will corrupt the backup because some of the data will be missing, as its backed up during being written to.
a) Is there a way to detect if a file is currently being accessed/written to?
That way if its currently being accessed, I can just make the script wait until its done and then finally back it up.
b) Instead of backing up the large file while it has potential to get written to, would it be better to make a copy of the file first, then gzip the copy? This idea comes from the fact that gzipping the original takes 5-10 seconds, whereas making a copy only takes 1-2 seconds. The less time, the less chance of corruption.
c) Is there anyway to freeze a program or a file to stop it from being written to for an amount of time?
With a, b, and c together. The best solution I have to my problem would be a script that first detects rather the file is being accessed. If not, it would then freeze the file/program and then make a quick copy of it. Once the copy is created, it will unfreeze the original file/program and then go about gzipping the copy.
Do you think this is the best solution? If not, what else would you recommend?
- 03-03-2009 #2
AS far as i'm concerned ,we have inotify.a) Is there a way to detect if a file is currently being accessed/written to?
Monitor file system activity with inotify
Kernel Korner - Intro to inotify
I'm not sure any specific tool but there are tools/commads available for incremental backup.try google.Code:Instead of backing up the large file while it has potential to get written to, would it be better to make a copy of the file first, then gzip the copy?
Is there anyway to freeze a program or a file to stop it from being written to for an amount of time?
I didn't understand your question here ...if want your program to wait before accessing it use sleep.
In case you don't want other programs to access the file ,there is file lock options available with linux programming.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 03-03-2009 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 7
- 03-05-2009 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
That will not guarantee that the file integrity is sane on that concrete moment, if you STOP in the middle of something important the state of the file might be inconsistent.
You can use inotify to know when a file contents changed, then set a write lock on it until you've done reading it.
From the other side, if the program that is writing to the file is well behaved, it should also set a lock on its side so other programs can access concurrently on a smart manner without conflicting with each other.


Reply With Quote
