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
8cf7170d
Commit
8cf7170d
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
use single status file; added backup size
parent
a57259d6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
storage_helper.sh
+71
-28
71 additions, 28 deletions
storage_helper.sh
with
71 additions
and
28 deletions
storage_helper.sh
+
71
−
28
View file @
8cf7170d
...
...
@@ -6,13 +6,17 @@
# ----------------------------------------------------------------------
#
# SYNTAX:
# storage_helper.sh PARAMETERS
#
# PARAMETERS:
#
# register [hostname]
# init backup for hostname; backup client must interrupt/ repeat
# return code is <> 0
#
# unregister [hostname]
# unregister [hostname]
[statuscode]
# send info that a backup was done to delete the connection flag
# for the given host
# for the given host
.
#
# status
# show current connections
...
...
@@ -25,6 +29,7 @@
# 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
# 2021-06-21 hahn use single status file; added backup size
# ======================================================================
# ----------------------------------------------------------------------
...
...
@@ -43,6 +48,7 @@
# max age of last backup in h
iMaxbackupAge
=
36
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
...
...
@@ -117,29 +123,48 @@
_getAllLogs |
cut
-f
2
-d
'['
|
cut
-f
1
-d
']'
|
sort
-u
}
# get timestamp of last backup start of a given server
- see _getLoggedServers
#
param
string s
ervername as fqdn
# get timestamp of last backup start of a given server
#
global
string s
BackupClient FQDN of current server
function
_getLastBackupstart
(){
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_start"
#test -r "${sStatusDir}/${sBackupClient}_start" && stat -c %Y "${sStatusDir}/${sBackupClient}_start"
#echo $tsBackupStart
#local _srv=$1
#_getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " "
test
-r
"
$sStatusDir
/
${
sBackupClient
}
"
&&
.
"
$sStatusDir
/
${
sBackupClient
}
"
echo
$tsBackupStart
}
# get timestamp of last backup end of a given server
- see _getLoggedServers
#
param
string s
ervername as fqdn
# get timestamp of last backup end of a given server
#
global
string s
BackupClient FQDN of current server
function
_getLastBackupend
(){
test
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
&&
stat
-c
%Y
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
#
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 " "
test
-r
"
$sStatusDir
/
${
sBackupClient
}
"
&&
.
"
$sStatusDir
/
${
sBackupClient
}
"
echo
$tsBackupEnd
}
# get status code of last backup from status file
# global string sBackupClient FQDN of current server
function
_getLastBackupstatus
(){
if
[
-f
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
]
;
then
cat
"
${
sStatusDir
}
/
${
sBackupClient
}
_end"
if
[
-r
"
${
sStatusDir
}
/
${
sBackupClient
}
"
]
;
then
.
"
${
sStatusDir
}
/
${
sBackupClient
}
"
echo
$backupRc
else
echo
"-
1
"
echo
"-
2
"
fi
}
# get size of backup data from status file
# global string sBackupClient FQDN of current server
function
_getBackupsize
(){
test
-r
"
$sStatusDir
/
${
sBackupClient
}
"
&&
.
"
$sStatusDir
/
${
sBackupClient
}
"
echo
$size
}
# check if a backup for current server is running
# it returns 0 for no and 1 for yes
# global string sBackupClient FQDN of current server
function
_isRunning
(){
sTouchfile
=
`
getConnFilename
$sBackupClient
`
test
-f
"
$sTouchfile
"
&&
echo
1
...
...
@@ -177,6 +202,9 @@
_addLog
"IGNORE request for a slot - [
$sBackupClient
] has a slot already"
else
touch
"
$sTouchfile
"
echo
"client='
$sBackupClient
'"
>
"
$sTouchfile
"
echo
"#
$(
date
"""+%Y-%m-%d %H:%M:%S"""
)
"
>>
"
$sTouchfile
"
echo
"tsBackupStart=
$(
date
+%s
)
"
>>
"
$sTouchfile
"
_addLog
"REQUEST a slot for server [
$sBackupClient
]"
fi
}
...
...
@@ -185,10 +213,15 @@
# see PUBLIC_unregister
# param int backup status
function
freeConnection
(){
local
_status
=
$1
test
-z
"
$1
"
&&
_status
=
-1
sTouchfile
=
`
getConnFilename
$sBackupClient
`
if
[
-f
"
$sTouchfile
"
]
;
then
mv
"
$sTouchfile
"
"
$sStatusDir
/
${
sBackupClient
}
_start"
echo
$1
>
"
$sStatusDir
/
${
sBackupClient
}
_end"
echo
"#
$(
date
"""+%Y-%m-%d %H:%M:%S"""
)
"
>>
"
$sTouchfile
"
echo
"tsBackupEnd=
$(
date
+%s
)
"
>>
"
$sTouchfile
"
echo
"backupRc=
$_status
"
>>
"
$sTouchfile
"
echo
"size=
$(
du
-hs
${
sBackupBasedir
}
/
*
/
$sBackupClient
2>/dev/null
)
"
>>
"
$sTouchfile
"
mv
"
$sTouchfile
"
"
$sStatusDir
/
${
sBackupClient
}
"
else
echo
INFO: server
[
$sBackupClient
]
had no reserved slot
_addLog
"IGNORE freeing the connection - [
$sBackupClient
] had no reserved slot"
...
...
@@ -209,6 +242,11 @@
echo
ERROR: no backup client was given
exit
1
fi
# read last backup status
typeset
-i
tsBackupStart
=
0
typeset
-i
tsBackupEnd
=
0
typeset
-i
backupRc
=
-2
# test -r "$sStatusDir/${sBackupClient}" && . "$sStatusDir/${sBackupClient}"
}
function
_listRepodirs
(){
...
...
@@ -229,27 +267,28 @@
function
PUBLIC_backupstatus
(){
typeset
-i
local
ierrors
=
0
local
tbl
=
"%-45s | %-20s | %-20s | %8s | %3s | %
5
s
\n
"
local
tbl
=
"%-45s | %-20s | %-20s | %8s | %3s | %
7s | %
s
\n
"
_showConnectionCount
echo
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
"-------------------------------------------------------------------------------------------------------------------"
printf
"
$tbl
"
" server"
"start"
"end"
"duration"
"rc"
"age [h]"
"size"
echo
"-------------------------------------------------------------------------------------------------------------------
----------
"
for
myserver
in
$(
_getLoggedServers
)
do
# get data
setBackupclient
$myserver
typeset
-i
local
istart
=
"
$(
_getLastBackupstart
)
"
typeset
-i
local
iend
=
"
$(
_getLastBackupend
)
"
typeset
-i
local
bIsRunning
=
$(
_isRunning
)
typeset
-i
local
iLastStatus
=
$(
_getLastBackupstatus
)
size
=
$(
_getBackupsize
)
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
iduration
=
${
iend
}
-
${
istart
}
typeset
-i
local
iage
=
$(
date
+%s
)
-
${
iend
}
typeset
-i
local
iagehours
=
$iage
/60/60
# check values
...
...
@@ -261,11 +300,11 @@
test
$iduration
-lt
0
&&
sduration
=
"RUNNING"
sStatusRun
=
"."
test
$iend
-eq
0
&&
sStatusRun
=
"?"
test
$bIsRunning
-eq
1
&&
sStatusRun
=
"R"
test
$iend
-eq
0
&&
sStatusRun
=
"?"
test
$bIsRunning
-eq
1
&&
sStatusRun
=
"R"
# output
printf
"
$tbl
"
"
$sStatusRun
$myserver
"
"
${
tstart
}
"
"
${
tend
}
"
"
${
sduration
}
"
"
$iLastStatus
"
"
${
iagehours
}
"
printf
"
$tbl
"
"
$sStatusRun
$myserver
"
"
${
tstart
}
"
"
${
tend
}
"
"
${
sduration
}
"
"
$iLastStatus
"
"
${
iagehours
}
"
"
$size
"
done
echo
echo
"total :
$(
_getLoggedServers |
wc
-l
)
servers"
...
...
@@ -300,9 +339,9 @@
echo
-n
"Repo to deactivate >"
read
inputdir
if
[
-d
"
$inputdir
"
-a
!
-f
"
$inputdir
/inactive.txt"
]
;
then
echo
-n
"
S
hort message >"
echo
-n
"
Optional s
hort message >"
read
mymessage
echo
"
$(
date
)
|
$mymessage
"
>
"
$inputdir
/inactive.txt"
echo
"
$(
date
)
|
$mymessage
"
>
"
$inputdir
/inactive.txt"
ls
-l
"
$inputdir
/inactive.txt"
else
echo
SKIP
[
$inputdir
]
...
...
@@ -463,8 +502,12 @@
echo
" backupstatus"
echo
" show all servers and their backup times"
echo
echo
" register | unregister [hostname]"
echo
" add/ remove slot for a backup client"
echo
" register [hostname]"
echo
" add a slot for a backup client"
echo
echo
" unregister [hostname] [statuscode]"
echo
" remove slot for a backup client."
echo
" The statuscode is an integer of the return code."
echo
echo
" setactive"
echo
" Reactivate an inctave backup repo."
...
...
@@ -477,7 +520,7 @@
echo
" status"
echo
" show current reserved slots"
echo
echo
" usage [full|[filter to hostname]]"
echo
" usage [full|[filter to hostname]]
- DEPRECATED
"
echo
" show used diskspace"
echo
" you can set a string to show additionally details if these hosts"
echo
" if you add
\"
full
\"
then details of all hosts will be shown"
...
...
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