#!/bin/bash # ToDos # # SOURCE_FOLDER="/opt/data/backup/backup_folders" LTO_DEV="/dev/st0" BACKUP_NAME="full_backup" TAPE_FOLDER="/opt/data/backup/tape_info" TAPE_CHECK="1440" TAPE_DELAY="30s" MAIL="backup_phex@stefan.heinrichsen.net" MAX_TAPE_SIZE="500G" DATE="$(date +%Y-%m-%d)" TIME="$(date +%H-%M)" LOGFILE="$(mktemp -t tar_output_XXX.txt)" MESSAGE="" TAPE_OLDFILE="$(ls -tC1 ${TAPE_FOLDER} | tail -n 1)" if [ ! -r $SOURCE_FOLDER ]; then MESSAGE="ERROR: Source folder does not exist or is not readable." fi if [ ! -w $LTO_DEV ]; then MESSAGE="ERROR: Output file/device does not exist or is not writeable." fi if [ ! -w $TAPE_FOLDER ]; then MESSAGE="ERROR: Tape info-folder does not exist or is not writeable." fi if [ ! -z "$MESSAGE" ]; then echo $MESSAGE; exit 1 fi # loop to wait for valid tape (check for 24h (288 time with 5 minutes delay), then give up # Format der Serieal ist: C140604093 COUNTER=0 TAPE_SERIAL="$(sg_rmsn -r /dev/st0 2> /dev/null)" EXIT_CODE=$? while [ $COUNTER -lt $TAPE_CHECK -a $EXIT_CODE -ne 0 ]; do # above check was negativ: send mail, wait and recheck echo $TAPE_SERIAL if [ $EXIT_CODE -ne 0 -a $COUNTER -eq 0 ]; then mail -s "Backup - ${BACKUP_NAME} - no tape found" $MAIL < /dev/null)" ]; then # We found an existing file. Now we check if it is the oldest file in our log-folder. if [ $TAPE_OLDFILE != $TAPE_SERIAL.log ]; then mail -s "Backup - ${BACKUP_NAME} - invalid tape" $MAIL <