From 04998e6f5b235142481290435711e3b85b5cc410 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Wed, 13 Jan 2021 16:12:45 +0100 Subject: [PATCH] add backup type auto; updates and fixes in output --- .gitignore | 1 + check_clientbackup.sh | 11 ++++++++--- jobhelper.sh | 13 +++++++++++-- jobs/backup.job.dist | 12 ++++++++++-- restore.sh | 20 ++++++++++---------- scheduler.sh | 13 ++++++------- transfer.sh | 14 +++++++++----- 7 files changed, 55 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index fe08cd8..6b5ad9a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # ignored configs # ---------------------------------------------------------------------- jobs/*.job +logs/auto-* logs/full-* logs/inc-* logs/transfer-* diff --git a/check_clientbackup.sh b/check_clientbackup.sh index fc3724e..d01480d 100755 --- a/check_clientbackup.sh +++ b/check_clientbackup.sh @@ -46,7 +46,7 @@ else iMaxAgeInHours=`j_getLastBackupAge` echo verify last backup: $iMaxAgeInHours h ago - for logfile in `ls -1t $logdir/inc*.log $logdir/full*.log 2>/dev/null | head -1` + for logfile in `ls -1t $logdir/inc*.log $logdir/full*.log $logdir/auto*.log 2>/dev/null | head -1` do echo LAST BACKUP: $logfile grep "final.*rc=" $logfile @@ -87,13 +87,18 @@ else # --- changes (incremental backups only) and backup status infos echo - sSearch="|Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize" + sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize" echo $logfile | fgrep "inc" >/dev/null if [ $? -eq 0 ]; then - sSearch="[ADM]\ ${sSearch}" + sSearch="[ADM]\ |${sSearch}" fi + echo --- changes: egrep "^(${sSearch})" $logfile + echo + echo --- summary of backed up directories: + grep "DIR\ " $logfile + sShort="$sShort - OK: $iOK ... Errors: $iError" done diff --git a/jobhelper.sh b/jobhelper.sh index 7d8d2f2..1c45f7b 100755 --- a/jobhelper.sh +++ b/jobhelper.sh @@ -292,13 +292,22 @@ function j_read(){ BACKUP_TARGETDIR=`_j_getvar ${JOBFILE} "dir-local-dumps"` JOBDEF_TYPE=`_j_getvar ${JOBFILE} "type"` - if [ -z $JOBDEF_TYPE ]; then - JOBDEF_TYPE=inc + if [ -z "$JOBDEF_TYPE" ]; then + JOBDEF_TYPE=auto fi JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"` JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"` + JOBDEF_AUTO=`_j_getvar ${JOBFILE} "auto"` + if [ "$JOBDEF_TYPE" = "auto" ]; then + if [ -z "$JOBDEF_AUTO" ]; then + JOBDEF_AUTO=1W + fi + else + JOBDEF_AUTO= + fi + bIsTodayInc=`_j_isToday $JOBDEF_INC` bIsTodayFull=`_j_isToday $JOBDEF_FULL` diff --git a/jobs/backup.job.dist b/jobs/backup.job.dist index 99b05b4..9d904b6 100644 --- a/jobs/backup.job.dist +++ b/jobs/backup.job.dist @@ -12,7 +12,9 @@ # # ---------------------------------------------------------------------- -type = inc +# type = inc +type = auto + lang = en_us # ---------------------------------------------------------------------- @@ -20,12 +22,18 @@ lang = en_us # for inc and full you can set # DOM:06,22 - days of month # DOW:Mon,Fri - weekdays -# WDM:WDM:1st Fri - nth weekday in month +# WDM:1st Fri - nth weekday in month # ---------------------------------------------------------------------- inc = DOW:Mon,Tue,Wed,Thu,Fri,Sat,Sun + +# full backups for type = inc full = WDM:3rd Fri +# full backups for type = auto +# auto = <time> i.e. 1M +auto = 1M + # --- when to start every day? # incremental jobs diff --git a/restore.sh b/restore.sh index 1fee351..4fc0993 100755 --- a/restore.sh +++ b/restore.sh @@ -460,39 +460,39 @@ h1 "RESTORE - GET FILES FROM STORAGE" echo color input - echo -n "Select and Return --> " + echo -n "Select (not case sensitive) --> " color reset read action echo case $action in - d) + d|D) enterBackupDir ;; - t) + t|T) enterDate ;; - c) + c|C) showFilechanges ;; - s) + s|S) searchFile ;; - v) + v|V) verify ;; - b) + b|B) echo type exit to return... export PS1="[`basename $0` \u@\h \w]\$ " bash ;; - w) + w|W) enterRestoreitem ;; - r) + r|R) doRestore ;; - x) + x|X) exit 0 ;; *) diff --git a/scheduler.sh b/scheduler.sh index e6c6186..1104e35 100755 --- a/scheduler.sh +++ b/scheduler.sh @@ -45,14 +45,12 @@ cat << EOFschedulerinfo - Job data - - Incremental backup: $JOBDEF_INC at `_j_getvar ${JOBFILE} "start-time-inc"` - Full backup : $JOBDEF_FULL at `_j_getvar ${JOBFILE} "start-time-full"` + execution times: $JOBDEF_INC at `_j_getvar ${JOBFILE} "start-time-inc"` + Full backup : $JOBDEF_FULL at `_j_getvar ${JOBFILE} "start-time-full"` do today = $JOB_DOTODAY - type = $JOBDEF_TYPE + type = $JOBDEF_TYPE $JOBDEF_AUTO starttime = $JOBDEF_STARTTIME stopfile = $JOB_DONEFILE @@ -68,6 +66,7 @@ EOFschedulerinfo # check: Backup bereits gelaufen? ls -l ${JOB_DONEFILE}.* 2>/dev/null if [ $? -eq 0 ]; then + echo echo "ABORT: $JOB_DONEFILE was found" bStart=0 else @@ -76,7 +75,7 @@ EOFschedulerinfo if [ ${JOBDEF_STARTTIME} -gt ${mytime} ]; then - echo "INFO: waiting for ${JOBDEF_STARTTIME} ..." + echo "INFO: waiting for next run at ${JOBDEF_STARTTIME} ..." bStart=0 fi @@ -121,7 +120,7 @@ EOFschedulerinfo # transfer files echo "INFO: `date` - Sending data to storage... ${DIR_SELF}/transfer.sh $JOBDEF_TYPE" | tee -a $JOB_LOGFILE touch "${JOB_DONEFILE}.02.STARTTRANSFER" - ${DIR_SELF}/transfer.sh $JOBDEF_TYPE 2>&1 | tee -a $JOB_LOGFILE + ${DIR_SELF}/transfer.sh $JOBDEF_TYPE $JOBDEF_AUTO 2>&1 | tee -a $JOB_LOGFILE rcTransfer=$? else diff --git a/transfer.sh b/transfer.sh index 9f63e85..9e9e6e2 100755 --- a/transfer.sh +++ b/transfer.sh @@ -164,6 +164,10 @@ if [ "$1" = "full" ]; then METHOD="full" fi + if [ "$1" = "auto" ]; then + METHOD="--full-if-older-than $2" + fi + PASSPHRASE=`_j_getvar ${STORAGEFILE} "gnupg-passphrase"` sParamExclude= @@ -290,10 +294,10 @@ color reset echo - if [ $rc -ne 0 ]; then + if [ $myrc -ne 0 ]; then color error - echo ERROR $rc during file transfer of ${mydir} - case $rc in + echo DIR ERROR ${mydir} rc=$myrc during file transfer + case $myrc in 23) echo A lock file was found. Maybe this server was rebooted while performing a backup. echo If so delete the file lockfile.lock named in the output and start $0 again. ;; @@ -304,7 +308,7 @@ else color ok - echo OK, Transfer of ${mydir} was successful. + echo DIR OK ${mydir} was successful. fi color reset echo @@ -322,7 +326,7 @@ else color error - echo "----- `date` SKIP: $mydir ... does not exist" + echo "DIR SKIP $mydir ... does not exist (no error)" color reset fi echo -- GitLab