1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-26 02:57:04 +00:00

Infer target_type from url

This commit is contained in:
Leo Koppelkamm 2015-07-27 22:09:58 +02:00
parent 1e3e34f15f
commit 91e4ea6e2f
3 changed files with 11 additions and 10 deletions

View File

@ -22,8 +22,7 @@ backup_root = os.path.join(load_environment()["STORAGE_ROOT"], 'backup')
# that depends on it is this many days old. # that depends on it is this many days old.
default_config = { default_config = {
"max_age_in_days": 3, "max_age_in_days": 3,
"target": "file://" + os.path.join(backup_root, 'encrypted'), "target": "file://" + os.path.join(backup_root, 'encrypted')
"target_type": "file"
} }
def backup_status(env): def backup_status(env):
@ -164,12 +163,16 @@ def get_env():
env = { "PASSPHRASE" : get_passphrase() } env = { "PASSPHRASE" : get_passphrase() }
if config["target_type"] == 's3': if get_target_type(config) == 's3':
env["AWS_ACCESS_KEY_ID"] = config["target_user"] env["AWS_ACCESS_KEY_ID"] = config["target_user"]
env["AWS_SECRET_ACCESS_KEY"] = config["target_pass"] env["AWS_SECRET_ACCESS_KEY"] = config["target_pass"]
return env return env
def get_target_type(config):
protocol = config["target"].split(":")[0]
return protocol
def perform_backup(full_backup): def perform_backup(full_backup):
env = load_environment() env = load_environment()
@ -267,7 +270,7 @@ def perform_backup(full_backup):
# Change ownership of backups to the user-data user, so that the after-bcakup # Change ownership of backups to the user-data user, so that the after-bcakup
# script can access them. # script can access them.
if config["target_type"] == 'file': if get_target_type(config) == 'file':
shell('check_call', ["/bin/chown", "-R", env["STORAGE_USER"], backup_dir]) shell('check_call', ["/bin/chown", "-R", env["STORAGE_USER"], backup_dir])
# Execute a post-backup script that does the copying to a remote server. # Execute a post-backup script that does the copying to a remote server.
@ -304,7 +307,7 @@ def run_duplicity_verification():
], get_env()) ], get_env())
def backup_set_custom(target, target_user, target_pass, target_type, max_age): def backup_set_custom(target, target_user, target_pass, max_age):
config = get_backup_config() config = get_backup_config()
# max_age must be an int # max_age must be an int
@ -314,7 +317,6 @@ def backup_set_custom(target, target_user, target_pass, target_type, max_age):
config["target"] = target config["target"] = target
config["target_user"] = target_user config["target_user"] = target_user
config["target_pass"] = target_pass config["target_pass"] = target_pass
config["target_type"] = target_type
config["max_age_in_days"] = max_age config["max_age_in_days"] = max_age
write_backup_config(config) write_backup_config(config)

View File

@ -416,7 +416,6 @@ def backup_set_custom():
request.form.get('target', ''), request.form.get('target', ''),
request.form.get('target_user', ''), request.form.get('target_user', ''),
request.form.get('target_pass', ''), request.form.get('target_pass', ''),
request.form.get('target_type', ''),
request.form.get('max_age', '') request.form.get('max_age', '')
)) ))

View File

@ -142,8 +142,9 @@ function show_custom_backup() {
"GET", "GET",
{ }, { },
function(r) { function(r) {
var target_type = r.target.split(':')[0]
$("#target").val(r.target); $("#target").val(r.target);
$("#target-type").val(r.target_type); $("#target-type").val(target_type);
$("#target-user").val(r.target_user); $("#target-user").val(r.target_user);
$("#target-pass").val(r.target_pass); $("#target-pass").val(r.target_pass);
$("#max-age").val(r.max_age_in_days); $("#max-age").val(r.max_age_in_days);
@ -162,7 +163,6 @@ function set_custom_backup() {
"POST", "POST",
{ {
target: target, target: target,
target_type: target_type,
target_user: target_user, target_user: target_user,
target_pass: target_pass, target_pass: target_pass,
max_age: max_age max_age: max_age