Added new checks and completed backup routine

This commit is contained in:
Jack-Benny Persson 2012-02-24 23:10:40 +01:00
parent e656cb33f6
commit bed265a4d7

View File

@ -1,22 +1,26 @@
#!/bin/bash
### Config options ###
BACKUP_DIRS="/home/jake/Documents/wallpaper"
DRIVE="/dev/st0"
RECHECK_WAIT=60
MT="/bin/mt"
TAR="/bin/tar"
### Functions ###
Do_backup()
{
echo "Doing backup"
echo "Doing backup..."
${TAR} -cf ${DRIVE} ${BACKUP_DIRS}
exit 0
}
Check_drive()
{
if [ ! -e ${DRIVE} ]; then
echo "No drive connected"
echo "No drive connected" >&2
EXIT_STATE=1
elif [ -e ${DRIVE} ]; then
@ -24,34 +28,49 @@ Check_drive()
EXIT_STATE=0
else
echo "Unknown error"
echo "Unknown error" >&2
EXIT_STATE=3
fi
}
Check_tape()
{
TESTTAPE=`mt -f ${DRIVE} status | grep DR_OPEN`
TESTTAPE=`${MT} -f ${DRIVE} status | grep DR_OPEN`
if [ $? == 0 ]; then
echo "No tape in drive, aborting"
echo "No tape in drive" >&2
EXIT_STATE=1
else
echo "Tape seems to exist"
echo "Tape seems to be in drive, contiuing"
EXIT_STATE=0
fi
}
Check_utils()
{
if [ ! -x ${MT} ]; then
echo "Program ${MT} dosen't seem to exist..." >&2
exit 1
fi
if [ ! -x ${TAR} ]; then
echo "Program ${TAR} doesn't seem to exist..." >&2
exit 1
fi
}
### Main routine ###
# Check if the utils/programs exists
Check_utils
# Check and repeat until the tape drive is on
EXIT_STATE=3
while [ ${EXIT_STATE} != 0 ]; do
Check_drive
if [ ${EXIT_STATE} != 0 ]; then
sleep 20
sleep ${RECHECK_WAIT}
fi
done
@ -60,6 +79,9 @@ EXIT_STATE=3
while [ ${EXIT_STATE} != 0 ]; do
Check_tape
if [ ${EXIT_STATE} != 0 ]; then
sleep 20
sleep ${RECHECK_WAIT}
fi
done
Do_backup