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
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
3 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
Hide 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 @@
...
@@ -20,6 +20,9 @@
# sConncectionDir="${sBackupBasedir}/_active"
# sConncectionDir="${sBackupBasedir}/_active"
sConncectionDir="${sSelfdir}/_active_connections"
sConncectionDir="${sSelfdir}/_active_connections"
# where to store last backup status
sStatusDir="${sSelfdir}/_last_backup"
# log
# log
sLogdir="${sSelfdir}/log"
sLogdir="${sSelfdir}/log"
sLogfile="$sLogdir/connections.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 @@
...
@@ -24,6 +24,7 @@
# 2019-11-01 hahn write more clear log messages
# 2019-11-01 hahn write more clear log messages
# 2021-06-xx hahn added setactive + setinactive
# 2021-06-xx hahn added setactive + setinactive
# 2021-06-16 hahn added backupstatus
# 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 @@
...
@@ -119,16 +120,33 @@
# get timestamp of last backup start of a given server - see _getLoggedServers
# get timestamp of last backup start of a given server - see _getLoggedServers
# param string servername as fqdn
# param string servername as fqdn
function
_getLastBackupstart
(){
function
_getLastBackupstart
(){
local
_srv
=
$1
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
_getAllLogs |
sort
|
grep
"
\[
$_srv
\]
"
|
grep
ACCEPTED |
tail
-1
|
cut
-f
-2
-d
" "
#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
# get timestamp of last backup end of a given server - see _getLoggedServers
# param string servername as fqdn
# param string servername as fqdn
function
_getLastBackupend
(){
function
_getLastBackupend
(){
local
_srv
=
$1
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
_getAllLogs |
sort
|
grep
"
\[
$_srv
\]
"
|
grep
REMOVED |
tail
-1
|
cut
-f
-2
-d
" "
# 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
# slot handling
# ------------------------------------------------------------
# ------------------------------------------------------------
...
@@ -153,7 +171,6 @@
...
@@ -153,7 +171,6 @@
# allow a slot for a new connection
# allow a slot for a new connection
# see PUBLIC_register
# see PUBLIC_register
function
addConnection
(){
function
addConnection
(){
# sBackupClient=$1
sTouchfile
=
`
getConnFilename
$sBackupClient
`
sTouchfile
=
`
getConnFilename
$sBackupClient
`
if
[
-f
"
$sTouchfile
"
]
;
then
if
[
-f
"
$sTouchfile
"
]
;
then
echo
INFO: server
[
$sBackupClient
]
has a slot already
echo
INFO: server
[
$sBackupClient
]
has a slot already
...
@@ -166,11 +183,12 @@
...
@@ -166,11 +183,12 @@
# remove slot of a connection
# remove slot of a connection
# see PUBLIC_unregister
# see PUBLIC_unregister
# param int backup status
function
freeConnection
(){
function
freeConnection
(){
# sBackupClient=$1
sTouchfile
=
`
getConnFilename
$sBackupClient
`
sTouchfile
=
`
getConnFilename
$sBackupClient
`
if
[
-f
"
$sTouchfile
"
]
;
then
if
[
-f
"
$sTouchfile
"
]
;
then
rm
-f
"
$sTouchfile
"
mv
"
$sTouchfile
"
"
$sStatusDir
/
${
sBackupClient
}
_start"
echo
$1
>
"
$sStatusDir
/
${
sBackupClient
}
_end"
else
else
echo
INFO: server
[
$sBackupClient
]
had no reserved slot
echo
INFO: server
[
$sBackupClient
]
had no reserved slot
_addLog
"IGNORE freeing the connection - [
$sBackupClient
] had no reserved slot"
_addLog
"IGNORE freeing the connection - [
$sBackupClient
] had no reserved slot"
...
@@ -211,32 +229,43 @@
...
@@ -211,32 +229,43 @@
function
PUBLIC_backupstatus
(){
function
PUBLIC_backupstatus
(){
typeset
-i
local
ierrors
=
0
typeset
-i
local
ierrors
=
0
local
tbl
=
"%-45s | %-20s | %-20s | %-12s | %-10s
\n
"
local
tbl
=
"%-45s | %-20s | %-20s | %8s | %3s | %5s
\n
"
printf
"
$tbl
"
"server"
"start"
"end"
"duration [s]"
"age [h]"
_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
"-------------------------------------------------------------------------------------------------------------------"
echo
"-------------------------------------------------------------------------------------------------------------------"
for
myserver
in
$(
_getLoggedServers
)
for
myserver
in
$(
_getLoggedServers
)
do
do
# get data
# get data
local
tstart
=
"
$(
_getLastBackupstart
$myserver
)
"
setBackupclient
$myserver
local
tend
=
"
$(
_getLastBackupend
$myserver
)
"
typeset
-i
local
istart
=
"
$(
_getLastBackupstart
)
"
typeset
-i
local
istart
=
$(
date
+%s
-d
"
$tstart
"
)
typeset
-i
local
iend
=
"
$(
_getLastBackupend
)
"
typeset
-i
local
iend
=
$(
date
+%s
-d
"
$tend
"
)
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
iduration
=
$iend
-
$istart
typeset
-i
local
iage
=
$(
date
+%s
)
-
$iend
typeset
-i
local
iage
=
$(
date
+%s
)
-
$iend
typeset
-i
local
iagehours
=
$iage
/60/60
typeset
-i
local
iagehours
=
$iage
/60/60
# check values
# check values
local
statusAge
=
$(
color ok
)
if
[
$iagehours
-gt
$iMaxbackupAge
]
;
then
if
[
$iagehours
-gt
$iMaxbackupAge
]
;
then
statusAge
=
$(
color error
)
ierrors
=
$ierrors
+1
ierrors
=
$ierrors
+1
fi
fi
local
sduration
=
$iduration
local
sduration
=
$iduration
test
$iduration
-lt
0
&&
sduration
=
"RUNNING"
test
$iduration
-lt
0
&&
sduration
=
"RUNNING"
sStatusRun
=
"."
test
$iend
-eq
0
&&
sStatusRun
=
"?"
test
$bIsRunning
-eq
1
&&
sStatusRun
=
"R"
# output
# output
printf
"
$tbl
"
$myserver
"
$tstart
"
"
${
tend
}
"
"
${
sduration
}
"
"
$
{
s
tatus
Age
}
${
iagehours
}
$(
color reset
)
"
printf
"
$tbl
"
"
$sStatusRun
$myserver
"
"
$
{
tstart
}
"
"
${
tend
}
"
"
${
sduration
}
"
"
$
iLastS
tatus
"
"
${
iagehours
}
"
done
done
echo
echo
echo
"total :
$(
_getLoggedServers |
wc
-l
)
servers"
echo
"total :
$(
_getLoggedServers |
wc
-l
)
servers"
...
@@ -289,6 +318,7 @@
...
@@ -289,6 +318,7 @@
}
}
# register a hostname to start backups
# register a hostname to start backups
# param string FQDN
function
PUBLIC_register
(){
function
PUBLIC_register
(){
setBackupclient
$1
setBackupclient
$1
echo
"REGISTER
$1
"
echo
"REGISTER
$1
"
...
@@ -317,11 +347,14 @@
...
@@ -317,11 +347,14 @@
}
}
# unregister a backup slot
# unregister a backup slot
# param string FQDN
# param int optional: return code of the backup run
function
PUBLIC_unregister
(){
function
PUBLIC_unregister
(){
typeset
-i
local
_status
=
$2
setBackupclient
$1
setBackupclient
$1
echo
"UNREGISTER
$1
"
echo
"UNREGISTER
$1
"
echo
echo
freeConnection
freeConnection
$_status
_addLog
"REMOVED slot for [
$sBackupClient
]"
_addLog
"REMOVED slot for [
$sBackupClient
]"
_showConnectionCount
_showConnectionCount
exit
0
exit
0
...
@@ -409,6 +442,9 @@
...
@@ -409,6 +442,9 @@
if
[
!
-d
"
$sConncectionDir
"
]
;
then
if
[
!
-d
"
$sConncectionDir
"
]
;
then
mkdir
-p
"
$sConncectionDir
"
||
exit
1
mkdir
-p
"
$sConncectionDir
"
||
exit
1
fi
fi
if
[
!
-d
"
$sStatusDir
"
]
;
then
mkdir
-p
"
$sStatusDir
"
||
exit
1
fi
color
head
color
head
echo
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