diff --git a/evibes/ftpstorage.py b/evibes/ftpstorage.py new file mode 100644 index 00000000..78165461 --- /dev/null +++ b/evibes/ftpstorage.py @@ -0,0 +1,11 @@ +from urllib.parse import urlparse + +from storages.backends.ftp import FTPStorage + + +class AbsoluteFTPStorage(FTPStorage): # type: ignore + def _get_config(self): + cfg = super()._get_config() + url = urlparse(self.location) + cfg["path"] = url.path or cfg["path"] + return cfg diff --git a/evibes/settings/dbbackup.py b/evibes/settings/dbbackup.py index f0278262..cec40f83 100644 --- a/evibes/settings/dbbackup.py +++ b/evibes/settings/dbbackup.py @@ -13,7 +13,7 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS dbbackup_server_type = getenv("DBBACKUP_TYPE", "sftp") project_name = getenv("EVIBES_PROJECT_NAME", "evibes_common").lower().replace(" ", "_") - raw_path = getenv("DBBACKUP_PATH", f"backups/{project_name}") + raw_path = getenv("DBBACKUP_PATH", f"/backups/{project_name}/") cleaned = raw_path.strip("/") remote_dir = f"{cleaned}/" @@ -35,13 +35,13 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS } case "ftp": - DBBACKUP_STORAGE = "storages.backends.ftp.FTPStorage" + DBBACKUP_STORAGE = "evibes.ftpstorage.AbsoluteFTPStorage" DBBACKUP_STORAGE_OPTIONS = { "location": ( f"ftp://{getenv('DBBACKUP_USER')}:" f"{getenv('DBBACKUP_PASS')}@" f"{getenv('DBBACKUP_HOST')}:21/" - f"{remote_dir}" + f"{raw_path}" ), }