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
61be8f6d
Commit
61be8f6d
authored
4 years ago
by
Florent Thiery
Browse files
Options
Downloads
Patches
Plain Diff
optimize local backup check, fixes
#33097
parent
4655573c
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/scripts/test_backup.py
+17
-11
17 additions, 11 deletions
tests/scripts/test_backup.py
with
17 additions
and
11 deletions
tests/scripts/test_backup.py
+
17
−
11
View file @
61be8f6d
...
...
@@ -137,7 +137,7 @@ def check_backup_is_incremental(path: str) -> bool:
return
all_ok
def
check_local_backup
(
path
:
str
)
->
bool
:
def
check_local_backup
(
backup_folder
:
str
)
->
bool
:
"""
Check that local backup is in a correct state.
:param path: Local backup folder path
...
...
@@ -146,18 +146,17 @@ def check_local_backup(path: str) -> bool:
:rtype: bool
"""
backup_folder
=
os
.
path
.
dirname
(
path
)
print
(
"
Checking {}:
"
.
format
(
backup_folder
))
all_ok
=
True
latest
=
os
.
path
.
join
(
backup_folder
,
"
latest
"
)
if
backup_folder
.
endswith
(
"
.disabled
"
):
latest
=
backup_folder
/
"
latest
"
if
backup_folder
.
name
.
endswith
(
"
.disabled
"
):
# skip if disabled
lg
.
info
(
"
disabled
"
)
elif
os
.
path
.
exists
(
latest
):
elif
latest
.
exists
():
# resolve symbolic link
latest
=
os
.
path
.
realpath
(
latest
)
latest_date
=
os
.
path
.
basename
(
latest
)
latest
=
latest
.
resolve
(
)
latest_date
=
latest
.
name
date
=
datetime
.
strptime
(
latest_date
,
"
%Y-%m-%d-%H%M%S
"
)
now
=
datetime
.
now
()
diff_seconds
=
(
now
-
date
).
total_seconds
()
...
...
@@ -168,7 +167,7 @@ def check_local_backup(path: str) -> bool:
lg
.
success
(
"
less than {} days old
"
.
format
(
MAX_AGE
))
if
not
check_backup_is_incremental
(
backup_folder
):
all_ok
=
False
elif
os
.
path
.
exists
(
os
.
path
.
join
(
backup_folder
,
"
backup.inprogress
"
)):
elif
(
backup_folder
/
"
backup.inprogress
"
)
.
exists
(
):
lg
.
warning
(
"
still running
"
)
all_ok
=
False
else
:
...
...
@@ -190,10 +189,17 @@ def check_local_backups(paths: str) -> bool:
all_ok
=
True
folders
=
paths
.
split
(
"
,
"
)
for
folder
in
folders
:
cmd
=
"
find -L {} -maxdepth 4 -name backup.marker
"
.
format
(
folder
)
_
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
for
backup_folder
in
out
.
split
(
"
\n
"
):
backup_root
=
Path
(
folder
)
subfolders
=
{
x
for
x
in
backup_root
.
iterdir
()
if
x
.
is_dir
()}
processed
=
set
()
for
backup_marker
in
backup_root
.
glob
(
"
*/backup.marker
"
):
backup_folder
=
backup_marker
.
parent
print
(
"
Checking local backups in %s
"
%
backup_folder
)
all_ok
=
min
(
check_local_backup
(
backup_folder
),
all_ok
)
processed
.
add
(
backup_folder
)
unprocessed
=
[
str
(
x
)
for
x
in
subfolders
-
processed
]
if
len
(
unprocessed
):
lg
.
warning
(
"
Warning, found non-mediavault folders under : %s
"
%
unprocessed
)
return
all_ok
...
...
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