[CentOS] OT: Testing copytruncate

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


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.

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 {
    rotate 2

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.
* why does the file get such strange entries when truncated and is there
an easy fix for it?


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

More information about the CentOS mailing list