Last active
December 11, 2015 12:58
-
-
Save anabarasan/4603841 to your computer and use it in GitHub Desktop.
Compress & Backup log file
This file contains hidden or 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
##################################################################### | |
# Script to compress and back up deployment server log file. | |
##################################################################### | |
# CONFIG | |
# Define the nohup file location and the location to backup the file | |
logFileName="nohup.out" | |
nohupDirectory="/home/ubuntu/DeployServer/Tornado/deploy" | |
backupDirectory="/home/ubuntu/DeployServer/Tornado/deploy/logBackup" | |
echo "initializing....." | |
NOW=$(date +"%m-%d-%Y-%H-%M") | |
fileSize=$(ls -la $nohupDirectory/nohup.out | awk '{print $5}') | |
echo nohup file size at $NOW is $fileSize | |
# check if nohup.out is greater than 100M | |
# if so copy the file, clear orignial and compress it. | |
if [ $fileSize -ge 104857600 ]; | |
then | |
echo "backing up and compressing nohup.out." | |
cp $nohupDirectory/$logFileName $backupDirectory/$logFileName_$NOW.log | |
echo '' > $nohupDirectory/$logFileName | |
gzip -9 $backupDirectory/$logFileName_$NOW.log | |
echo "backup process completed." | |
fi | |
echo "-----------------------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment