[CentOS] OT: Testing copytruncate

Thu Nov 27 17:28:51 UTC 2008
Gerhardus.Geldenhuis at gta-travel.com <Gerhardus.Geldenhuis at gta-travel.com>

Hi

I am trying to simulate the behaviour when a file gets copy-truncated or
any other option selected in logrotate.

As a start, I have written a quick script to create values in a file at
high rate.

#!/usr/bin/perl
open FILE, ">testdata" or die $!;
for (my $i = 1; $i <= 10000000; $i++){
  print FILE "$i\n";
#  sleep 1;
}
close FILE

and a logrotate.conf file that rotates the file
/home/blah/testfileopen/testdata {
    copytruncate
    daily
    rotate 2
    size=10M
}

It works but the copy truncate messes up the file the application is
writing to... or it might be my simplistic perl script. I can't to a
head on the testdata file. A hexdump reveals some strange errors which I
believe is the cause of the problems, why I dont know.

0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
1028000 3232 3635 3235 0a31 3232 3635 3235 0a32
1028010 3232 3635 3235 0a33 3232 3635 3235 0a34


The truncated file is fine and is perfectly readable.

So I have two questions really:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Given a well written program what is the potential data loss if any
when doing a copy truncate logrotate.
and
* why does the file get such strange entries when truncated and is there
an easy fix for it?

Regards


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________