New backup script debacle

A while back I made this post about the backup script I used for the file server I was using at the house at the time, a SUN Ultra 10. I went with the SUN because it was free hardware that I got from a friend and I had found a Debian flavor that would work on it but I always missed the USB support, as well as having distribution choices. When you go with SUN hardware it’s either Solaris or whatever you can find that has a SPARC port. I tended to favor OpenBSD, but Debian was the only Linux distro I could find.

A few months ago a friend at work told me about CentOS, which is a Linux distribution that was based on the Red Hat Enterprise Linux 4 Kernel (RHEL4), which is my distro of choice, so I decided to look into switching out the box with an old Intel box with Centos on it instead.

So I did this, but when I switched the drives over to the new box I kept getting a mount error. I determined that the root of the problem came from a non-clean shutdown of the SUN box, but in order to fix the problem I had to put the suspect drive in a USB enclosure and then I was able to mount and copy the files off of the drive. I guess the SCSI drivers were a little more forgiving than the IDE ones.

The problem with this whole deal was that the backups I had been taking were no good, as the tar files I had been making were corrupt, which didn’t work out very well. After I managed to recover the files I was a little suspect of using the same backup methodology, so I held off without a backup strategy.

So the time has come to implement a new backup script for this purpose, and this is the latest backup script offering I have come up with. This script simply does a file copy from one location to another, using the return code from cp to verify if the script completed correctly. In order to send myself notifications I would simply need to scrape the log of the server and look for the string “FAILED”, then email myself.

The code of the script is below, and an example execution of it would be “backup.sh “/dirtobackup””. The passed is a list of directories/files to backup which is then backed up to the variable that is specified in the script. This location can be altered by changing a variable assignment in the file. The source for the script can be copied from below or found from this link.

#!/bin/sh

# Created By:  Jason Cumberland

# Date Created: 8/26/2006

# Purpose:     Copies directories passed in first variable to backup directory

# Parameters:  $1 space spirited list of folders to backup

#Change the variables below to fit your computer/backup

FOLDERS=$1                                    # folders to back up

BACKUPDIR=/mnt/bkup/pinky                     # where to store the backups

BACKUPPROG="PINKY_BACKUP"                     # program name for message log

RETRIES=3                                     # number of retries to attempt

# app locations and configurations

BACKUP="/bin/cp -u -R --reply=yes"                   # name and location of backup program

LOG="/usr/bin/logger -t $BACKUPPROG"          # name and locaction of logger

# check to see if any folders were passed

if [ "$1" ]; then

echo "Backup starting for \"$FOLDER\""

for folder in $FOLDERS

do

$LOG "Starting backup of \"$folder\"."

$BACKUP $folder $BACKUPDIR

if [ "$?" = 0 ]; then

$LOG "Backup of \"$folder\" completed with SUCCESS."

else

$LOG "Backup of \"$folder\" completed with FAILURE."

fi

done

else

echo "No folders passed to program for backup"

fi

echo "Backup Completed"

 

One response

  1. Thank god.