Categories
Bash Check Point

Bash Script to Backup CheckPoint Log Files

bash script to tar up checkpoint log filesQuick bash script hack to take a bunch of log files and make tar/gz out of them.
You could add a SCP line in the loop and it would auto move them to the log backup server…



#!/bin/bash
# tarup files designed for tarring up a bunch of checkpoint log files
# not sure why they don't just do this, but this is the format
# we want before transferring to log backup, so...
# pulls only the unique first parts of a list of log files
# and ONLY for the current year, hoping that nobody names a random file ^%Y
# 2013-07-09_094213_1
# 2013-07-10_144108_2
# 2013-07-11_091531_3
# etc
# get real year
RYEAR=$(/bin/date +'%Y')
# make them type the year, assuming they've checked for other files
YEAR=$1
[ $# -eq 0 ] && { echo "Usage: $0 $RYEAR\n"; exit 1; }
# we have the year, get the unique file name portion from something like:
#2013-07-10_144108_2.log
#2013-07-10_144108_2.logaccount_ptr
#2013-07-10_144108_2.loginitial_ptr
#2013-07-10_144108_2.logptr
#2013-07-11_091531_3.log
#2013-07-11_091531_3.logaccount_ptr
#2013-07-11_091531_3.loginitial_ptr
#2013-07-11_091531_3.logptr
# into something like this:
# 2013-07-10_144108_2 2013-07-11_091531_3
# assuming that only something with YYYY_etc.log for our regex/test
for FILE in `ls $YEAR*.log|awk 'BEGIN { FS = "." }; { print $1 }'`; do
        # let the user know what's going on
        echo creating $FILE.gz
        # tar/gz to a temp file tarring log, ptr, accounting, etc
        echo nice -19 tar cvzf t_${FILE}.gz `ls ${FILE}.*`
        # delete the others
        echo rm $FILE.*
        # rename it back to original
        echo mv t_${FILE}.gz ${FILE}.gz
done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.