Simple Shell Backup script

I had a need to backup some Call logging/asset management software we have running on a CentOs7 install to a network location, so that we can restore, should everything go tits up.

It contains a backup of the MySQL DB’s and TARing them for moving to a new location and output to a log file.

This could probably be slimmed down immensely, but it was my 1st shell script, so it’s rough around the edges!

Here is the script.

#!/bin/sh

 

# GLPI Live Backup of SQL, WWW State currently not being backed up.

# Runs at 06:00 evry day via a CronTab

 

runat=”$(date “+%F”)”

timethen=”$(date +”%H:%M:%S”)”

 

printf “Daily Backup for %s\n” “$runat” >> /bkp/logs/BackupLog.log

printf “Start of Task. $timethen %s\n” >> /bkp/logs/BackupLog.log

printf “Create Todays Backup Folder…%s\n” >> /bkp/logs/BackupLog.log

 

mkdir /bkp/”$runat”

#mkdir /bkp/”$runat”/www

 

printf “Extracting SQL File…%s\n” >> /bkp/logs/BackupLog.log

/usr/bin/mysqldump -u glpi -p’Access to GLPI-Live 01′ glpi-live > /bkp/”$runat”/GLPILiveBackup-“$runat”.sql

 

printf “Compressing SQL File…%s\n” >> /bkp/logs/BackupLog.log

 

7z a /bkp/GLPILiveBackup-“$runat”.7z /bkp/”$runat”/GLPILiveBackup-“$runat”.sql

rm -f /bkp/”$runat”/GLPILiveBackup-“$runat”.sql

 

#printf “Creating www root archive…%s\n” >> /bkp/logs/BackupLog.log

#env pigz=-9 tar -zcvf /bkp/”$runat”/www/GLPIwwwBackup-“$runat”.tar.gz /var/www/glpi

#7z a /bkp/GLPILive-0.90.1-“$runat”.7z /bkp/”$runat”

 

printf “Copying locally to Bel-NAS-01…%s\n” >> /bkp/logs/BackupLog.log

cp –force /bkp/GLPILive-0.90.1-“$runat”.7z /mnt/bel-NAS-01/GLPI-Backups/

 

printf “Copying remotely to Bel_Del…%s\n” >> /bkp/logs/BackupLog.log

cp –force /bkp/GLPILive-0.90.1-“$runat”.7z “/mnt/bel_del/Technical Team/GLPI-Backup/”

 

rm -Rf /bkp/”$runat”

 

timenow=”$(date +”%H:%M:%S”)”

 

printf “/bkp/sql/GLPILiveBackups-“$runat $timenow”.sql.gz %s\n” >> /mnt/bel-NAS-01/GLPI-Backups/archive.txt

printf “End of Task. $timenow %s\n” >> /bkp/logs/BackupLog.log

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

This works well and using p7zip i was able to get the over all size of the 100mb SQL dump down to 8mb 4 less than Gzip or TAR.

As time wore on with this script running i had a need to tidy the out put. So done house keeping was required…

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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