This is designed to work with the realtime.log files that are generated by this project: http://cumulus.tnetweather.com/projects/realtimelog. That project creates realtime.log files from the realtime.txt files uploaded to the server by Cumulus, but it doesn't ever trim the file.
This script does that. I took my existing script that rotates my realtime.log files and pulled it out of my system. All of my scripts use common config scripts to get names, places, files, folders, timezones, configs, colors and even common functions... So the result is not as tidy as the original script, but I really can't distribute the script with my configs in it.
What the script does.
o Can be run from CLI or Web (CLI = Command Line Interface). Personally, I use CLI in a crontab.
o If run by WEB, it requires a code to be provided. This prevents someone from messing with your data by calling your script via the web.
o It reads in the current realtime.log file once
o It then parses the data to find out what months data is in the file
o Next it creates a backup file of the original data into an archive directory.
o Next it writes out Archives of each of the non-current months data to the archive directory.
o Last it over writes the existing realtime.log with just the current months data.
You should like I do, only run this once a month since it will only generate the archive files if the current month is newer than data in the logfile. Personally, I run it from cron on the 4th day of the month after midnight. This ensures there is 48 hours worth of data that I use for charts, trends and things.
Permissions
If you are running this via CLI, you most likely don't need to deal with this. As your cron will most likely run as you and the files you have are owned by you.
If however, you use this via the web, the web server needs to be able to write to the files.
Specifically... Whatever you use for the archive directory most likely should have 0777 (rwxrwxrw) permissions (Note this is a directory, NOT a file). This will allow the webserver to write to new files in the directory.
The realtime.log needs to most likely need to be 0666 (rw-rw-rw-) permissions.
Settings:
The following settings are used...
Your Timezone - Ref: http://php.net/manual/en/timezones.php
Code: Select all
$SITE['timezone'] = 'America/Phoenix';
Code: Select all
$SITE['realtime_log'] = './realtime.log';
Code: Select all
$SITE['archive_dir'] = './archives/';
Code: Select all
$SITE['codeval'] = intval('SET_ME_PLEASE');
If you are trying this for the first time, PLEASE make sure you backup your realtime.log file yourself somewhere so that if it messes it up, you can recover from it. The script does make a backup, but if that file fails you may end up without any of your historical data in the realtime.log.
Backups are a smart thing to do.... Be smart!
DOWNLOAD
You can download this from my project page:
o http://cumulus.tnetweather.com/projects ... elogrotate