Cumulus RealTimeLog Rotate Script
This is designed to work with the realtime.log files that are generated by this project: Cumulus RealTimeLog Script. 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 it Does
- Can be run from CLI or Web (CLI = Command Line Interface). Personally, I use CLI in a crontab.
- 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.
- It reads in the current realtime.log file once
- It then parses the data to find out what months data is in the file
- Next it creates a backup file of the original data into an archive directory.
- Next it writes out Archives of each of the non-current months data to the archive directory.
- 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.
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.
The following settings are used...
Timezone SettingYour Timezone - Ref: http://php.net/manual/en/timezones.php
Location of your realtime.logLocation of your realtime.log file. If the script is in the same dir as the log this should be okay.
Location of your Archive directory.Location of your archive data. If you don't have one, you will need to create it (See permissions above)
Secret Code to Prevent Unwanted RunsThe Secret Code... If you use the script via the WEB, you need to set this to a set of numbers. Letters don't work.
SAVE YOUR SELF A HEADACHE!
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!