| 1 |
import socket |
| 2 |
import tempfile |
| 3 |
|
| 4 |
from django.conf import settings |
| 5 |
|
| 6 |
# Raise an exception if DBBACKUP_STORAGE or DBBACKUP_STORAGE_OPTIONS is used |
| 7 |
if hasattr(settings, "DBBACKUP_STORAGE") or hasattr(settings, "DBBACKUP_STORAGE_OPTIONS"): |
| 8 |
msg = ( |
| 9 |
"The settings DBBACKUP_STORAGE and DBBACKUP_STORAGE_OPTIONS have been " |
| 10 |
"deprecated in favor of using Django Storages configuration. " |
| 11 |
"Please refer to the documentation for more details." |
| 12 |
) |
| 13 |
raise RuntimeError(msg) |
| 14 |
|
| 15 |
DATABASES = getattr(settings, "DBBACKUP_DATABASES", list(settings.DATABASES.keys())) |
| 16 |
HOSTNAME = getattr(settings, "DBBACKUP_HOSTNAME", socket.gethostname()) |
| 17 |
TMP_DIR = getattr(settings, "DBBACKUP_TMP_DIR", tempfile.gettempdir()) |
| 18 |
TMP_FILE_MAX_SIZE = getattr(settings, "DBBACKUP_TMP_FILE_MAX_SIZE", 10 * 1024 * 1024) |
| 19 |
TMP_FILE_READ_SIZE = getattr(settings, "DBBACKUP_TMP_FILE_READ_SIZE", 1024 * 1000) |
| 20 |
CLEANUP_KEEP = getattr(settings, "DBBACKUP_CLEANUP_KEEP", 10) |
| 21 |
CLEANUP_KEEP_MEDIA = getattr(settings, "DBBACKUP_CLEANUP_KEEP_MEDIA", CLEANUP_KEEP) |
| 22 |
CLEANUP_KEEP_FILTER = getattr(settings, "DBBACKUP_CLEANUP_KEEP_FILTER", lambda x: False) |
| 23 |
MEDIA_PATH = getattr(settings, "DBBACKUP_MEDIA_PATH", settings.MEDIA_ROOT) |
| 24 |
DATE_FORMAT = getattr(settings, "DBBACKUP_DATE_FORMAT", "%Y-%m-%d-%H%M%S") |
| 25 |
FILENAME_TEMPLATE = getattr( |
| 26 |
settings, |
| 27 |
"DBBACKUP_FILENAME_TEMPLATE", |
| 28 |
"{databasename}-{servername}-{datetime}.{extension}", |
| 29 |
) |
| 30 |
MEDIA_FILENAME_TEMPLATE = getattr(settings, "DBBACKUP_MEDIA_FILENAME_TEMPLATE", "{servername}-{datetime}.{extension}") |
| 31 |
GPG_ALWAYS_TRUST = getattr(settings, "DBBACKUP_GPG_ALWAYS_TRUST", False) |
| 32 |
GPG_RECIPIENT = GPG_ALWAYS_TRUST = getattr(settings, "DBBACKUP_GPG_RECIPIENT", None) |
| 33 |
STORAGES_DBBACKUP_ALIAS = "dbbackup" |
| 34 |
DJANGO_STORAGES = getattr(settings, "STORAGES", {}) |
| 35 |
storage: dict = DJANGO_STORAGES.get(STORAGES_DBBACKUP_ALIAS, {}) |
| 36 |
STORAGE = storage.get("BACKEND", "django.core.files.storage.FileSystemStorage") |
| 37 |
STORAGE_OPTIONS = storage.get("OPTIONS", {}) |
| 38 |
CONNECTORS = getattr(settings, "DBBACKUP_CONNECTORS", {}) |
| 39 |
CUSTOM_CONNECTOR_MAPPING = getattr(settings, "DBBACKUP_CONNECTOR_MAPPING", {}) |
| 40 |
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
| 41 |
SEND_EMAIL = getattr(settings, "DBBACKUP_SEND_EMAIL", True) |
| 42 |
SERVER_EMAIL = getattr(settings, "DBBACKUP_SERVER_EMAIL", settings.SERVER_EMAIL) |
| 43 |
ADMINS = getattr(settings, "DBBACKUP_ADMIN", settings.ADMINS) |
| 44 |
EMAIL_SUBJECT_PREFIX = getattr(settings, "DBBACKUP_EMAIL_SUBJECT_PREFIX", "[dbbackup] ") |
| 45 |
BACKUP_METADATA_SETTER = getattr(settings, "DBBACKUP_BACKUP_METADATA_SETTER", None) |
| 46 |
RESTORE_METADATA_VALIDATOR = getattr(settings, "DBBACKUP_RESTORE_METADATA_VALIDATOR", None) |