I’m archiving a directory. This directory has a file that is being written by another process. When I tar this using Linux tar/Perl Tar module, in the archive the entry for the file is there but the contents are null.
Before tarring the files are…
-rw-r--r-- 1 irraju dba 28 Feb 18 02:22 a -rw-r--r-- 1 irraju dba 25 Feb 18 02:23 b -rw-r--r-- 1 irraju dba 29 Feb 18 03:38 c
After untarring
-rw-r--r-- irraju/dba 28 2009-02-18 02:22:58 a -rw-r--r-- irraju/dba 25 2009-02-18 02:23:17 b -rw-r--r-- irraju/dba 0 2009-02-18 03:33:12 c
How can I fix this problem? I want the file to be in the archive with the contents it has at the instant it is archived. This file can be a log file and assume that we can not close the file handle before tarring.
As you tagged the question with ‘Linux’ there’s a chance you’re using an LVM partition. If indeed you’re running on an LVM partition, you can use the LVM snapshot feature.
Here’s a link to the relevant LVM documentation on how to perform the operation.
Here’s a part of the LVM snapshot intro: