Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Iml Backup Server
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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 Server
Commits
a57259d6
Commit
a57259d6
authored
4 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
store backup status in status files ... do not grep frpom logs
parent
a277fb26
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
inc_config.sh.dist
+3
-0
3 additions, 0 deletions
inc_config.sh.dist
storage_helper.sh
+54
-18
54 additions, 18 deletions
storage_helper.sh
with
57 additions
and
18 deletions
inc_config.sh.dist
+
3
−
0
View file @
a57259d6
...
...
@@ -20,6 +20,9 @@
# sConncectionDir="${sBackupBasedir}/_active"
sConncectionDir="${sSelfdir}/_active_connections"
# where to store last backup status
sStatusDir="${sSelfdir}/_last_backup"
# log
sLogdir="${sSelfdir}/log"
sLogfile="$sLogdir/connections.log"
...
...
This diff is collapsed.
Click to expand it.
storage_helper.sh
+
54
−
18
View file @
a57259d6
...
...
@@ -24,6 +24,7 @@
# 2019-11-01 hahn write more clear log messages
# 2021-06-xx hahn added setactive + setinactive
# 2021-06-16 hahn added backupstatus
# 2021-06-18 hahn store backup status in status files ... do not grep frpom logs
# ======================================================================
# ----------------------------------------------------------------------
...
...
@@ -119,16 +120,33 @@
# get timestamp of last backup start of a given server - see _getLoggedServers
# param string servername as fqdn
function
_getLastBackupstart
(){
local
_srv
=
$1
_getAllLogs |
sort
|
grep
"
\[
$_srv
\]
"
|
grep
ACCEPTED |
tail
-1
|
cut
-f
-2
-d
" "
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
#local _srv=$1
#_getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " "
}
# get timestamp of last backup end of a given server - see _getLoggedServers
# param string servername as fqdn
function
_getLastBackupend
(){
local
_srv
=
$1
_getAllLogs |
sort
|
grep
"
\[
$_srv
\]
"
|
grep
REMOVED |
tail
-1
|
cut
-f
-2
-d
" "
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
# local _srv=$1
# _getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " "
}
function
_getLastBackupstatus
(){
if
[
-f
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
]
;
then
cat
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
else
echo
"-1"
fi
}
function
_isRunning
(){
sTouchfile
=
`
getConnFilename
$sBackupClient
`
test
-f
"
$sTouchfile
"
&&
echo
1
test
-f
"
$sTouchfile
"
||
echo
0
}
# ------------------------------------------------------------
# slot handling
# ------------------------------------------------------------
...
...
@@ -153,7 +171,6 @@
# allow a slot for a new connection
# see PUBLIC_register
function
addConnection
(){
# sBackupClient=$1
sTouchfile
=
`
getConnFilename
$sBackupClient
`
if
[
-f
"
$sTouchfile
"
]
;
then
echo
INFO: server
[
$sBackupClient
]
has a slot already
...
...
@@ -166,11 +183,12 @@
# remove slot of a connection
# see PUBLIC_unregister
# param int backup status
function
freeConnection
(){
# sBackupClient=$1
sTouchfile
=
`
getConnFilename
$sBackupClient
`
if
[
-f
"
$sTouchfile
"
]
;
then
rm
-f
"
$sTouchfile
"
mv
"
$sTouchfile
"
"
$sStatusDir
/
${
sBackupClient
}
_start"
echo
$1
>
"
$sStatusDir
/
${
sBackupClient
}
_end"
else
echo
INFO: server
[
$sBackupClient
]
had no reserved slot
_addLog
"IGNORE freeing the connection - [
$sBackupClient
] had no reserved slot"
...
...
@@ -211,32 +229,43 @@
function
PUBLIC_backupstatus
(){
typeset
-i
local
ierrors
=
0
local
tbl
=
"%-45s | %-20s | %-20s | %-12s | %-10s
\n
"
printf
"
$tbl
"
"server"
"start"
"end"
"duration [s]"
"age [h]"
local
tbl
=
"%-45s | %-20s | %-20s | %8s | %3s | %5s
\n
"
_showConnectionCount
echo
"This table shows the time and duration [s] of the last backup for each server."
echo
printf
"
$tbl
"
" server"
"start"
"end"
"duration"
"rc"
"age [h]"
echo
"-------------------------------------------------------------------------------------------------------------------"
for
myserver
in
$(
_getLoggedServers
)
do
# get data
local
tstart
=
"
$(
_getLastBackupstart
$myserver
)
"
local
tend
=
"
$(
_getLastBackupend
$myserver
)
"
typeset
-i
local
istart
=
$(
date
+%s
-d
"
$tstart
"
)
typeset
-i
local
iend
=
$(
date
+%s
-d
"
$tend
"
)
setBackupclient
$myserver
typeset
-i
local
istart
=
"
$(
_getLastBackupstart
)
"
typeset
-i
local
iend
=
"
$(
_getLastBackupend
)
"
typeset
-i
local
bIsRunning
=
$(
_isRunning
)
typeset
-i
local
iLastStatus
=
$(
_getLastBackupstatus
)
local
tstart
=
$(
date
+
"%Y-%m-%d %H:%M:%S"
-d
@
${
istart
}
)
local
tend
=
$(
date
+
"%Y-%m-%d %H:%M:%S"
-d
@
${
iend
}
)
typeset
-i
local
iduration
=
$iend
-
$istart
typeset
-i
local
iage
=
$(
date
+%s
)
-
$iend
typeset
-i
local
iagehours
=
$iage
/60/60
# check values
local
statusAge
=
$(
color ok
)
if
[
$iagehours
-gt
$iMaxbackupAge
]
;
then
statusAge
=
$(
color error
)
ierrors
=
$ierrors
+1
fi
local
sduration
=
$iduration
test
$iduration
-lt
0
&&
sduration
=
"RUNNING"
sStatusRun
=
"."
test
$iend
-eq
0
&&
sStatusRun
=
"?"
test
$bIsRunning
-eq
1
&&
sStatusRun
=
"R"
# output
printf
"
$tbl
"
$myserver
"
$tstart
"
"
${
tend
}
"
"
${
sduration
}
"
"
$
{
s
tatus
Age
}
${
iagehours
}
$(
color reset
)
"
printf
"
$tbl
"
"
$sStatusRun
$myserver
"
"
$
{
tstart
}
"
"
${
tend
}
"
"
${
sduration
}
"
"
$
iLastS
tatus
"
"
${
iagehours
}
"
done
echo
echo
"total :
$(
_getLoggedServers |
wc
-l
)
servers"
...
...
@@ -289,6 +318,7 @@
}
# register a hostname to start backups
# param string FQDN
function
PUBLIC_register
(){
setBackupclient
$1
echo
"REGISTER
$1
"
...
...
@@ -317,11 +347,14 @@
}
# unregister a backup slot
# param string FQDN
# param int optional: return code of the backup run
function
PUBLIC_unregister
(){
typeset
-i
local
_status
=
$2
setBackupclient
$1
echo
"UNREGISTER
$1
"
echo
freeConnection
freeConnection
$_status
_addLog
"REMOVED slot for [
$sBackupClient
]"
_showConnectionCount
exit
0
...
...
@@ -409,6 +442,9 @@
if
[
!
-d
"
$sConncectionDir
"
]
;
then
mkdir
-p
"
$sConncectionDir
"
||
exit
1
fi
if
[
!
-d
"
$sStatusDir
"
]
;
then
mkdir
-p
"
$sStatusDir
"
||
exit
1
fi
color
head
echo
...
...
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