#!/bin/bash # The folder which should be backuped (hint: use links to backup more than one folder at a time) SOURCE_FOLDER="/opt/data/backup/backup_folders" # The device to store the tar file to LTO_DEV="/dev/st0" # Name of the Backup-Set BACKUP_NAME="full_backup" # Where to store information about used tapes TAPE_FOLDER="/opt/data/backup/tape_info" # How long to wait between tape checks (if a tape has been inserted) TAPE_DELAY="30s" # How often to try to find a tape (1440 and 30s above will lead to 12h of trying) TAPE_CHECK="1440" # Receiver of result mail MAIL="" # set maximum Tape Size MAX_TAPE_SIZE="500G" # compress tar index file (with many files the index file can grow quite big); # "y" = yes, "n" = no LOGFILE_COMPRESS="y" # # You shouldn't need to change some below here # # Todays timestamp DATE="$(date +%Y-%m-%d)" TIME="$(date +%H-%M)" # Create a temporary filename LOGFILE_BASENAME="$(mktemp -t backup_XXX)" # Search in Tape_Folder for the oldest file in the backup-set TAPE_OLDFILE="$(ls -tC1 ${TAPE_FOLDER} | tail -n 1)" MESSAGE="" # # First some general sanity checks # 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 (see TAPE_CHECK and TYPE_DELAY parameters); give up after specified tries # Hint: Format of serials is similar to 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 one 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 <