[Unix-help] Help Needed

Tom Cavin cavin at MIT.EDU
Thu Feb 24 10:43:30 EST 2005


Hi Satyarth,

The "tar" command is expecting to be able to read the entire file and is
designed to tell you if something goes wrong when it is copying a file.
That is not going to change and it would be a very bad idea if it did.

Since what you seem to want to do is take snapshots of a constantly
changing file, tar is probably not the best tool to use -- or at least not
directly.

The first question that comes to mind is: how is the file changing?  If it
is a log file that is constantly growing, that is one situation.  If it is
a database that is changing in the middle as well as possibly growing, that
is a different situation.

Another aspect of this is whether the process (or processes) that is making
the changes is keeping the file open the whole time or repeatedly closing
and opening the file.

The easiest case is a rapidly growing log file in which the process opens
the file, seeks to the end, appends its information and then closes the
file.  In that case, what's in the file at the time the process appends to
it doesn't matter.  All it needs is to put its data at the end.  That case
is handled by renaming the log file and letting the process open/create a
new log.  The old log is now static and can be easily archived by tar or
any other program.

If the current contents of the rapidly changing file matter to the program,
you are talking about something like a database, and that has a different
problem.  That case requires the data to be consistent and if changes in
one part of the file need to be matched with changes in a different part,
any snapshot runs the risk of being inconsistent unless the entire process
happens between changes.  To backup a file like this you either need to
shutdown the database process (cold backup) or use something like a
transaction journal which reduces the problem to the first case of a
growing log file (hot backup).

If the file is changing and you don't care about the consistency of any
given snapshot, meaning it's okay for the snapshot to be wrong or contain
incomplete changes, what you need is a tool that doesn't do any consistency
checks, or that reads the file a block at a time (an atomic operation) and
just copies what it finds.

Depending on your particular case you have a few alternatives, and if you
supply a few more details you can get a more specific answer.

Best Wishes,

     --Tom

Satyarth Negi writes:
 > I run "tar" command ( on both Solaris/Unix) to archive a file which is
 > constantly changing in size .
 > "tar" command makes the archive but returns with error status , saying
 > "file size changed " .
 > I dont want tar command to return error status if it sees that file
 > that is being archived by it , is changing in size .
 > 
 > Thanx in anticipation  . 
 > 
 > Regards 
 > Satyarth
 > _______________________________________________
 > Unix-help mailing list
 > Unix-help at mit.edu
 > http://mailman.mit.edu/mailman/listinfo/unix-help


More information about the Unix-help mailing list