Tape Library Backup With Linux

1. Install tape library physically to the server
2. Perform lsscsi command to check device spec on system.

[user@server]# lsscsi -g
[0:2:0:0] disk LSI MR9260DE-8i 2.12 /dev/sda /dev/sg0
[8:0:0:0] tape IBM ULT3580-HH6 E6R3 /dev/st0 /dev/sg1
[8:0:0:1] mediumx IBM 3573-TL C.30 /dev/sch0 /dev/sg2
[8:0:1:0] tape IBM ULT3580-HH6 E6R3 /dev/st1 /dev/sg3
[8:0:1:1] mediumx IBM 3573-TL C.30 /dev/sch1 /dev/sg4
*** Charger Arm device is /dev/sg2 and /dev/sg4
*** Tape drive device is /dev/st0 and /dev/st1

3. Install MT and MTX software for tape/arm management tools.

Installed Packages
mt-st.x86_64 1.1-14.el7 @base
mtdev.x86_64 1.1.5-5.el7 @base
mtools.x86_64 4.0.18-5.el7 @anaconda
mtx.x86_64 1.3.12-11.el7 @base
*** As we need to use both MT & MTX.

4. Extract the serial from the physical tape cartridges barcode, use the serial to configuration Tape for seven day as listed below:

00001L6 for Monday,
00002L6 for Tuesday,
00003L6 for Wednesday,
00004L6 for Thursday,
00005L6 for Friday,
00006L6 for Saturday,
00007L6 for Sunday,
00008L6/00009L6/00010L6 for Backup Use.

5. Configure script on schedule to start backup to tape. Below is a sample tape backup script:

#!/bin/bash
# -------------------------------------------------------------------------
# Last updated on : 1-April-2016 - Created by Jason.
# -------------------------------------------------------------------------
LOGBASE=/var/log/tapebackup
# Backup dirs; do not prefix /
BACKUP_ROOT_DIR="Backup etc"
# Get todays day like Mon, Tue and so on
NOW=$(date +"%a")
# Tape devie name
TAPE="/dev/st0"
# Exclude file
TAR_ARGS=""
EXCLUDE_CONF=/root/.backup.exclude.conf
# Backup Log file
LOGFIILE=$LOGBASE/$NOW.backup.log
# Path to binaries
TAR=/bin/tar
MT=/bin/mt
MTX=/sbin/mtx
MKDIR=/bin/mkdir
[ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF"
#### Custom functions #####
# Make a full backup
full_backup(){
local old=$(pwd)
cd /
$TAR $TAR_ARGS -cvpf $TAPE $BACKUP_ROOT_DIR
$MT -f $TAPE rewind
$MT -f $TAPE offline
cd $old
}

# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo "Error : /$d directory does not exits!"
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}

#### Main logic ####
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
verify_backup_dirs
case $NOW in
Mon) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000001L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
Tue) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000002L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
Wed) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000003L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
Thu) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000004L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
Fri) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000005L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload ;;
Sat) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000006L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
Sun) TAPESLOT=$($MTX -f /dev/sg4 status | grep "000007L6" | awk '{print $3}'| cut -f1 -d ":")
$MTX -f /dev/sg4 load $TAPESLOT 0
full_backup
$MTX -f /dev/sg4 unload;;
*) ;;
esac > $LOGFIILE 2>&1

Be the first to comment

Leave a Reply

Your email address will not be published.


*