Features: 1) Introduced AbsoluteFTPStorage class for path customization in FTP storage; 2) Updated dbbackup settings to use AbsoluteFTPStorage for FTP storage configurations.

Fixes: 1) Corrected `DBBACKUP_PATH` default to ensure proper backup directory structure.

Extra: 1) Minor cleanup in FTP storage configuration handling.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-08-05 21:08:32 +03:00
parent 2cbea05ea7
commit e373f28358
2 changed files with 14 additions and 3 deletions

11
evibes/ftpstorage.py Normal file
View file

@ -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

View file

@ -13,7 +13,7 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS
dbbackup_server_type = getenv("DBBACKUP_TYPE", "sftp") dbbackup_server_type = getenv("DBBACKUP_TYPE", "sftp")
project_name = getenv("EVIBES_PROJECT_NAME", "evibes_common").lower().replace(" ", "_") 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("/") cleaned = raw_path.strip("/")
remote_dir = f"{cleaned}/" remote_dir = f"{cleaned}/"
@ -35,13 +35,13 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS
} }
case "ftp": case "ftp":
DBBACKUP_STORAGE = "storages.backends.ftp.FTPStorage" DBBACKUP_STORAGE = "evibes.ftpstorage.AbsoluteFTPStorage"
DBBACKUP_STORAGE_OPTIONS = { DBBACKUP_STORAGE_OPTIONS = {
"location": ( "location": (
f"ftp://{getenv('DBBACKUP_USER')}:" f"ftp://{getenv('DBBACKUP_USER')}:"
f"{getenv('DBBACKUP_PASS')}@" f"{getenv('DBBACKUP_PASS')}@"
f"{getenv('DBBACKUP_HOST')}:21/" f"{getenv('DBBACKUP_HOST')}:21/"
f"{remote_dir}" f"{raw_path}"
), ),
} }