0

House Keeping the SQL Dumps

As written in my previous post, the backups had became unwieldy and needed to be archived.

So i added another script to the CronTab to run at 00:01 on the 1st of every month.

I had wanted to do a bit of math to make it see what jobs were created last month and go from there, but that wasn’t so easy.

Using the find┬ácommand i used any thing greater than 31 days as a catch all and hoped for the best…

#!/bin/sh

 

# House Keeping, archive files over 31 days old.

# Runs at 00:01 on the 1st of Every Month via a CronTab

 

find /bkp/*.tar.gz -mtime +31 -exec 7z a /bkp/archive/”$(date “+%B-%Y” -d ‘last month’)”.7z {} \;

find /bkp/*.tar.gz -mtime +31 -exec rm {} \;

 

printf “Monthly Archive Complete for “”$(date “+%B-%Y” -d ‘last month’)””%s\n” >> /bkp/logs/BackupLog.log

printf “==============================%s\n” >> /bkp/logs/BackupLog.log

Once again, a bit unwieldy, but it gets the job done.

Niall

Leave a Reply

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