I have a 8GB file called php.log
with a running php script logging into it. It is important for me that I log every event, and I want to compress it and empty the current file without stopping the web server.
If I run:
mv php.log php.log.backup20140305-01
touch php.log
I will lose some of the data. How can I do this without losing any data?
Best Answer
You'll find it easier to configure
logrotate
to do the rotation for you. If you create a file called/etc/logrotate.d/php
containing something like the following, it'll handle the log rotation automatically. This is just a guide, so make sure to test and customise it before you put it into production.NB: the comments in this extract break
logrotate
syntax, so make sure to strip them out of your live config file.