Features: 1) Add support for multiple database backup types (SFTP, FTP) with dynamic configuration;
Fixes: 1) Correct formatting issue in `0036_vendor_b2b_auth_token_vendor_users` migration file; Extra: 1) Update environment file generation scripts to accommodate new DBBACKUP_TYPE configuration; 2) Add import for `ImproperlyConfigured` in `dbbackup.py`.
This commit is contained in:
parent
f39737d624
commit
877f71f614
4 changed files with 40 additions and 28 deletions
|
|
@ -6,7 +6,6 @@ from django.db import migrations, models
|
|||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0035_alter_brand_slug_alter_category_slug_and_more"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
|
|
@ -26,8 +25,6 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name="vendor",
|
||||
name="users",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="vendors", to=settings.AUTH_USER_MODEL
|
||||
),
|
||||
field=models.ManyToManyField(blank=True, related_name="vendors", to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from os import getenv
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
DBBACKUP_CONNECTORS = {
|
||||
"default": {
|
||||
"SINGLE_TRANSACTION": False,
|
||||
|
|
@ -8,14 +10,17 @@ DBBACKUP_CONNECTORS = {
|
|||
}
|
||||
}
|
||||
|
||||
if getenv("DBBACKUP_SFTP_HOST") and getenv("DBBACKUP_SFTP_USER") and getenv("DBBACKUP_SFTP_PASS"):
|
||||
if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS"):
|
||||
dbbackup_server_type = getenv("DBBACKUP_TYPE", "sftp")
|
||||
match dbbackup_server_type:
|
||||
case "sftp":
|
||||
DBBACKUP_STORAGE = "storages.backends.sftpstorage.SFTPStorage"
|
||||
DBBACKUP_STORAGE_OPTIONS = {
|
||||
"host": getenv("DBBACKUP_SFTP_HOST"),
|
||||
"host": getenv("DBBACKUP_HOST"),
|
||||
"root_path": "/db_backups/",
|
||||
"params": {
|
||||
"username": getenv("DBBACKUP_SFTP_USER"),
|
||||
"password": getenv("DBBACKUP_SFTP_PASS"),
|
||||
"username": getenv("DBBACKUP_USER"),
|
||||
"password": getenv("DBBACKUP_PASS"),
|
||||
"allow_agent": False,
|
||||
"look_for_keys": False,
|
||||
},
|
||||
|
|
@ -23,6 +28,13 @@ if getenv("DBBACKUP_SFTP_HOST") and getenv("DBBACKUP_SFTP_USER") and getenv("DBB
|
|||
"file_mode": 0o600,
|
||||
"dir_mode": 0o700,
|
||||
}
|
||||
case "ftp":
|
||||
DBBACKUP_STORAGE = "storages.backends.ftp.FTPStorage"
|
||||
DBBACKUP_STORAGE_OPTIONS = {
|
||||
"location": f"ftp://{getenv('DBBACKUP_USER')}:{getenv('DBBACKUP_PASS')}@{getenv('DBBACKUP_HOST')}:21",
|
||||
}
|
||||
case _:
|
||||
raise ImproperlyConfigured(f"Invalid DBBACKUP_TYPE: {dbbackup_server_type}")
|
||||
else:
|
||||
DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage"
|
||||
DBBACKUP_STORAGE_OPTIONS = {"location": "/app/db_backups/"}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,10 @@ POSTGRES_DB=$(prompt_default POSTGRES_DB evibes)
|
|||
POSTGRES_USER=$(prompt_default POSTGRES_USER evibes_user)
|
||||
POSTGRES_PASSWORD=$(prompt_autogen POSTGRES_PASSWORD 16)
|
||||
|
||||
DBBACKUP_SFTP_HOST=$(prompt_default DBBACKUP_SFTP_HOST "Your SFTP backup host")
|
||||
DBBACKUP_SFTP_USER=$(prompt_default DBBACKUP_SFTP_USER "The username to use to log in to that host")
|
||||
DBBACKUP_SFTP_PASS=$(prompt_default DBBACKUP_SFTP_PASS "The password to use to log in to that host")
|
||||
DBBACKUP_TYPE=$(prompt_default DBBACKUP_TYPE "Your backup connection type")
|
||||
DBBACKUP_HOST=$(prompt_default DBBACKUP_HOST "Your SFTP backup host")
|
||||
DBBACKUP_USER=$(prompt_default DBBACKUP_USER "The username to use to log in to that host")
|
||||
DBBACKUP_PASS=$(prompt_default DBBACKUP_PASS "The password to use to log in to that host")
|
||||
|
||||
ELASTIC_PASSWORD=$(prompt_autogen ELASTIC_PASSWORD 16)
|
||||
REDIS_PASSWORD=$(prompt_autogen REDIS_PASSWORD 16)
|
||||
|
|
|
|||
|
|
@ -67,9 +67,10 @@ $POSTGRES_DB = Prompt-Default 'POSTGRES_DB' 'evibes'
|
|||
$POSTGRES_USER = Prompt-Default 'POSTGRES_USER' 'evibes_user'
|
||||
$POSTGRES_PASSWORD = Prompt-AutoGen 'POSTGRES_PASSWORD' 16
|
||||
|
||||
$DBBACKUP_SFTP_HOST = Prompt-Default 'DBBACKUP_SFTP_HOST' 'Your SFTP backup host'
|
||||
$DBBACKUP_SFTP_USER = Prompt-Default 'DBBACKUP_SFTP_USER' 'The username to use to log in to that host'
|
||||
$DBBACKUP_SFTP_PASS = Prompt-Default 'DBBACKUP_SFTP_PASS' 'The password to use to log in to that host'
|
||||
$DBBACKUP_TYPE = Prompt-Default 'DBBACKUP_TYPE' 'Your backup connection type'
|
||||
$DBBACKUP_HOST = Prompt-Default 'DBBACKUP_HOST' 'Your SFTP backup host'
|
||||
$DBBACKUP_USER = Prompt-Default 'DBBACKUP_USER' 'The username to use to log in to that host'
|
||||
$DBBACKUP_PASS = Prompt-Default 'DBBACKUP_PASS' 'The password to use to log in to that host'
|
||||
|
||||
$ELASTIC_PASSWORD = Prompt-AutoGen 'ELASTIC_PASSWORD' 16
|
||||
|
||||
|
|
@ -113,9 +114,10 @@ $lines = @(
|
|||
"POSTGRES_USER=""$POSTGRES_USER"""
|
||||
"POSTGRES_PASSWORD=""$POSTGRES_PASSWORD"""
|
||||
""
|
||||
"DBBACKUP_SFTP_HOST=""$DBBACKUP_SFTP_HOST"""
|
||||
"DBBACKUP_SFTP_USER=""$DBBACKUP_SFTP_USER"""
|
||||
"DBBACKUP_SFTP_PASS=""$DBBACKUP_SFTP_PASS"""
|
||||
"DBBACKUP_TYPE=""$DBBACKUP_TYPE"""
|
||||
"DBBACKUP_HOST=""$DBBACKUP_HOST"""
|
||||
"DBBACKUP_USER=""$DBBACKUP_USER"""
|
||||
"DBBACKUP_PASS=""$DBBACKUP_PASS"""
|
||||
""
|
||||
"ELASTIC_PASSWORD=""$ELASTIC_PASSWORD"""
|
||||
""
|
||||
|
|
|
|||
Loading…
Reference in a new issue