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
Merge requests
!81
show last backup, prune and verify
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
show last backup, prune and verify
check-clientbackup-with-prune-verify
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Hahn Axel (hahn)
requested to merge
check-clientbackup-with-prune-verify
into
master
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
6986483b
1 commit,
2 years ago
1 file
+
74
−
36
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
check_clientbackup.sh
+
74
−
36
View file @ 6986483b
Edit in single-file editor
Open in Web IDE
Show full file
@@ -15,6 +15,7 @@
# 2022-01-19 ah v1.1 fixes with shellcheck
# 2022-02-09 ah v1.2 update after changes in logging
# 2022-10-07 ah v1.3 unescape regex with space to prevent "grep: warning: stray \ before white space"
# 2022-10-20 ah v1.4 show last backup, prune and verify
# ==============================================================================
.
$(
dirname
$0
)
/jobhelper.sh
@@ -24,16 +25,56 @@
# ------------------------------------------------------------------------------
typeset
-i
iOK
=
0
typeset
-i
iError
# limit when to warn if no backup was started
typeset
-i
iMaxAgeInHours
=
96
typeset
-i
iMaxAgeInHours
=
24
typeset
-i
iAge
typeset
-i
iAge
2
typeset
-i
i
Error
typeset
-i
iAge
H
typeset
-i
i
AgeD
logdir
=
$(
dirname
"
$0
"
)
/logs
flagShowChangedFiles
=
0
# ------------------------------------------------------------------------------
# FUNCTIONS
# ------------------------------------------------------------------------------
# get age of a given file and fill global vars
# iAge
# iAgeH
# iAgeD
# param string filename
function
getAge
(){
typeset
-i
local
tsfile
=
0
test
-r
"
$1
"
&&
tsfile
=
$(
date
+%s
-r
"
$1
"
)
iAge
=
$(
date
+%s
)
-
$tsfile
iAgeH
=
$iAge
/60/60
iAgeD
=
$iAge
/60/60/24
}
# show age of a file hr like
function
showAge
(){
getAge
"
$1
"
if
[
$iAgeD
-gt
10000
]
;
then
echo
"NEVER"
else
test
$iAgeD
-gt
0
&&
echo
-n
"
$iAgeD
days"
test
$iAgeD
-eq
0
&&
test
$iAgeH
-gt
0
&&
echo
-n
"
$iAgeH
h"
test
$iAgeD
-eq
0
&&
test
$iAgeH
-eq
0
&&
echo
-n
"
$iAge
s"
echo
" ago"
fi
}
# filter color in given output
# To use it set a pipe in front:
# <command> | filterColor
function
filterColor
(){
sed
-r
"s/
\x
1B
\[
([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
}
# ------------------------------------------------------------------------------
# MAIN
@@ -47,23 +88,16 @@ if [ $? -ne 0 ]; then
iError
=
1
else
# 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)
# do
backuplogfile
=
$(
ls
-1t
"
$logdir
"
/inc
*
.log
"
$logdir
"
/full
*
.log
"
$logdir
"
/auto
*
.log 2>/dev/null |
head
-1
)
transferlogfile
=
$(
ls
-1t
"
$logdir
"
/transfer
*
.log |
head
-1
)
logfile
=
"
${
backuplogfile
}
${
transferlogfile
}
"
lastlogfile
=
"
$(
ls
-1t
$logfile
|
head
-1
)
"
echo
LAST BACKUP:
"
$logfile
"
echo
LAST LOGS:
"
$logfile
"
echo
echo
">>> RETURNCODES"
grep
"final.*rc="
$logfile
#
echo ">>> RETURNCODES"
#
grep "final.*rc=" $logfile
# --- Monitoring Statusline
if
[
-f
"
$(
dirname
$0
)
"
/transfer.sh
]
;
then
@@ -77,21 +111,23 @@ else
iOK
=
$(
grep
"final.*rc=0$"
$logfile
|
wc
-l
)
iError
=
$(
grep
"final.*rc="
$logfile
|
grep
-v
"rc=0$"
|
wc
-l
)
echo
"OK:
$iOK
... Errors:
$iError
"
# show errors:
grep
"final.*rc="
$logfile
|
grep
-v
"rc=0"
# --- rc=0 must be here
if
[
$iOK
-eq
0
]
;
then
echo
"ERROR: no OK message was found. Something is messed up :-/"
iError+
=
1
fi
echo
# --- check age
echo
echo
">>> AGE"
iAge
=
$(
date
+%s
)
-
$(
date
+%s
-r
"
$lastlogfile
"
)
iAge2
=
$iAge
/60/60
echo
"age:
$iAge
sec ...
$iAge2
h"
sShort
=
"
$sShort
last backup log:
$(
basename
"
$lastlogfile
"
)
(
$iAge2
h ago) "
if
[
$iAge2
-gt
$iMaxAgeInHours
]
;
then
getAge
"
$lastlogfile
"
echo
"age:
$iAge
sec ...
$iAgeH
h"
sShort
=
"
$sShort
last backup log:
$(
basename
"
$lastlogfile
"
)
(
$iAgeH
h ago) "
if
[
$iAgeH
-gt
$iMaxAgeInHours
]
;
then
echo
"Error: the last backup is older than
$iMaxAgeInHours
hours"
sShort
=
"
$sShort
ERROR: backup is older than
$iMaxAgeInHours
hours "
iError+
=
1
@@ -100,33 +136,35 @@ else
sShort
=
"
$sShort
OK: backup is younger than
$iMaxAgeInHours
hours "
iOK+
=
1
fi
echo
# --- changes (incremental backups only) and backup status infos
# echo
# sSearch="Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
# echo "$logfile" | grep -F "inc" >/dev/null
# if [ $? -eq 0 ]; then
# sSearch="[ADM] |${sSearch}"
# fi
# echo --- changes:
# grep -E "^(${sSearch})" "$logfile"
if
[
$flagShowChangedFiles
-ne
0
]
;
then
sSearch
=
"Args:|ElapsedTime|SourceFiles|SourceFileSize|RawDeltaSize"
if
echo
"
$logfile
"
|
grep
-E
"(inc|auto)"
>
/dev/null
;
then
sSearch
=
"[ADM] |
${
sSearch
}
"
fi
echo
">>> Changes:"
grep
-E
"^(
${
sSearch
}
)"
$logfile
|
cut
-f
2-
-d
':'
echo
fi
echo
">>> Summary of database backup actions:"
cat
$logfile
|
grep
"__[A-Z][A-Z]*__"
|
grep
'__DB__'
| filterColor
echo
# echo ">>> Summary of backed up directories:"
# cat $logfile | grep "DIR "
echo
">>> Summary of backup actions:"
cat
$logfile
|
grep
"__[A-Z][A-Z]*__"
echo
">>> Summary of transfer actions:"
cat
$logfile
|
grep
"__[A-Z][A-Z]*__"
|
grep
-v
'__DB__'
| filterColor
echo
sShort
=
"
$sShort
- OK:
$iOK
... Errors:
$iError
"
# done
fi
echo
">>> Backup repository:"
echo
"__LAST__backup "
$(
showAge
"
$logdir
/last_backup"
)
echo
"__LAST__prune "
$(
showAge
"
$logdir
/last_prune"
)
echo
"__LAST__verify "
$(
showAge
"
$logdir
/last_verify"
)
echo
echo
"MONITORINFO:
$sShort
"
echo
"STATUS
$0
- final returncode rc=
$iError
"
Loading