Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
4c62161a
Commit
4c62161a
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
fix vars and helper functions
parent
7a0cd860
No related branches found
No related tags found
1 merge request
!26
Eliminate scheduler
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_clientbackup.sh
+8
-6
8 additions, 6 deletions
check_clientbackup.sh
jobhelper.sh
+115
-127
115 additions, 127 deletions
jobhelper.sh
with
123 additions
and
133 deletions
check_clientbackup.sh
+
8
−
6
View file @
4c62161a
...
...
@@ -24,6 +24,8 @@ typeset -i iOK=0
typeset
-i
iErr
=
0
typeset
-i
rc
=
0
typeset
-i
iMaxAgeInHours
=
96
typeset
-i
iAge
typeset
-i
iAge2
typeset
-i
iError
...
...
@@ -43,10 +45,10 @@ if [ $? -ne 0 ]; then
iError
=
1
else
iMaxAgeInHours
=
`
j_getLastBackupAge
`
echo
verify last backup:
$iMaxAgeInHours
h ago
#
iMaxAgeInHours=`j_getLastBackupAge`
#
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
echo
LAST BACKUP:
$logfile
grep
"final.*rc="
$logfile
...
...
@@ -72,9 +74,9 @@ else
fi
# --- check age
iAge
=
`
date
+%s
`
-
`
stat
-c
%Y
$logfile
`
iAge
=
$(
date
+%s
)
-
$(
date
+%s
-r
"
$logfile
"
)
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) "
if
[
$iAge2
-gt
$iMaxAgeInHours
]
;
then
echo
"Error: the last backup is older than
$iMaxAgeInHours
hours"
...
...
@@ -88,7 +90,7 @@ else
# --- changes (incremental backups only) and backup status infos
echo
sSearch
=
"Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
echo
$logfile
| fgrep
"inc"
>
/dev/null
echo
"
$logfile
"
| fgrep
"inc"
>
/dev/null
if
[
$?
-eq
0
]
;
then
sSearch
=
"[ADM]
\
|
${
sSearch
}
"
fi
...
...
This diff is collapsed.
Click to expand it.
jobhelper.sh
+
115
−
127
View file @
4c62161a
...
...
@@ -19,17 +19,14 @@
# CONFIG
# ----------------------------------------------------------------------
DIR_SELF
=
`
dirname
$0
`
DIR_SELF
=
$(
dirname
"
$0
"
)
DIR_JOBS
=
${
DIR_SELF
}
/jobs
DIR_LOGS
=
${
DIR_SELF
}
/logs
JOBFILE
=
${
DIR_JOBS
}
/backup.job
DIRFILE
=
${
DIR_JOBS
}
/dirs.job
STORAGEFILE
=
${
DIR_JOBS
}
/transfer.job
# RMQ_SERVER=
DIR_JOBS
=
"
${
DIR_SELF
}
/jobs"
DIR_LOGS
=
"
${
DIR_SELF
}
/logs"
JOBFILE
=
"
${
DIR_JOBS
}
/backup.job"
DIRFILE
=
"
${
DIR_JOBS
}
/dirs.job"
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
# ------------------------------------------------------------
...
...
@@ -53,17 +41,17 @@ function j_init(){
j_banner
if
[
!
-d
${
DIR_LOGS
}
]
;
then
mkdir
-p
${
DIR_LOGS
}
&&
echo
"INFO: dir created
${
DIR_LOGS
}
"
if
[
!
-d
"
${
DIR_LOGS
}
"
]
;
then
mkdir
-p
"
${
DIR_LOGS
}
"
&&
echo
"INFO: dir created
${
DIR_LOGS
}
"
fi
if
[
!
-d
${
DIR_JOBS
}
]
;
then
if
[
!
-d
"
${
DIR_JOBS
}
"
]
;
then
# mkdir -p ${DIR_JOBS} && echo "INFO: dir created ${DIR_JOBS}"
echo
"ERROR: missing jobs directory. Aborting."
exit
1
fi
for
myfile
in
${
JOBFILE
}
${
DIRFILE
}
${
STORAGEFILE
}
for
myfile
in
"
${
JOBFILE
}
"
"
${
DIRFILE
}
"
"
${
STORAGEFILE
}
"
do
if
[
!
-f
"
${
myfile
}
"
]
;
then
echo
"WARNING: missing a config file:
$myfile
"
...
...
@@ -167,27 +155,27 @@ function j_getFullTarget(){
# get minimal Age of last backup that had to run in hours
# it returns a value between 24 and 96
# ------------------------------------------------------------
function
j_getLastBackupAge
(){
typeset
-i
sCmpDate
typeset
-i
iWasInc
typeset
-i
iWasFull
j_read
#
function j_getLastBackupAge(){
#
typeset -i sCmpDate
#
typeset -i iWasInc
#
typeset -i iWasFull
#
j_read
JOBDEF_INC
=
`
_j_getvar
${
JOBFILE
}
"inc"
`
JOBDEF_FULL
=
`
_j_getvar
${
JOBFILE
}
"full"
`
#
JOBDEF_INC=`_j_getvar ${JOBFILE} "inc"`
#
JOBDEF_FULL=`_j_getvar ${JOBFILE} "full"`
for
iDeltaH
in
{
24..96
}
do
sCmpDate
=
`
date
+%s
`
-iDeltaH
*
60
*
60
iWasInc
=
`
_j_wasThisDay @
${
sCmpDate
}
$JOBDEF_INC
`
iWasFull
=
`
_j_wasThisDay @
${
sCmpDate
}
$JOBDEF_FULL
`
if
[
${
iWasInc
}
-gt
0
-o
${
iWasFull
}
-gt
0
]
;
then
echo
$iDeltaH
exit
fi
done
echo
$iDeltaH
}
#
for iDeltaH in {24..96}
#
do
#
sCmpDate=`date +%s`-iDeltaH*60*60
#
iWasInc=`_j_wasThisDay @${sCmpDate} $JOBDEF_INC`
#
iWasFull=`_j_wasThisDay @${sCmpDate} $JOBDEF_FULL`
#
if [ ${iWasInc} -gt 0 -o ${iWasFull} -gt 0 ]; then
#
echo $iDeltaH
#
exit
#
fi
#
done
#
echo $iDeltaH
#
}
# ------------------------------------------------------------
# replace / to _ to get a save filename for a directory to
...
...
@@ -226,38 +214,38 @@ function _j_getvar(){
# param string date to compare
# param string value of full|inc in backup.job
# ------------------------------------------------------------
function
_j_wasThisDay
(){
typeset
-i
bToday
=
0
sCompDate
=
"
$1
"
shift
1
value
=
"
$*
"
#
function _j_wasThisDay(){
#
typeset -i bToday=0
#
sCompDate="$1"
#
shift 1
#
value="$*"
# grep weekday
echo
$value
|
grep
"^DOW:"
|
grep
`
date
+%a
-d
$sCompDate
`
>
/dev/null
&&
bToday
=
1
#
# grep weekday
#
echo $value | grep "^DOW:" | grep `date +%a -d $sCompDate` >/dev/null && bToday=1
# grep day of month
echo
$value
|
grep
"^DOM:"
|
grep
`
date
+%d
-d
$sCompDate
`
>
/dev/null
&&
bToday
=
1
#
# grep day of month
#
echo $value | grep "^DOM:" | grep `date +%d -d $sCompDate` >/dev/null && bToday=1
# grep nth weekday of a month
echo
$value
|
grep
"^WDM:"
>
/dev/null
if
[
$?
-eq
0
]
;
then
#
# grep nth weekday of a month
#
echo $value | grep "^WDM:" >/dev/null
#
if [ $? -eq 0 ]; then
typeset
-i
iDayOfMonth
=
`
date
+%e
-d
$sCompDate
`
typeset
-i
iWeekday
=
`
date
+%u
-d
$sCompDate
`
# `date +%u` - weekday as int; Sun = 0
# `date +%e` - day in date
typeset
-i
iWeekInMonth
=
$(
echo
$((
(
${
iDayOfMonth
}
-
${
iWeekday
}
+
6
)
/
7
))
)
#
typeset -i iDayOfMonth=`date +%e -d $sCompDate`
#
typeset -i iWeekday=`date +%u -d $sCompDate`
#
# `date +%u` - weekday as int; Sun = 0
#
# `date +%e` - day in date
#
typeset -i iWeekInMonth=$(echo $(( ( ${iDayOfMonth} - ${iWeekday} + 6 ) / 7 )) )
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
" "
`
#
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 " "`
if
[
${
n
}
-eq
${
iWeekInMonth
}
-a
${
sDay
}
=
`
date
+%a
-d
$sCompDate
`
]
;
then
bToday
=
1
fi
fi
#
if [ ${n} -eq ${iWeekInMonth} -a ${sDay} = `date +%a -d $sCompDate` ]; then
#
bToday=1
#
fi
#
fi
echo
$bToday
}
#
echo $bToday
#
}
# ------------------------------------------------------------
# parse day of week and day of month and echo 0 or 1
...
...
@@ -269,10 +257,10 @@ function _j_wasThisDay(){
#
# param string value of full|inc in backup.job
# ------------------------------------------------------------
function
_j_isToday
(){
sCmpDate
=
`
date
+%s
`
_j_wasThisDay
"@
$sCmpDate
"
$*
}
#
function _j_isToday(){
#
sCmpDate=`date +%s`
#
_j_wasThisDay "@$sCmpDate" $*
#
}
# ------------------------------------------------------------
# read local jobdescription and set as variables
...
...
@@ -283,52 +271,52 @@ function j_read(){
# --- 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
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
#
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
`
#
bIsTodayInc=`_j_isToday $JOBDEF_INC`
#
bIsTodayFull=`_j_isToday $JOBDEF_FULL`
JOB_DOTODAY
=
1
if
[
$bIsTodayFull
-eq
0
-a
$bIsTodayInc
-eq
0
]
;
then
JOB_DOTODAY
=
0
fi
#
JOB_DOTODAY=1
#
if [ $bIsTodayFull -eq 0 -a $bIsTodayInc -eq 0 ]; then
#
JOB_DOTODAY=0
#
fi
sStartInc
=
`
_j_fetchLatestStarttime
"start-time-inc"
`
JOBDEF_STARTTIME
=
$sStartInc
#
sStartInc=`_j_fetchLatestStarttime "start-time-inc"`
#
JOBDEF_STARTTIME=$sStartInc
if
[
$bIsTodayFull
-eq
1
]
;
then
sStartFull
=
`
_j_fetchLatestStarttime
"start-time-full"
`
#
if [ $bIsTodayFull -eq 1 ]; then
#
sStartFull=`_j_fetchLatestStarttime "start-time-full"`
if
[
$bIsTodayInc
-eq
1
-a
$sStartFull
-ne
$sStartInc
]
;
then
echo
INFO: full backup today
$sStartFull
- but incremental is at
$sStartInc
echo
-n
""
else
# echo INFO: full backup today $sStartFull
JOBDEF_TYPE
=
"full"
JOBDEF_STARTTIME
=
$sStartFull
fi
fi
#
if [ $bIsTodayInc -eq 1 -a $sStartFull -ne $sStartInc ]; then
#
echo INFO: full backup today $sStartFull - but incremental is at $sStartInc
#
echo -n ""
#
else
#
# echo INFO: full backup today $sStartFull
#
JOBDEF_TYPE="full"
#
JOBDEF_STARTTIME=$sStartFull
#
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"
}
...
...
@@ -338,29 +326,29 @@ function j_read(){
# * if empty: take value from start-time
# param string one of start-time-inc|start-time-full
# ------------------------------------------------------------
function
_j_fetchLatestStarttime
(){
sLatest
=
sStart
=
`
_j_getvar
${
JOBFILE
}
"
$1
"
|
sed
"s#[
\ \:\-
]##g"
`
for
sTime
in
`
echo
$sStart
|
sed
"s#,# #g"
`
do
if
[
-z
$sLatest
]
;
then
sLatest
=
$sTime
fi
if
[
$sTime
-le
`
date
+%H%M
`
]
;
then
sLatest
=
$sTime
fi
done
if
[
-z
$sLatest
]
;
then
$sLatest
=
`
_j_getvar
${
JOBFILE
}
"start-time"
|
sed
"s#[
\ \:\-
]##g"
`
fi
if
[
-z
$sLatest
]
;
then
color error
echo
ERROR: missing start
time
info
for
$1
color reset
exit
1
fi
echo
$sLatest
}
#
function _j_fetchLatestStarttime(){
#
sLatest=
#
sStart=`_j_getvar ${JOBFILE} "$1" | sed "s#[\ \:\-]##g"`
#
for sTime in `echo $sStart | sed "s#,# #g"`
#
do
#
if [ -z $sLatest ]; then
#
sLatest=$sTime
#
fi
#
if [ $sTime -le `date +%H%M` ]; then
#
sLatest=$sTime
#
fi
#
done
#
if [ -z $sLatest ]; then
#
$sLatest=`_j_getvar ${JOBFILE} "start-time" | sed "s#[\ \:\-]##g"`
#
fi
#
if [ -z $sLatest ]; then
#
color error
#
echo ERROR: missing start time info for $1
#
color reset
#
exit 1
#
fi
#
echo $sLatest
#
}
# ------------------------------------------------------------
# check if a binary exists - and abort if not
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment