|
1 | | -# DO NOT IMPORT THIS BEFORE django.configure() has been run! |
2 | | - |
3 | 1 | import socket |
4 | 2 | import tempfile |
5 | 3 |
|
6 | 4 | from django.conf import settings |
7 | 5 |
|
8 | | -DATABASES = getattr(settings, "DBBACKUP_DATABASES", list(settings.DATABASES.keys())) |
| 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 | + raise RuntimeError( |
| 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 | + ) |
9 | 13 |
|
10 | | -# Fake host |
| 14 | +DATABASES = getattr(settings, "DBBACKUP_DATABASES", list(settings.DATABASES.keys())) |
11 | 15 | HOSTNAME = getattr(settings, "DBBACKUP_HOSTNAME", socket.gethostname()) |
12 | | - |
13 | | -# Directory to use for temporary files |
14 | 16 | TMP_DIR = getattr(settings, "DBBACKUP_TMP_DIR", tempfile.gettempdir()) |
15 | 17 | TMP_FILE_MAX_SIZE = getattr(settings, "DBBACKUP_TMP_FILE_MAX_SIZE", 10 * 1024 * 1024) |
16 | 18 | TMP_FILE_READ_SIZE = getattr(settings, "DBBACKUP_TMP_FILE_READ_SIZE", 1024 * 1000) |
17 | | - |
18 | | -# Number of old backup files to keep |
19 | 19 | CLEANUP_KEEP = getattr(settings, "DBBACKUP_CLEANUP_KEEP", 10) |
20 | 20 | CLEANUP_KEEP_MEDIA = getattr(settings, "DBBACKUP_CLEANUP_KEEP_MEDIA", CLEANUP_KEEP) |
21 | 21 | CLEANUP_KEEP_FILTER = getattr(settings, "DBBACKUP_CLEANUP_KEEP_FILTER", lambda x: False) |
22 | | - |
23 | 22 | MEDIA_PATH = getattr(settings, "DBBACKUP_MEDIA_PATH", settings.MEDIA_ROOT) |
24 | | - |
25 | 23 | DATE_FORMAT = getattr(settings, "DBBACKUP_DATE_FORMAT", "%Y-%m-%d-%H%M%S") |
26 | 24 | FILENAME_TEMPLATE = getattr( |
27 | 25 | settings, |
28 | 26 | "DBBACKUP_FILENAME_TEMPLATE", |
29 | 27 | "{databasename}-{servername}-{datetime}.{extension}", |
30 | 28 | ) |
31 | 29 | MEDIA_FILENAME_TEMPLATE = getattr(settings, "DBBACKUP_MEDIA_FILENAME_TEMPLATE", "{servername}-{datetime}.{extension}") |
32 | | - |
33 | 30 | GPG_ALWAYS_TRUST = getattr(settings, "DBBACKUP_GPG_ALWAYS_TRUST", False) |
34 | 31 | GPG_RECIPIENT = GPG_ALWAYS_TRUST = getattr(settings, "DBBACKUP_GPG_RECIPIENT", None) |
35 | | - |
36 | 32 | STORAGES_DBBACKUP_ALIAS = "dbbackup" |
37 | 33 | DJANGO_STORAGES = getattr(settings, "STORAGES", {}) |
38 | 34 | storage: dict = DJANGO_STORAGES.get(STORAGES_DBBACKUP_ALIAS, {}) |
39 | 35 | STORAGE = storage.get("BACKEND", "django.core.files.storage.FileSystemStorage") |
40 | 36 | STORAGE_OPTIONS = storage.get("OPTIONS", {}) |
41 | | - |
42 | 37 | CONNECTORS = getattr(settings, "DBBACKUP_CONNECTORS", {}) |
43 | 38 | CUSTOM_CONNECTOR_MAPPING = getattr(settings, "DBBACKUP_CONNECTOR_MAPPING", {}) |
44 | | - |
45 | 39 | DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
46 | | - |
47 | | -# Mail |
48 | 40 | SEND_EMAIL = getattr(settings, "DBBACKUP_SEND_EMAIL", True) |
49 | 41 | SERVER_EMAIL = getattr(settings, "DBBACKUP_SERVER_EMAIL", settings.SERVER_EMAIL) |
50 | 42 | ADMINS = getattr(settings, "DBBACKUP_ADMIN", settings.ADMINS) |
|
0 commit comments