Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
e288d773
Commit
e288d773
authored
Jan 02, 2016
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backups: trap an error that occurs as early as getting the current backup status
parent
5ae75e72
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
10 deletions
+22
-10
backup.py
management/backup.py
+13
-9
daemon.py
management/daemon.py
+4
-1
system-backup.html
management/templates/system-backup.html
+5
-0
No files found.
management/backup.py
View file @
e288d773
#!/usr/bin/python3
#!/usr/bin/python3
# This script performs a backup of all user data:
# This script performs a backup of all user data:
# 1) System services are stopped while a copy of user data is made.
# 1) System services are stopped.
# 2) An incremental encrypted backup is made using duplicity into the
# 2) An incremental encrypted backup is made using duplicity.
# directory STORAGE_ROOT/backup/encrypted. The password used for
# encryption is stored in backup/secret_key.txt.
# 3) The stopped services are restarted.
# 3) The stopped services are restarted.
#
5
) STORAGE_ROOT/backup/after-backup is executd if it exists.
#
4
) STORAGE_ROOT/backup/after-backup is executd if it exists.
import
os
,
os
.
path
,
shutil
,
glob
,
re
,
datetime
import
os
,
os
.
path
,
shutil
,
glob
,
re
,
datetime
,
sys
import
dateutil.parser
,
dateutil
.
relativedelta
,
dateutil
.
tz
import
dateutil.parser
,
dateutil
.
relativedelta
,
dateutil
.
tz
import
rtyaml
import
rtyaml
...
@@ -65,8 +63,8 @@ def backup_status(env):
...
@@ -65,8 +63,8 @@ def backup_status(env):
trap
=
True
)
trap
=
True
)
if
code
!=
0
:
if
code
!=
0
:
# Command failed. This is likely due to an improperly configured remote
# Command failed. This is likely due to an improperly configured remote
# destination for the backups.
# destination for the backups
or the last backup job terminated unexpectedly
.
r
eturn
{
}
r
aise
Exception
(
"Something is wrong with the backup: "
+
collection_status
)
for
line
in
collection_status
.
split
(
'
\n
'
):
for
line
in
collection_status
.
split
(
'
\n
'
):
if
line
.
startswith
(
" full"
)
or
line
.
startswith
(
" inc"
):
if
line
.
startswith
(
" full"
)
or
line
.
startswith
(
" inc"
):
backup
=
parse_line
(
line
)
backup
=
parse_line
(
line
)
...
@@ -217,7 +215,13 @@ def perform_backup(full_backup):
...
@@ -217,7 +215,13 @@ def perform_backup(full_backup):
# will fail. Otherwise do a full backup when the size of
# will fail. Otherwise do a full backup when the size of
# the increments since the most recent full backup are
# the increments since the most recent full backup are
# large.
# large.
full_backup
=
full_backup
or
should_force_full
(
env
)
try
:
full_backup
=
full_backup
or
should_force_full
(
env
)
except
Exception
as
e
:
# This was the first call to duplicity, and there might
# be an error already.
print
(
e
)
sys
.
exit
(
1
)
# Stop services.
# Stop services.
shell
(
'check_call'
,
[
"/usr/sbin/service"
,
"php5-fpm"
,
"stop"
])
shell
(
'check_call'
,
[
"/usr/sbin/service"
,
"php5-fpm"
,
"stop"
])
...
...
management/daemon.py
View file @
e288d773
...
@@ -422,7 +422,10 @@ def do_updates():
...
@@ -422,7 +422,10 @@ def do_updates():
@
authorized_personnel_only
@
authorized_personnel_only
def
backup_status
():
def
backup_status
():
from
backup
import
backup_status
from
backup
import
backup_status
return
json_response
(
backup_status
(
env
))
try
:
return
json_response
(
backup_status
(
env
))
except
Exception
as
e
:
return
json_response
({
"error"
:
str
(
e
)
})
@
app
.
route
(
'/system/backup/config'
,
methods
=
[
"GET"
])
@
app
.
route
(
'/system/backup/config'
,
methods
=
[
"GET"
])
@
authorized_personnel_only
@
authorized_personnel_only
...
...
management/templates/system-backup.html
View file @
e288d773
...
@@ -121,6 +121,11 @@ function show_system_backup() {
...
@@ -121,6 +121,11 @@ function show_system_backup() {
"
GET
"
,
"
GET
"
,
{
},
{
},
function
(
r
)
{
function
(
r
)
{
if
(
r
.
error
)
{
show_modal_error
(
"
Backup Error
"
,
$
(
"
<pre/>
"
).
text
(
r
.
error
));
return
;
}
$
(
'
#backup-status tbody
'
).
html
(
""
);
$
(
'
#backup-status tbody
'
).
html
(
""
);
var
total_disk_size
=
0
;
var
total_disk_size
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment