From f85b323f5291b4981751f5cc56fb582b5c7590bf Mon Sep 17 00:00:00 2001 From: Stefan Heinrichsen Date: Thu, 20 Apr 2017 12:20:52 +0200 Subject: [PATCH] First Version --- do_full_backup.sh | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 do_full_backup.sh diff --git a/do_full_backup.sh b/do_full_backup.sh new file mode 100755 index 0000000..7a96335 --- /dev/null +++ b/do_full_backup.sh @@ -0,0 +1,161 @@ +#!/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 <