Created
February 21, 2018 08:49
-
-
Save christiannageby/d09ab68dfb8ecdf0e53a901197112c26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# README: This script is a log-archive tool wich compresses the logs in to weekly-archives and puts the Weekly archives in to monthly archives. | |
# README: The script also deletes the montly archives after a 6 months | |
# README: ------------------------------------------------------------------- | |
# README: How the script Works: | |
# README: Setup two Cron-jobs one weekly whch runs the script without any parameters | |
# README: And a monthly wich contains the parameter 'Monthly'. | |
#!/bin/bash | |
# Change directory to where the logs is stored (/storage/logs/apache/error) | |
cd /storage/logs/apache/error/ | |
# Determine if the script is a weekly rotation or a monthly. | |
# If the a commandline parameter is set assume there is a monthly rotation. | |
if [$1 == ''] | |
then # Weekly Run | |
zip -R /storage/logs/apache/error/archive/log-$(date + '%Y-%m-%d').zip '*.log' #Compress all logs into weekly archive | |
rm -rf *.log # Remove all logs that has been compressed | |
else # Monthly Run | |
cd storage/ # Change into storage directory | |
zip log-$(date +'%Y-%M').zip log-$(date + '%Y-%m')-*.zip #ZIP all weekly logs to a monthly log | |
rm log-$(date -d "-6 month" +'%Y')*.zip # remove all logs older than 6 months | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment