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