Hi,
We want to use logrotate to rotate the logfile but due to the size of the logfile.
We want to split the file first and then truncate -s the original file to a manageable size.
Using a sample file blah.log
$ du -sh blah.log
1.0G blah.log
Then we run
split -C 100M blah.log blah.log. -d
and it produces the following files?
blah.log.00
blah.log.01
blah.log.02
blah.log.03
blah.log.04
blah.log.05
blah.log.06
blah.log.07
blah.log.08
blah.log.09
blah.log.10
PROBLEM 1:
Is there a way to let it start as 1,2,3 ... i.e. blah.log.l, blah.log.2, i.e without the leading zero and start with 1 instead of 0?
PROBLEM 2:
I am hoping that blah.log.00 contains the latest entries and blah.log.10, the oldest entries
and unfortunately, that is not the case.
Because we will be using logrotate, we need the oldest entries on blah.log.10 and the earliest ones on blah.log.00
since logrotate has the older files in the high number, isn't it?
I can't find an option for split to start with blah.log.10, then blah.log.9 etc. so I think the only
option I have is to do it manually
Or maybe someone else here have a trick that also does this? Logically, I suppose split has to start from low to high since it doesn't know how many files to split it to.
Both problems can be resolved manually or 'scripted' I believe, maybe someone in this group has done so in the past?
At the moment, I am working on renaming the splitted files using a script like below
#!/bin/bash
n=$( ls -1 blah.log.* | wc -l | awk '{ print $1 }' )
for file in $( ls -1 blah.log.* )
do
echo "mv $file blah.log.${n}"
n=$(( n - 1 ))
done
And then I just truncate -s the original blah.log file to a certain size.
BTW, while logrotate has copytruncate, I don't see an option for it to do truncate to a specific size, is that correct?
SO, copytruncate will always truncate the log file to zero size?
Any advise will be much appreciated. Thanks in advance.