Skip to content
Snippets Groups Projects
Commit 4c62161a authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

fix vars and helper functions

parent 7a0cd860
No related branches found
No related tags found
1 merge request!26Eliminate scheduler
...@@ -24,6 +24,8 @@ typeset -i iOK=0 ...@@ -24,6 +24,8 @@ typeset -i iOK=0
typeset -i iErr=0 typeset -i iErr=0
typeset -i rc=0 typeset -i rc=0
typeset -i iMaxAgeInHours=96
typeset -i iAge typeset -i iAge
typeset -i iAge2 typeset -i iAge2
typeset -i iError typeset -i iError
...@@ -43,10 +45,10 @@ if [ $? -ne 0 ]; then ...@@ -43,10 +45,10 @@ if [ $? -ne 0 ]; then
iError=1 iError=1
else else
iMaxAgeInHours=`j_getLastBackupAge` # iMaxAgeInHours=`j_getLastBackupAge`
echo verify last backup: $iMaxAgeInHours h ago # echo verify last backup: $iMaxAgeInHours h ago
for logfile in `ls -1t $logdir/inc*.log $logdir/full*.log $logdir/auto*.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 do
echo LAST BACKUP: $logfile echo LAST BACKUP: $logfile
grep "final.*rc=" $logfile grep "final.*rc=" $logfile
...@@ -72,9 +74,9 @@ else ...@@ -72,9 +74,9 @@ else
fi fi
# --- check age # --- check age
iAge=`date +%s`-`stat -c %Y $logfile` iAge=$( date +%s )-$( date +%s -r "$logfile" )
iAge2=$iAge/60/60 iAge2=$iAge/60/60
echo age: $iAge sec ... $iAge2 h echo "age: $iAge sec ... $iAge2 h"
sShort="$sShort last backup log: `basename $logfile` ($iAge2 h ago) " sShort="$sShort last backup log: `basename $logfile` ($iAge2 h ago) "
if [ $iAge2 -gt $iMaxAgeInHours ]; then if [ $iAge2 -gt $iMaxAgeInHours ]; then
echo "Error: the last backup is older than $iMaxAgeInHours hours" echo "Error: the last backup is older than $iMaxAgeInHours hours"
...@@ -88,7 +90,7 @@ else ...@@ -88,7 +90,7 @@ else
# --- changes (incremental backups only) and backup status infos # --- changes (incremental backups only) and backup status infos
echo echo
sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize" sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
echo $logfile | fgrep "inc" >/dev/null echo "$logfile" | fgrep "inc" >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sSearch="[ADM]\ |${sSearch}" sSearch="[ADM]\ |${sSearch}"
fi fi
......
...@@ -19,17 +19,14 @@ ...@@ -19,17 +19,14 @@
# CONFIG # CONFIG
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
DIR_SELF=`dirname $0` DIR_SELF=$( dirname "$0" )
DIR_JOBS=${DIR_SELF}/jobs DIR_JOBS="${DIR_SELF}/jobs"
DIR_LOGS=${DIR_SELF}/logs DIR_LOGS="${DIR_SELF}/logs"
JOBFILE=${DIR_JOBS}/backup.job
DIRFILE=${DIR_JOBS}/dirs.job
STORAGEFILE=${DIR_JOBS}/transfer.job
# RMQ_SERVER=
JOBFILE="${DIR_JOBS}/backup.job"
DIRFILE="${DIR_JOBS}/dirs.job"
STORAGEFILE="${DIR_JOBS}/transfer.job"
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -37,15 +34,6 @@ STORAGEFILE=${DIR_JOBS}/transfer.job ...@@ -37,15 +34,6 @@ STORAGEFILE=${DIR_JOBS}/transfer.job
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# ------------------------------------------------------------
# IDEA ONLY; UNUSED
# fetch current job from queue and store it to job directory
# ------------------------------------------------------------
function j_fetch(){
echo TODO: fetch from RMQ_SERVER
}
# ------------------------------------------------------------ # ------------------------------------------------------------
# init function # init function
# ------------------------------------------------------------ # ------------------------------------------------------------
...@@ -53,17 +41,17 @@ function j_init(){ ...@@ -53,17 +41,17 @@ function j_init(){
j_banner j_banner
if [ ! -d ${DIR_LOGS} ]; then if [ ! -d "${DIR_LOGS}" ]; then
mkdir -p ${DIR_LOGS} && echo "INFO: dir created ${DIR_LOGS}" mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}"
fi fi
if [ ! -d ${DIR_JOBS} ]; then if [ ! -d "${DIR_JOBS}" ]; then
# mkdir -p ${DIR_JOBS} && echo "INFO: dir created ${DIR_JOBS}" # mkdir -p ${DIR_JOBS} && echo "INFO: dir created ${DIR_JOBS}"
echo "ERROR: missing jobs directory. Aborting." echo "ERROR: missing jobs directory. Aborting."
exit 1 exit 1
fi fi
for myfile in ${JOBFILE} ${DIRFILE} ${STORAGEFILE} for myfile in "${JOBFILE}" "${DIRFILE}" "${STORAGEFILE}"
do do
if [ ! -f "${myfile}" ]; then if [ ! -f "${myfile}" ]; then
echo "WARNING: missing a config file: $myfile" echo "WARNING: missing a config file: $myfile"
...@@ -167,27 +155,27 @@ function j_getFullTarget(){ ...@@ -167,27 +155,27 @@ function j_getFullTarget(){
# get minimal Age of last backup that had to run in hours # get minimal Age of last backup that had to run in hours
# it returns a value between 24 and 96 # it returns a value between 24 and 96
# ------------------------------------------------------------ # ------------------------------------------------------------
function j_getLastBackupAge(){ # function j_getLastBackupAge(){
typeset -i sCmpDate # typeset -i sCmpDate
typeset -i iWasInc # typeset -i iWasInc
typeset -i iWasFull # typeset -i iWasFull
j_read # j_read
JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"` # JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"`
JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"` # JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"`
for iDeltaH in {24..96} # for iDeltaH in {24..96}
do # do
sCmpDate=`date +%s`-iDeltaH*60*60 # sCmpDate=`date +%s`-iDeltaH*60*60
iWasInc=`_j_wasThisDay @${sCmpDate} $JOBDEF_INC` # iWasInc=`_j_wasThisDay @${sCmpDate} $JOBDEF_INC`
iWasFull=`_j_wasThisDay @${sCmpDate} $JOBDEF_FULL` # iWasFull=`_j_wasThisDay @${sCmpDate} $JOBDEF_FULL`
if [ ${iWasInc} -gt 0 -o ${iWasFull} -gt 0 ]; then # if [ ${iWasInc} -gt 0 -o ${iWasFull} -gt 0 ]; then
echo $iDeltaH # echo $iDeltaH
exit # exit
fi # fi
done # done
echo $iDeltaH # echo $iDeltaH
} # }
# ------------------------------------------------------------ # ------------------------------------------------------------
# replace / to _ to get a save filename for a directory to # replace / to _ to get a save filename for a directory to
...@@ -226,38 +214,38 @@ function _j_getvar(){ ...@@ -226,38 +214,38 @@ function _j_getvar(){
# param string date to compare # param string date to compare
# param string value of full|inc in backup.job # param string value of full|inc in backup.job
# ------------------------------------------------------------ # ------------------------------------------------------------
function _j_wasThisDay(){ # function _j_wasThisDay(){
typeset -i bToday=0 # typeset -i bToday=0
sCompDate="$1" # sCompDate="$1"
shift 1 # shift 1
value="$*" # value="$*"
# grep weekday # # grep weekday
echo $value | grep "^DOW:" | grep `date +%a -d $sCompDate` >/dev/null && bToday=1 # echo $value | grep "^DOW:" | grep `date +%a -d $sCompDate` >/dev/null && bToday=1
# grep day of month # # grep day of month
echo $value | grep "^DOM:" | grep `date +%d -d $sCompDate` >/dev/null && bToday=1 # echo $value | grep "^DOM:" | grep `date +%d -d $sCompDate` >/dev/null && bToday=1
# grep nth weekday of a month # # grep nth weekday of a month
echo $value | grep "^WDM:" >/dev/null # echo $value | grep "^WDM:" >/dev/null
if [ $? -eq 0 ]; then # if [ $? -eq 0 ]; then
typeset -i iDayOfMonth=`date +%e -d $sCompDate` # typeset -i iDayOfMonth=`date +%e -d $sCompDate`
typeset -i iWeekday=`date +%u -d $sCompDate` # typeset -i iWeekday=`date +%u -d $sCompDate`
# `date +%u` - weekday as int; Sun = 0 # # `date +%u` - weekday as int; Sun = 0
# `date +%e` - day in date # # `date +%e` - day in date
typeset -i iWeekInMonth=$(echo $(( ( ${iDayOfMonth} - ${iWeekday} + 6 ) / 7 )) ) # typeset -i iWeekInMonth=$(echo $(( ( ${iDayOfMonth} - ${iWeekday} + 6 ) / 7 )) )
typeset -i n=`echo $value | grep "^WDM:" | cut -f 2- -d ":" | cut -c 1` # typeset -i n=`echo $value | grep "^WDM:" | cut -f 2- -d ":" | cut -c 1`
sDay=`echo $value | grep "^WDM:" | cut -f 2- -d ":" | cut -f 2 -d " "` # sDay=`echo $value | grep "^WDM:" | cut -f 2- -d ":" | cut -f 2 -d " "`
if [ ${n} -eq ${iWeekInMonth} -a ${sDay} = `date +%a -d $sCompDate` ]; then # if [ ${n} -eq ${iWeekInMonth} -a ${sDay} = `date +%a -d $sCompDate` ]; then
bToday=1 # bToday=1
fi # fi
fi # fi
echo $bToday # echo $bToday
} # }
# ------------------------------------------------------------ # ------------------------------------------------------------
# parse day of week and day of month and echo 0 or 1 # parse day of week and day of month and echo 0 or 1
...@@ -269,10 +257,10 @@ function _j_wasThisDay(){ ...@@ -269,10 +257,10 @@ function _j_wasThisDay(){
# #
# param string value of full|inc in backup.job # param string value of full|inc in backup.job
# ------------------------------------------------------------ # ------------------------------------------------------------
function _j_isToday(){ # function _j_isToday(){
sCmpDate=`date +%s` # sCmpDate=`date +%s`
_j_wasThisDay "@$sCmpDate" $* # _j_wasThisDay "@$sCmpDate" $*
} # }
# ------------------------------------------------------------ # ------------------------------------------------------------
# read local jobdescription and set as variables # read local jobdescription and set as variables
...@@ -283,52 +271,52 @@ function j_read(){ ...@@ -283,52 +271,52 @@ function j_read(){
# --- parse something # --- parse something
BACKUP_TARGETDIR=`_j_getvar ${JOBFILE} "dir-local-dumps"` BACKUP_TARGETDIR=$(_j_getvar ${JOBFILE} "dir-local-dumps")
JOBDEF_TYPE=`_j_getvar ${JOBFILE} "type"` JOBDEF_TYPE=$(_j_getvar ${JOBFILE} "type")
if [ -z "$JOBDEF_TYPE" ]; then if [ -z "$JOBDEF_TYPE" ]; then
JOBDEF_TYPE=auto JOBDEF_TYPE=auto
fi fi
JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"` # JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"`
JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"` # JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"`
JOBDEF_AUTO=`_j_getvar ${JOBFILE} "auto"` # JOBDEF_AUTO=`_j_getvar ${JOBFILE} "auto"`
if [ "$JOBDEF_TYPE" = "auto" ]; then # if [ "$JOBDEF_TYPE" = "auto" ]; then
if [ -z "$JOBDEF_AUTO" ]; then # if [ -z "$JOBDEF_AUTO" ]; then
JOBDEF_AUTO=1W # JOBDEF_AUTO=1W
fi # fi
else # else
JOBDEF_AUTO= # JOBDEF_AUTO=
fi # fi
bIsTodayInc=`_j_isToday $JOBDEF_INC` # bIsTodayInc=`_j_isToday $JOBDEF_INC`
bIsTodayFull=`_j_isToday $JOBDEF_FULL` # bIsTodayFull=`_j_isToday $JOBDEF_FULL`
JOB_DOTODAY=1 # JOB_DOTODAY=1
if [ $bIsTodayFull -eq 0 -a $bIsTodayInc -eq 0 ]; then # if [ $bIsTodayFull -eq 0 -a $bIsTodayInc -eq 0 ]; then
JOB_DOTODAY=0 # JOB_DOTODAY=0
fi # fi
sStartInc=`_j_fetchLatestStarttime "start-time-inc"` # sStartInc=`_j_fetchLatestStarttime "start-time-inc"`
JOBDEF_STARTTIME=$sStartInc # JOBDEF_STARTTIME=$sStartInc
if [ $bIsTodayFull -eq 1 ]; then # if [ $bIsTodayFull -eq 1 ]; then
sStartFull=`_j_fetchLatestStarttime "start-time-full"` # sStartFull=`_j_fetchLatestStarttime "start-time-full"`
if [ $bIsTodayInc -eq 1 -a $sStartFull -ne $sStartInc ]; then # if [ $bIsTodayInc -eq 1 -a $sStartFull -ne $sStartInc ]; then
echo INFO: full backup today $sStartFull - but incremental is at $sStartInc # echo INFO: full backup today $sStartFull - but incremental is at $sStartInc
echo -n "" # echo -n ""
else # else
# echo INFO: full backup today $sStartFull # # echo INFO: full backup today $sStartFull
JOBDEF_TYPE="full" # JOBDEF_TYPE="full"
JOBDEF_STARTTIME=$sStartFull # JOBDEF_STARTTIME=$sStartFull
fi # fi
fi # fi
JOB_DONEFILE=${DIR_LOGS}/${JOBDEF_TYPE}-`date +%Y%m%d`-${JOBDEF_STARTTIME} JOB_DONEFILE=${DIR_LOGS}/${JOBDEF_TYPE}-$(date +%Y%m%d)-${JOBDEF_STARTTIME}
JOB_LOGFILE="${JOB_DONEFILE}.log" JOB_LOGFILE="${JOB_DONEFILE}.log"
} }
...@@ -338,29 +326,29 @@ function j_read(){ ...@@ -338,29 +326,29 @@ function j_read(){
# * if empty: take value from start-time # * if empty: take value from start-time
# param string one of start-time-inc|start-time-full # param string one of start-time-inc|start-time-full
# ------------------------------------------------------------ # ------------------------------------------------------------
function _j_fetchLatestStarttime(){ # function _j_fetchLatestStarttime(){
sLatest= # sLatest=
sStart=`_j_getvar ${JOBFILE} "$1" | sed "s#[\ \:\-]##g"` # sStart=`_j_getvar ${JOBFILE} "$1" | sed "s#[\ \:\-]##g"`
for sTime in `echo $sStart | sed "s#,# #g"` # for sTime in `echo $sStart | sed "s#,# #g"`
do # do
if [ -z $sLatest ]; then # if [ -z $sLatest ]; then
sLatest=$sTime # sLatest=$sTime
fi # fi
if [ $sTime -le `date +%H%M` ]; then # if [ $sTime -le `date +%H%M` ]; then
sLatest=$sTime # sLatest=$sTime
fi # fi
done # done
if [ -z $sLatest ]; then # if [ -z $sLatest ]; then
$sLatest=`_j_getvar ${JOBFILE} "start-time" | sed "s#[\ \:\-]##g"` # $sLatest=`_j_getvar ${JOBFILE} "start-time" | sed "s#[\ \:\-]##g"`
fi # fi
if [ -z $sLatest ]; then # if [ -z $sLatest ]; then
color error # color error
echo ERROR: missing start time info for $1 # echo ERROR: missing start time info for $1
color reset # color reset
exit 1 # exit 1
fi # fi
echo $sLatest # echo $sLatest
} # }
# ------------------------------------------------------------ # ------------------------------------------------------------
# check if a binary exists - and abort if not # check if a binary exists - and abort if not
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment