Shell Script for Tape backup


Symptom: To initiate backup from disk to tape in shell script.

Solution:

#!/bin/bash

BAK=/data2

 TAPE=/dev/st0

 echo ” Trying to backup ${BAK} directory to tape device ${TAPE} ..”

 # See if $BAK exits or not else die

# Set unsuccessful shell script termination with exit status # 1

[! -d $BAK ] && { echo “Source backup directory $BAK not found.” exit1;} 

# See if $TAPE device exits or not else die

# Set unsuccessful shell script termination with exit status # 2

[! -b $TAPE ] && { echo  “Backup tape drive $TAPE not found or configured.” ; exit 2; }

 # Okay back it up

tar cvf $TAPE  $BAK  2> /tmp/error.log

if [$? -ne 0]

then

 

# die with unsuccessful shell script termination exit status # 3

 

 echo “An error occurred while making a tape backup, see /tmp/error.log file”

 exit 3

fi

# Terminate our shell script with success message i.e. backup done!

exit 0

Save and close the file. Run it as follows:

chmod +x datatapebackup.sh

./datatapebackup.sh

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: