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
e6938020
Commit
e6938020
authored
Jul 27, 2015
by
Leo Koppelkamm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename max_age to min_age
Also clarify a comment and remove an unneeded type check
parent
fa0dd684
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
20 deletions
+17
-20
backup.py
management/backup.py
+13
-16
system-backup.html
management/templates/system-backup.html
+4
-4
No files found.
management/backup.py
View file @
e6938020
...
...
@@ -18,10 +18,11 @@ from utils import exclusive_process, load_environment, shell, wait_for_service
backup_root
=
os
.
path
.
join
(
load_environment
()[
"STORAGE_ROOT"
],
'backup'
)
# Default settings
# Destroy backups when the most recent increment in the chain
# that depends on it is this many days old.
# min_age_in_days is the minimum amount of days a backup will be kept before
# it is eligble to be removed. Backups might be kept much longer if there's no
# new full backup yet.
default_config
=
{
"m
ax
_age_in_days"
:
3
,
"m
in
_age_in_days"
:
3
,
"target"
:
"file://"
+
os
.
path
.
join
(
backup_root
,
'encrypted'
)
}
...
...
@@ -101,11 +102,11 @@ def backup_status(env):
# when the threshold is met.
deleted_in
=
None
if
incremental_count
>
0
and
first_full_size
is
not
None
:
deleted_in
=
"approx.
%
d days"
%
round
(
config
[
"m
ax
_age_in_days"
]
+
(
.5
*
first_full_size
-
incremental_size
)
/
(
incremental_size
/
incremental_count
)
+
.5
)
deleted_in
=
"approx.
%
d days"
%
round
(
config
[
"m
in
_age_in_days"
]
+
(
.5
*
first_full_size
-
incremental_size
)
/
(
incremental_size
/
incremental_count
)
+
.5
)
# When will a backup be deleted?
saw_full
=
False
days_ago
=
now
-
datetime
.
timedelta
(
days
=
config
[
"m
ax
_age_in_days"
])
days_ago
=
now
-
datetime
.
timedelta
(
days
=
config
[
"m
in
_age_in_days"
])
for
bak
in
backups
:
if
deleted_in
:
# Subsequent backups are deleted when the most recent increment
...
...
@@ -248,7 +249,7 @@ def perform_backup(full_backup):
shell
(
'check_call'
,
[
"/usr/bin/duplicity"
,
"remove-older-than"
,
"
%
dD"
%
config
[
"m
ax
_age_in_days"
],
"
%
dD"
%
config
[
"m
in
_age_in_days"
],
"--archive-dir"
,
backup_cache_dir
,
"--force"
,
config
[
"target"
]
...
...
@@ -307,17 +308,17 @@ def run_duplicity_verification():
],
get_env
())
def
backup_set_custom
(
target
,
target_user
,
target_pass
,
m
ax
_age
):
def
backup_set_custom
(
target
,
target_user
,
target_pass
,
m
in
_age
):
config
=
get_backup_config
()
# m
ax
_age must be an int
if
isinstance
(
m
ax
_age
,
str
):
m
ax_age
=
int
(
max
_age
)
# m
in
_age must be an int
if
isinstance
(
m
in
_age
,
str
):
m
in_age
=
int
(
min
_age
)
config
[
"target"
]
=
target
config
[
"target_user"
]
=
target_user
config
[
"target_pass"
]
=
target_pass
config
[
"m
ax_age_in_days"
]
=
max
_age
config
[
"m
in_age_in_days"
]
=
min
_age
write_backup_config
(
config
)
...
...
@@ -332,11 +333,7 @@ def get_backup_config():
merged_config
=
default_config
.
copy
()
merged_config
.
update
(
config
)
# max_age must be an int
if
isinstance
(
merged_config
[
"max_age_in_days"
],
str
):
merged_config
[
"max_age_in_days"
]
=
int
(
merged_config
[
"max_age_in_days"
])
return
config
def
write_backup_config
(
newconfig
):
...
...
management/templates/system-backup.html
View file @
e6938020
...
...
@@ -26,7 +26,7 @@
<div
class=
"form-group"
>
<label
for=
"target"
class=
"col-sm-2 control-label"
>
Maximum time to keep old backups (in days)
</label>
<div
class=
"col-sm-8"
>
<input
type=
"number"
class=
"form-control"
rows=
"1"
id=
"m
ax
-age"
></input>
<input
type=
"number"
class=
"form-control"
rows=
"1"
id=
"m
in
-age"
></input>
</div>
</div>
<div
class=
"form-group form-advanced"
>
...
...
@@ -147,7 +147,7 @@ function show_custom_backup() {
$
(
"
#target-type
"
).
val
(
target_type
);
$
(
"
#target-user
"
).
val
(
r
.
target_user
);
$
(
"
#target-pass
"
).
val
(
r
.
target_pass
);
$
(
"
#m
ax-age
"
).
val
(
r
.
max
_age_in_days
);
$
(
"
#m
in-age
"
).
val
(
r
.
min
_age_in_days
);
toggle_form
()
})
}
...
...
@@ -157,7 +157,7 @@ function set_custom_backup() {
var
target_type
=
$
(
"
#target-type
"
).
val
();
var
target_user
=
$
(
"
#target-user
"
).
val
();
var
target_pass
=
$
(
"
#target-pass
"
).
val
();
var
m
ax_age
=
$
(
"
#max
-age
"
).
val
();
var
m
in_age
=
$
(
"
#min
-age
"
).
val
();
api
(
"
/system/backup/custom
"
,
"
POST
"
,
...
...
@@ -165,7 +165,7 @@ function set_custom_backup() {
target
:
target
,
target_user
:
target_user
,
target_pass
:
target_pass
,
m
ax_age
:
max
_age
m
in_age
:
min
_age
},
function
(
r
)
{
// Responses are multiple lines of pre-formatted text.
...
...
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