diff --git a/backup.sh b/backup.sh index 664000a9baf5d4dd7d28723effe2f6ad99a70042..f3c4f69ac58deb86822a32cd03fb67b1a0f29dc5 100755 --- a/backup.sh +++ b/backup.sh @@ -24,7 +24,7 @@ # -------------------------------------------------------------------------------- -# functions +# FUNCTIONS # -------------------------------------------------------------------------------- function showHelp(){ @@ -59,17 +59,15 @@ EOFhelp } # -------------------------------------------------------------------------------- -# checks +# MAIN # -------------------------------------------------------------------------------- - - - # --- read schedulerdata + # --- read backup config data j_read - -while [ "$#" -gt 0 ]; -do + # --- handle params + while [ "$#" -gt 0 ]; + do case "$1" in -h|-\?|--help) @@ -120,33 +118,44 @@ do done - # update logfile after param overrides + # --- update logfile after param overrides _j_setLogfile - # show infos +# -------------------------------------------------------------------------------- +# show infos +# -------------------------------------------------------------------------------- + cfg_type=$(_j_getvar "${STORAGEFILE}" "type") cfg_full=$(_j_getvar "${STORAGEFILE}" "full") cfg_startfull=$(_j_getvar "${STORAGEFILE}" "start-time-full") - + test -z "${cfg_full}${cfg_startfull}" || cfg_info="INFO: Type is [auto]; ignoring config for full backup: [full = $cfg_full ... start-time-full = $cfg_startfull]" JOBDEF_STARTTIME=$(date +%H%M) STORAGE_BIN=$( _j_getvar "${STORAGEFILE}" "bin" ) + STORAGE_BASEDIR=$(_j_getvar "${STORAGEFILE}" "storage") cat << EOFbackupinfo CONFIG: - Used Backup tool : $STORAGE_BIN - Backup type : $(_j_getvar ${STORAGEFILE} "type") - $( test "$cfg_type" = "auto" && echo "$cfg_info" )$( test "$cfg_type" = "auto" || echo "INFO: full backup: $cfg_info" ) + Used Backup tool : $STORAGE_BIN + Backup type : $(_j_getvar ${STORAGEFILE} "type") + $( test "$cfg_type" = "auto" && echo "$cfg_info" )$( test "$cfg_type" = "auto" || echo "INFO: full backup: $cfg_info" ) EFFECTIVE: - type : $JOBDEF_TYPE $JOBDEF_AUTO - donefile : $JOB_DONEFILE - log : $JOB_LOGFILE + type : $JOBDEF_TYPE $JOBDEF_AUTO + log : $JOB_LOGFILE + + target : ${STORAGE_BASEDIR}$( test -z "$STORAGE_BASEDIR" && echo "NONE (local backup dumps only; no transfer)") EOFbackupinfo + test -z "$STORAGE_BASEDIR" || ( + echo " dirs to transfer : " + j_getDirs2Backup | sed "s#^# #g" + echo + ) + j_requireUser "root" # -------------------------------------------------------------------------------- @@ -157,7 +166,9 @@ EOFbackupinfo sleep 3 - # ----- local dumps + # ------------------------------------------------------------ + # local dumps + # ------------------------------------------------------------ echo "INFO: $(date) - starting backup ... type $JOBDEF_TYPE - time $JOBDEF_STARTTIME " | tee -a "$JOB_LOGFILE" touch "${JOB_DONEFILE}.01.START" @@ -168,12 +179,14 @@ EOFbackupinfo "${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE" rcBackup=$? echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE" - + echo sleep 2 - # ----- transfer + # ------------------------------------------------------------ + # transfer + # ------------------------------------------------------------ - if [ -x "${DIR_SELF}/transfer.sh" ]; then + if [ -n "$STORAGE_BASEDIR" ] && [ -x "${DIR_SELF}/transfer.sh" ]; then # transfer files cat "$STORAGEFILE" >>"$JOB_LOGFILE" @@ -184,15 +197,18 @@ EOFbackupinfo rcTransfer=$? else - echo "SKIP - transfer.sh not found; all files will be kept on local filesystem only" | tee -a "$JOB_LOGFILE" + echo "SKIP - No backup of dirs to a backup target." | tee -a "$JOB_LOGFILE" fi rcBackup=$rcBackup+rcTransfer - echo "INFO: $(date) - DONE" | tee -a "$JOB_LOGFILE" touch "${JOB_DONEFILE}.03.DONE" + # ------------------------------------------------------------ + # cleanup + # ------------------------------------------------------------ + echo echo "INFO: $(date) - compress older logs" echo find "${DIR_LOGS}" -name "*.log" -mtime +2 -print -exec gzip {} \; @@ -204,6 +220,10 @@ EOFbackupinfo find "${DIR_LOGS}" -mtime +28 -delete -print echo + # ------------------------------------------------------------ + # finish + # ------------------------------------------------------------ + echo STATUS $0 exit with final returncode rc=$rcBackup | tee -a "$JOB_LOGFILE" echo echo "log for this executed job is"