Call: (480) 382-8464

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 *

Main Offers/Services

Hosting and website related services offered by Digital Crunch:



Managed VPS Hosting

Server Updates, Module/Software Installs, Firewall, Security, Hosting Management, Wordpress - let us manage it for you

Hosted Email

Setup and Maintain Business Class, Secure Email Hosting including spam protection and 25GB of storage space

Linux Consulting

Server Updates, Module/Software Installs, Firewall, Security, Hosting, Wordpress and Apps, anything related to Linux

Email Marketing Services

We broadcast your content to your list, capture leads for you, follow up on schedules, make more sales for you

Website Maintenance

Content updates, menu changes, graphics changes, adding content, getting links, building traffic, building sales funnels

Hosting Tutorials

Tutorials we've written for other customers that like to get their hands dirty and learn about hosting