Skip to content

Instantly share code, notes, and snippets.

@anabarasan
Last active December 11, 2015 12:58
Show Gist options
  • Save anabarasan/4603841 to your computer and use it in GitHub Desktop.
Save anabarasan/4603841 to your computer and use it in GitHub Desktop.
Compress & Backup log file
#####################################################################
# 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