mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-03 00:07:05 +00:00
The conversion of backup configuration is made in setup/migrate.py.
This commit is contained in:
parent
928ca81397
commit
607ad27941
@ -646,50 +646,6 @@ def get_backup_config(env):
|
||||
custom_config = rtyaml.load(f)
|
||||
if not isinstance(custom_config, dict): raise ValueError() # caught below
|
||||
|
||||
# Converting the previous configuration (which was not very clear)
|
||||
# into the new configuration format which also provides
|
||||
# a "type" attribute to distinguish the type of backup.
|
||||
if "type" not in custom_config:
|
||||
scheme = custom_config["target"].split(":")[0]
|
||||
if scheme == "off":
|
||||
custom_config = {
|
||||
"type": "off"
|
||||
}
|
||||
elif scheme == "file":
|
||||
custom_config = {
|
||||
"type": "local",
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "rsync":
|
||||
custom_config = {
|
||||
"type": "rsync",
|
||||
"target_url": custom_config["target"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "s3":
|
||||
import urllib.parse
|
||||
url = urllib.parse.urlparse(custom_config["target"])
|
||||
target_url = url.scheme + ":/" + url.path
|
||||
s3_endpoint_url = "https://" + url.netloc
|
||||
s3_access_key_id = custom_config["target_user"]
|
||||
s3_secret_access_key = custom_config["target_pass"]
|
||||
custom_config = {
|
||||
"type": "s3",
|
||||
"target_url": target_url,
|
||||
"s3_endpoint_url": s3_endpoint_url,
|
||||
"s3_access_key_id": custom_config["target_user"],
|
||||
"s3_secret_access_key": custom_config["target_pass"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "b2":
|
||||
custom_config = {
|
||||
"type": "b2",
|
||||
"target_url": custom_config["target"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
else:
|
||||
raise ValueError("Unexpected scheme during the conversion of the previous config to the new format.")
|
||||
|
||||
config.update(custom_config)
|
||||
except:
|
||||
pass
|
||||
|
@ -191,6 +191,62 @@ def migration_14(env):
|
||||
db = os.path.join(env["STORAGE_ROOT"], 'mail/users.sqlite')
|
||||
shell("check_call", ["sqlite3", db, "CREATE TABLE auto_aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL UNIQUE, destination TEXT NOT NULL, permitted_senders TEXT);"])
|
||||
|
||||
def migration_15(env):
|
||||
backup_configuration_file = os.path.join(env["STORAGE_ROOT"], 'backup', 'custom.yaml')
|
||||
if os.path.exists(backup_configuration_file):
|
||||
import yaml
|
||||
|
||||
with open(backup_configuration_file, 'r') as f:
|
||||
custom_config = yaml.load(f, Loader=yaml.SafeLoader)
|
||||
if not isinstance(custom_config, dict): raise ValueError()
|
||||
|
||||
# Converting the previous configuration (which was not very clear)
|
||||
# into the new configuration format which also provides
|
||||
# a "type" attribute to distinguish the type of backup.
|
||||
scheme = custom_config["target"].split(":")[0]
|
||||
if scheme == "off":
|
||||
custom_config = {
|
||||
"type": "off"
|
||||
}
|
||||
elif scheme == "file":
|
||||
custom_config = {
|
||||
"type": "local",
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "rsync":
|
||||
custom_config = {
|
||||
"type": "rsync",
|
||||
"target_url": custom_config["target"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "s3":
|
||||
import urllib.parse
|
||||
url = urllib.parse.urlparse(custom_config["target"])
|
||||
target_url = url.scheme + ":/" + url.path
|
||||
s3_endpoint_url = "https://" + url.netloc
|
||||
s3_access_key_id = custom_config["target_user"]
|
||||
s3_secret_access_key = custom_config["target_pass"]
|
||||
custom_config = {
|
||||
"type": "s3",
|
||||
"target_url": target_url,
|
||||
"s3_endpoint_url": s3_endpoint_url,
|
||||
"s3_access_key_id": custom_config["target_user"],
|
||||
"s3_secret_access_key": custom_config["target_pass"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
elif scheme == "b2":
|
||||
custom_config = {
|
||||
"type": "b2",
|
||||
"target_url": custom_config["target"],
|
||||
"min_age_in_days": custom_config["min_age_in_days"]
|
||||
}
|
||||
else:
|
||||
raise ValueError("Unexpected scheme during the conversion of the previous config to the new format.")
|
||||
|
||||
|
||||
with open(backup_configuration_file, "w") as f:
|
||||
f.write(yaml.dump(custom_config))
|
||||
|
||||
###########################################################
|
||||
|
||||
def get_current_migration():
|
||||
|
Loading…
Reference in New Issue
Block a user