Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
a43c57f6
Commit
a43c57f6
authored
7 years ago
by
Florent Thiery
Browse files
Options
Downloads
Patches
Plain Diff
add check to verify that backup is incremental refs
#23246
parent
574c91ae
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
tests/test_backup.py
+28
-5
28 additions, 5 deletions
tests/test_backup.py
with
28 additions
and
5 deletions
tests/test_backup.py
+
28
−
5
View file @
a43c57f6
...
...
@@ -11,7 +11,7 @@ import os
import
socket
import
subprocess
import
sys
import
glob
GREEN
=
'
\033
[92m
'
RED
=
'
\033
[91m
'
...
...
@@ -19,12 +19,15 @@ DEF = '\033[0m'
MAX_AGE_H
=
48
def
print_red
(
string
):
print
(
RED
+
string
+
DEF
)
def
print_green
(
string
):
print
(
GREEN
+
string
+
DEF
)
def
test_ssh
(
ip
):
cmd
=
'
ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp
'
%
ip
print
(
'
Connecting to MediaVault: %s
'
%
cmd
)
...
...
@@ -64,7 +67,7 @@ def test_backup_space(server=None, path="/backup"):
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
if
status
==
0
:
dev
,
total
,
used
,
free
,
used_perc
,
mount
=
out
.
strip
().
split
()
used_perc
=
int
(
used_perc
.
replace
(
'
%
'
,
''
))
used_perc
=
int
(
used_perc
.
replace
(
'
%
'
,
''
))
if
used_perc
>
80
:
print
(
'
There is less than 20% of available space for backups
'
)
return
False
...
...
@@ -75,6 +78,24 @@ def test_backup_space(server=None, path="/backup"):
print
(
'
Failed to check backup space
'
)
return
False
def
check_backup_is_incremental
(
path
):
dirs
=
os
.
listdir
(
path
)
dirs
.
sort
()
for
d
in
dirs
:
num_folders
=
0
if
os
.
path
.
isdir
(
d
):
media
=
glob
.
glob
(
os
.
path
.
join
(
path
,
d
,
"
*/msinstance/media/resources/
"
))
for
m
in
media
:
num_folders
+=
len
(
os
.
listdir
(
m
))
print
(
'
%s: %s
'
%
(
d
,
num_folders
))
if
num_folders
==
0
:
print
(
'
Folder %s is empty, this indicates non-incremental backups (we are expecting links)
'
%
d
)
return
False
return
True
def
check_local_backup
(
path
):
all_ok
=
True
backup_folder
=
os
.
path
.
dirname
(
path
)
...
...
@@ -87,11 +108,13 @@ def check_local_backup(path):
d
=
datetime
.
strptime
(
date
,
'
%Y-%m-%d-%H%M%S
'
)
now
=
datetime
.
now
()
diff_seconds
=
(
now
-
d
).
total_seconds
()
if
diff_seconds
>
MAX_AGE_H
*
3600
:
print_red
(
'
Backup %s is older than %sh (%ih)
'
%
(
backup_folder
,
MAX_AGE_H
,
diff_seconds
/
3600
))
all_ok
=
False
if
diff_seconds
>
MAX_AGE_H
*
3600
:
print_red
(
'
Backup %s is older than %sh (%ih)
'
%
(
backup_folder
,
MAX_AGE_H
,
diff_seconds
/
3600
))
all_ok
=
False
else
:
print_green
(
'
Backup %s is fine
'
%
backup_folder
)
if
not
check_backup_is_incremental
(
backup_folder
):
all_ok
=
False
elif
os
.
path
.
exists
(
os
.
path
.
join
(
backup_folder
,
'
backup.inprogress
'
)):
print_red
(
'
Initial backup %s still running
'
%
backup_folder
)
all_ok
=
False
...
...
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