django-cloud-backup 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/PKG-INFO +218 -56
- django_cloud_backup-0.1.1/django_cloud_backup.egg-info/PKG-INFO → django_cloud_backup-0.1.2/README.md +201 -77
- django_cloud_backup-0.1.2/cloud_backup/admin.py +29 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup.py +32 -2
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup_azure.py +41 -17
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup_db.py +55 -10
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/config.py +26 -2
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/db_tiers.py +68 -22
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/enhanced_views.py +106 -47
- django_cloud_backup-0.1.2/cloud_backup/management/commands/backup_status.py +30 -0
- django_cloud_backup-0.1.2/cloud_backup/migrations/0001_initial.py +32 -0
- django_cloud_backup-0.1.2/cloud_backup/migrations/__init__.py +0 -0
- django_cloud_backup-0.1.2/cloud_backup/models.py +57 -0
- django_cloud_backup-0.1.2/cloud_backup/runs.py +76 -0
- django_cloud_backup-0.1.2/cloud_backup/sql_functions.py +89 -0
- django_cloud_backup-0.1.2/cloud_backup/status.py +528 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storage_setup.py +115 -49
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storages/azure.py +1 -1
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storages/base.py +37 -4
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storages/gdrive.py +2 -1
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storages/s3.py +123 -19
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/tasks.py +12 -7
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/templates/cloud_backup/info.html +1 -1
- django_cloud_backup-0.1.2/cloud_backup/templates/cloud_backup/runs_content.html +7 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/__init__.py +0 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/test_backup_azure.py +223 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/test_db_tiers.py +185 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/test_extensions.py +130 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/test_s3_trash.py +83 -0
- django_cloud_backup-0.1.2/cloud_backup/tests/test_status.py +477 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/urls.py +8 -1
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/views.py +25 -1
- django_cloud_backup-0.1.1/README.md → django_cloud_backup-0.1.2/django_cloud_backup.egg-info/PKG-INFO +240 -55
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/django_cloud_backup.egg-info/SOURCES.txt +14 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/pyproject.toml +20 -1
- django_cloud_backup-0.1.1/cloud_backup/sql_functions.py +0 -46
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/LICENSE +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/MANIFEST.in +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/__init__.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/apps.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup_azure_s3.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup_local_files.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/backup_s3.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/base_backup.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/compression.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/encryption.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/management/__init__.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/management/commands/__init__.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/management/commands/backup_website.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/management/commands/restore_db.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/management/commands/storage_setup.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/modals.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/prune_backups.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/storages/__init__.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/templates/cloud_backup/backup.html +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/templates/cloud_backup/backup_content.html +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/templates/cloud_backup/storage_setup_content.html +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/cloud_backup/utils.py +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/django_cloud_backup.egg-info/dependency_links.txt +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/django_cloud_backup.egg-info/requires.txt +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/django_cloud_backup.egg-info/top_level.txt +0 -0
- {django_cloud_backup-0.1.1 → django_cloud_backup-0.1.2}/setup.cfg +0 -0
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django-cloud-backup
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Backs up django postgres databases, local folders and S3 folders to Google Drive, S3-compatible storage (AWS, Backblaze B2, Cloudflare R2) or Azure Blob Storage.
|
|
5
5
|
Author: Ian Jones
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/jonesim/django-cloud-backup
|
|
8
|
+
Project-URL: Documentation, https://github.com/jonesim/django-cloud-backup#readme
|
|
9
|
+
Project-URL: Changelog, https://github.com/jonesim/django-cloud-backup/releases
|
|
10
|
+
Project-URL: Issues, https://github.com/jonesim/django-cloud-backup/issues
|
|
11
|
+
Project-URL: Source, https://github.com/jonesim/django-cloud-backup
|
|
12
|
+
Keywords: django,backup,postgres,postgresql,ransomware,immutable,object-lock,worm,s3,backblaze,b2,cloudflare-r2,azure,google-drive,disaster-recovery
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: Django :: 5.2
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: System Administrators
|
|
8
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: System :: Archiving :: Backup
|
|
23
|
+
Classifier: Topic :: System :: Systems Administration
|
|
9
24
|
Classifier: Operating System :: OS Independent
|
|
10
25
|
Requires-Python: >=3.8
|
|
11
26
|
Description-Content-Type: text/markdown
|
|
@@ -21,39 +36,85 @@ Provides-Extra: encryption
|
|
|
21
36
|
Requires-Dist: cryptography; extra == "encryption"
|
|
22
37
|
Dynamic: license-file
|
|
23
38
|
|
|
39
|
+
# django-cloud-backup
|
|
40
|
+
|
|
24
41
|
[](https://badge.fury.io/py/django-cloud-backup)
|
|
25
42
|
|
|
43
|
+
**Django backups that survive your credentials being stolen.**
|
|
44
|
+
|
|
45
|
+
Backs up PostgreSQL databases, local folders, S3 buckets and Azure containers to Google
|
|
46
|
+
Drive, S3-compatible storage (AWS, Backblaze B2, Cloudflare R2) or Azure Blob Storage -
|
|
47
|
+
and then holds them down so that whoever gets into your server cannot destroy them.
|
|
48
|
+
|
|
49
|
+
An attacker who reaches your settings has your backup credentials too. The usual
|
|
50
|
+
arrangement - scheduled dumps to a bucket the application can delete from - fails at
|
|
51
|
+
exactly the moment it is needed: the backups are wiped, or quietly overwritten with
|
|
52
|
+
encrypted copies on the next scheduled run. This package is built for that threat model.
|
|
53
|
+
|
|
54
|
+
## What it does that a scheduled dump does not
|
|
55
|
+
|
|
56
|
+
- **Object Lock retention stamped at upload.** Every dump is immutable for a fixed window,
|
|
57
|
+
topped up by a scheduled task; in `COMPLIANCE` mode not even the bucket owner can shorten
|
|
58
|
+
it. See [Ransomware protection](#ransomware-protection).
|
|
59
|
+
- **An application that never deletes.** With `BACKUP_DB_TIERS` dumps are promoted between
|
|
60
|
+
hourly/daily/monthly prefixes by server-side copy and the bucket's own lifecycle rules do
|
|
61
|
+
all the expiry, so the backup credential needs no delete permission at all. See
|
|
62
|
+
[Lifecycle-managed database backups](#lifecycle-managed-database-backups-s3b2r2).
|
|
63
|
+
- **Changed source files cannot silently overwrite good backups.**
|
|
64
|
+
`BACKUP_CHANGED_FILES = 'protect'` refuses the overwrite and fails the run; `'history'`
|
|
65
|
+
keeps the previous version first. See [Ransomware protection](#ransomware-protection).
|
|
66
|
+
- **Read-only destinations.** A config marked `restore_only` refuses every write and
|
|
67
|
+
generates a read-only key - for the staging box that shares an encrypted settings file
|
|
68
|
+
with live. See [Live, staging and local machines](#live-staging-and-local-machines).
|
|
69
|
+
- **It verifies the bucket is actually configured that way.** The management page queries
|
|
70
|
+
the destination and reports versioning, soft delete, Object Lock and lifecycle rules, and
|
|
71
|
+
flags any hidden version or overwrite the retention policy cannot explain. See
|
|
72
|
+
[Setting up the bucket](#setting-up-the-bucket).
|
|
73
|
+
- **It tells you when the backups stop being current.** Every run is recorded and graded
|
|
74
|
+
against your `CELERY_BEAT_SCHEDULE`, browsable in a Run Log page and served as json at
|
|
75
|
+
`backup/status/` for a monitoring agent. See
|
|
76
|
+
[Checking that the backups are current](#checking-that-the-backups-are-current).
|
|
77
|
+
- **Optional client-side AES-256-GCM encryption**, so the destination never holds
|
|
78
|
+
plaintext. See [Client-side encryption](#client-side-encryption).
|
|
79
|
+
|
|
80
|
+
Alongside that: a Django management UI for browsing, verifying and restoring backups,
|
|
81
|
+
Celery tasks for scheduling, MD5/ETag deduplication, per-schema database backups, and
|
|
82
|
+
several named destinations in one project.
|
|
83
|
+
|
|
84
|
+
A schema dump (`pg_dump -n`) does not include the extensions installed in that schema, so
|
|
85
|
+
each schema dump records their names in its metadata (`extensions`, e.g. `pg_trgm`), and
|
|
86
|
+
restoring it creates any that are missing first. Only extensions installed *in* that
|
|
87
|
+
schema are recorded: one in `public` used by a tenant schema needs `public` restored
|
|
88
|
+
first, and a restore warns when a recorded extension is installed in a different schema.
|
|
89
|
+
The **Drop Restore** button, which runs `DROP SCHEMA ... CASCADE` and so removes the
|
|
90
|
+
extensions too, notes them before dropping and recreates them afterwards in the same
|
|
91
|
+
transaction, which also covers dumps made before this was recorded.
|
|
92
|
+
|
|
93
|
+
## Install
|
|
94
|
+
|
|
95
|
+
pip install django-cloud-backup # Google Drive destination
|
|
96
|
+
pip install django-cloud-backup[s3] # AWS S3, Backblaze B2, Cloudflare R2
|
|
97
|
+
pip install django-cloud-backup[azure] # Azure Blob Storage
|
|
98
|
+
pip install django-cloud-backup[encryption] # client-side encryption
|
|
99
|
+
|
|
100
|
+
settings.py:
|
|
101
|
+
|
|
102
|
+
INSTALLED_APPS = ['cloud_backup', ...]
|
|
103
|
+
BACKUP_ROOT = 'django_backup'
|
|
26
104
|
|
|
27
|
-
|
|
105
|
+
Google Drive is the default destination and needs a service account - the setup walkthrough
|
|
106
|
+
starts below. To back up to a bucket instead, set `BACKUP_STORAGE`; see
|
|
107
|
+
[Choosing a backup destination](#choosing-a-backup-destination).
|
|
28
108
|
|
|
29
|
-
|
|
109
|
+
Already running `django-gdrive-backup`? See
|
|
110
|
+
[Migrating from django-gdrive-backup](#migrating-from-django-gdrive-backup) at the end.
|
|
30
111
|
|
|
31
|
-
|
|
112
|
+
## Setup
|
|
32
113
|
|
|
33
|
-
|
|
34
|
-
|
|
114
|
+
The walkthrough below configures the default Google Drive destination.
|
|
115
|
+
For a bucket destination, skip to [Choosing a backup destination](#choosing-a-backup-destination).
|
|
35
116
|
|
|
36
|
-
|
|
37
|
-
`django-gdrive-backup`
|
|
38
|
-
- `INSTALLED_APPS`: `'gdrive_backup'` → `'cloud_backup'`
|
|
39
|
-
- urls.py: `include('gdrive_backup.urls')` → `include('cloud_backup.urls')`, and any
|
|
40
|
-
reverses/`{% url %}` tags use the `cloud_backup:` namespace instead of `gdrive_backup:`
|
|
41
|
-
- Celery beat schedules: task names are now `cloud_backup.tasks.*`
|
|
42
|
-
(e.g. `cloud_backup.tasks.backup`)
|
|
43
|
-
- Settings renamed: `BACKUP_GDRIVE_DIR` → `BACKUP_ROOT`, `BACKUP_GDRIVE_DB` → `BACKUP_DB_DIR`
|
|
44
|
-
(they apply to every destination backend, not just Google Drive). `BACKUP_TEAM_DRIVE` is
|
|
45
|
-
unchanged.
|
|
46
|
-
- Removed legacy method aliases `backup_db_gdrive`, `restore_gdrive_db` and
|
|
47
|
-
`restore_gdrive_folder` - use `backup_db_to_storage`, `restore_db_from_storage` and
|
|
48
|
-
`restore_folder`
|
|
49
|
-
- Client-side encryption: the file format constants changed with the rename, so files
|
|
50
|
-
encrypted by pre-release versions of the encryption feature cannot be read. No published
|
|
51
|
-
release included encryption, so this affects no production backups.
|
|
52
|
-
|
|
53
|
-
Backups already in your storage destination are unaffected - folder layout and metadata
|
|
54
|
-
are unchanged, and existing backups restore as before.
|
|
55
|
-
|
|
56
|
-
**encrypted-credentials**
|
|
117
|
+
## encrypted-credentials
|
|
57
118
|
|
|
58
119
|
This package uses encrypted-credentials and the instructions there could be useful. Adding the following lines to **settings.py** will initialise the package
|
|
59
120
|
|
|
@@ -62,13 +123,13 @@ This package uses encrypted-credentials and the instructions there could be usef
|
|
|
62
123
|
add_encrypted_settings(globals())
|
|
63
124
|
|
|
64
125
|
|
|
65
|
-
|
|
126
|
+
## Create service account
|
|
66
127
|
|
|
67
128
|
Requires a Google service account with the Google Drive API enabled
|
|
68
129
|
|
|
69
130
|
https://console.cloud.google.com/apis/credentials/serviceaccountkey
|
|
70
131
|
|
|
71
|
-
|
|
132
|
+
## Add to cloud_backup installed apps
|
|
72
133
|
|
|
73
134
|
settings.py
|
|
74
135
|
|
|
@@ -76,7 +137,7 @@ settings.py
|
|
|
76
137
|
'cloud_backup',
|
|
77
138
|
]
|
|
78
139
|
|
|
79
|
-
|
|
140
|
+
## Store service account key
|
|
80
141
|
|
|
81
142
|
By default *encrypted-credentials* is used to store the key. Create a directory off the django projects BASE_DIR called credentials and save the json key.
|
|
82
143
|
|
|
@@ -88,24 +149,24 @@ settings.py
|
|
|
88
149
|
}
|
|
89
150
|
|
|
90
151
|
|
|
91
|
-
|
|
152
|
+
## Create Google Drive folder and share with service account
|
|
92
153
|
|
|
93
154
|
With a Google Drive account create a folder and share with the email address of the service account.
|
|
94
155
|
|
|
95
156
|
|
|
96
|
-
|
|
157
|
+
## Ensure psql is available to python subprocess
|
|
97
158
|
|
|
98
159
|
For docker containers you may need to something similar to the following line in the Dockerfile dependent on the version of Postgres.
|
|
99
160
|
|
|
100
161
|
RUN apt-get -y install postgresql-client-11
|
|
101
162
|
|
|
102
|
-
|
|
163
|
+
## Configure database backup
|
|
103
164
|
|
|
104
165
|
settings.py
|
|
105
166
|
|
|
106
167
|
BACKUP_ROOT = 'django_backup'
|
|
107
168
|
|
|
108
|
-
|
|
169
|
+
## Choosing a backup destination
|
|
109
170
|
|
|
110
171
|
Google Drive is the default destination and needs no extra settings beyond those above.
|
|
111
172
|
Backups can instead be stored on any S3-compatible service or Azure Blob Storage by adding
|
|
@@ -161,7 +222,7 @@ backup page queries the destination and shows whether versioning, soft delete an
|
|
|
161
222
|
Object Lock/immutability (WORM) are actually enabled, so a missing safety net is
|
|
162
223
|
visible at a glance.
|
|
163
224
|
|
|
164
|
-
|
|
225
|
+
## Ransomware protection
|
|
165
226
|
|
|
166
227
|
If backups re-sync whenever a source file changes, an attacker encrypting your files
|
|
167
228
|
would overwrite the good backups on the next scheduled run. Protection is layered:
|
|
@@ -231,7 +292,7 @@ With delete-less credentials, pruning logs a warning instead of failing the back
|
|
|
231
292
|
leave `BACKUP_DB_RETENTION` unset and let bucket lifecycle rules do the pruning - the
|
|
232
293
|
tiered layout below is the supported way to do that.
|
|
233
294
|
|
|
234
|
-
|
|
295
|
+
## Lifecycle-managed database backups (S3/B2/R2)
|
|
235
296
|
|
|
236
297
|
`BACKUP_DB_RETENTION` prunes from the application: it lists the dumps and deletes the
|
|
237
298
|
ones it does not want to keep. `BACKUP_DB_TIERS` is the alternative - the application
|
|
@@ -245,8 +306,16 @@ scheduled job promotes one dump per day into `daily/` and one per month into
|
|
|
245
306
|
`monthly/` using server-side copies (no download, no re-upload, no egress):
|
|
246
307
|
|
|
247
308
|
<root>/db/hourly/2026/07/30/db_2026_07_30_14_05_37.dump expire after ~15 days
|
|
248
|
-
<root>/db/daily/db_2026-07-30.dump
|
|
249
|
-
<root>/db/monthly/db_2026-07.dump
|
|
309
|
+
<root>/db/daily/20_117_165_6/db_2026-07-30.dump expire after ~91 days
|
|
310
|
+
<root>/db/monthly/20_117_165_6/db_2026-07.dump no rule - kept forever
|
|
311
|
+
|
|
312
|
+
The sub-folder is the server the dump came from (the `ip_address` metadata every dump
|
|
313
|
+
carries), and each server is promoted on its own: its last dump of the day becomes its
|
|
314
|
+
daily copy, its last daily copy of the month its monthly one. Several installations can
|
|
315
|
+
share one db folder - a staging server that restores from production's dumps, or a
|
|
316
|
+
developer's machine - and each keeps its own archive rather than whichever of them
|
|
317
|
+
dumped last overwriting the day's single copy. That is the same guarantee the
|
|
318
|
+
`BACKUP_DB_RETENTION` layout gives by pruning per server.
|
|
250
319
|
|
|
251
320
|
The retention you get is the lifecycle rules you create; this package never writes
|
|
252
321
|
them, so the backup credential needs neither `DeleteObject` nor
|
|
@@ -294,8 +363,9 @@ Notes:
|
|
|
294
363
|
|
|
295
364
|
- Tiers are created inside each database folder, so a schema backed up separately gets
|
|
296
365
|
`<root>/db/<schema>/hourly/...` and needs its own pair of lifecycle rules.
|
|
297
|
-
-
|
|
298
|
-
|
|
366
|
+
- Copies at the root of `daily/` and `monthly/` are from before promotion was per
|
|
367
|
+
server. They are left as they are, expire under the same rules, and count as that
|
|
368
|
+
day's (or month's) copy, so upgrading creates no duplicates.
|
|
299
369
|
- Not compatible with Object Lock (`lock` in `BACKUP_STORAGE`): a retention lock stops
|
|
300
370
|
lifecycle expiry, so locked hourly dumps would accumulate forever. Pick one.
|
|
301
371
|
- Dumps written before tiering was turned on stay listed and restorable where they
|
|
@@ -316,7 +386,29 @@ application never applies these numbers - the destination's own rules are what a
|
|
|
316
386
|
delete, and the page reads them back: a rule that expires a tier *sooner* than the config
|
|
317
387
|
asks for is a red row, and one that keeps it *longer* an amber one.
|
|
318
388
|
|
|
319
|
-
|
|
389
|
+
Expiry on a versioned bucket only *hides* a dump; the rule's second clause purges the
|
|
390
|
+
hidden version `purge_days` later (default 1). That clause applies to every hidden
|
|
391
|
+
version however it got hidden - including dumps an attacker holding the backup
|
|
392
|
+
credential has deleted or overwritten - so it is also the window in which such an attack
|
|
393
|
+
can still be undone. Trading a few days of hourly retention for a longer window costs
|
|
394
|
+
about the same storage and buys a week to notice:
|
|
395
|
+
|
|
396
|
+
BACKUP_DB_TIERS = {'expire_days': {'hourly': 7}, 'purge_days': 7} # 7 visible + 7 hidden
|
|
397
|
+
|
|
398
|
+
The setup page generates the rules with that clause and flags a real rule that purges
|
|
399
|
+
sooner.
|
|
400
|
+
|
|
401
|
+
A deleted dump is loud - the status check sees it missing. An *overwritten* one is not:
|
|
402
|
+
the name, date and size still look right, and the real version sits hidden underneath
|
|
403
|
+
until the purge. So for tiered configs the status check also audits the bucket's
|
|
404
|
+
versions: dumps get unique names and are only ever hidden by expiry once they are
|
|
405
|
+
`expire_days` old, so a dump hidden younger than that, anything hidden under `monthly/`,
|
|
406
|
+
or a key holding two real versions is someone else's doing. The `Version audit` row
|
|
407
|
+
names them, says whether they are `hidden` (still recoverable), `overwritten` or already
|
|
408
|
+
`purged`, and gives the deadline the purge clock sets - run `backup_status` more often
|
|
409
|
+
than `purge_days`.
|
|
410
|
+
|
|
411
|
+
### Explicit deletes with a locked archive
|
|
320
412
|
|
|
321
413
|
Lifecycle rules are only as durable as the bucket configuration - anyone with
|
|
322
414
|
`writeBuckets` can shorten them, and they delete silently. `delete: 'app'` moves the
|
|
@@ -351,7 +443,7 @@ retention date rather than trusting the settings.
|
|
|
351
443
|
The trade-off is explicit: the backup credential can now delete, which is what an attacker
|
|
352
444
|
would use it for. What survives that is exactly the tiers in `lock_days`.
|
|
353
445
|
|
|
354
|
-
|
|
446
|
+
### Setting up the bucket
|
|
355
447
|
|
|
356
448
|
Since the package never creates a bucket or writes a lifecycle rule, the *Storage Setup*
|
|
357
449
|
tab on the backup page (`/backup/setup/`) works out what is missing and shows the
|
|
@@ -380,7 +472,7 @@ Points the page makes, and the reasons behind them:
|
|
|
380
472
|
|---|---|---|
|
|
381
473
|
| `listBuckets` | find the bucket; read its versioning, object-lock and lifecycle configuration (the checks on this page) | always |
|
|
382
474
|
| `listFiles` | list backups for the UI, dedup and pruning | always |
|
|
383
|
-
| `readFiles` | download for restore, and read metadata (md5, schema, ip) | always |
|
|
475
|
+
| `readFiles` | download for restore, and read metadata (md5, schema, ip, extensions) | always |
|
|
384
476
|
| `writeFiles` | upload backups, and server-side copies (tier promotion, `changed_files='history'`) | always |
|
|
385
477
|
| `readBuckets` | `Get Bucket Versioning` | always - read-only, for this page |
|
|
386
478
|
| `readBucketRetentions` | `Get Object Lock Configuration` | always - read-only, for this page |
|
|
@@ -435,7 +527,7 @@ the browser's clipboard API, which only works over https or on localhost.
|
|
|
435
527
|
`python manage.py storage_setup [--config <name>]` prints the same thing on a server
|
|
436
528
|
with no web UI.
|
|
437
529
|
|
|
438
|
-
|
|
530
|
+
## Client-side encryption
|
|
439
531
|
|
|
440
532
|
By default backups are stored as the provider receives them - anyone with access to
|
|
441
533
|
the Drive folder or bucket can read a full database dump. Setting `BACKUP_ENCRYPTION`
|
|
@@ -475,7 +567,7 @@ Notes:
|
|
|
475
567
|
- With multiple backup configurations (below), encryption is set per config rather
|
|
476
568
|
than globally.
|
|
477
569
|
|
|
478
|
-
|
|
570
|
+
## Multiple backup configurations
|
|
479
571
|
|
|
480
572
|
`BACKUP_CONFIGS` lets one project back up to several destinations with different
|
|
481
573
|
behaviour per destination - the classic case being a hardened offsite backup plus an
|
|
@@ -546,7 +638,7 @@ Backups made by one config restore with that config's key: restoring an encrypte
|
|
|
546
638
|
backup through a config with a different key (or none) fails cleanly.
|
|
547
639
|
|
|
548
640
|
|
|
549
|
-
|
|
641
|
+
### Live, staging and local machines
|
|
550
642
|
|
|
551
643
|
The usual three-role setup: one server produces the backups, and the others restore them
|
|
552
644
|
to get a copy of live data to work with.
|
|
@@ -614,13 +706,13 @@ If a machine only ever restores and backs nothing up at all, `BACKUP_RESTORE_ONL
|
|
|
614
706
|
sets the flag globally without needing `BACKUP_CONFIGS`.
|
|
615
707
|
|
|
616
708
|
|
|
617
|
-
|
|
709
|
+
## Management commands
|
|
618
710
|
|
|
619
711
|
python manage.py backup_website
|
|
620
712
|
python manage.py restore_db
|
|
621
713
|
python manage.py storage_setup
|
|
622
714
|
|
|
623
|
-
|
|
715
|
+
## Management page
|
|
624
716
|
|
|
625
717
|
urls.py
|
|
626
718
|
|
|
@@ -642,7 +734,7 @@ from the following PyPi packages
|
|
|
642
734
|
|
|
643
735
|
django-nested-modals, django-filtered-datatables, django-tab-menus, django-ajax-helpers
|
|
644
736
|
|
|
645
|
-
|
|
737
|
+
### Branding the management page
|
|
646
738
|
|
|
647
739
|
The enhanced page views build the whole UI (menus, storage info and tables) into a
|
|
648
740
|
single HTML string, `{{ backup_content }}`, so it can be dropped into your own
|
|
@@ -688,7 +780,7 @@ Register the subclasses with `backup_urlpatterns` so the menu links and modals
|
|
|
688
780
|
The unbranded standard page remains the default when using
|
|
689
781
|
`include('cloud_backup.urls')`.
|
|
690
782
|
|
|
691
|
-
|
|
783
|
+
### Restoring from the management page
|
|
692
784
|
|
|
693
785
|
Restore and drop-schema actions on the enhanced management page require
|
|
694
786
|
|
|
@@ -702,7 +794,7 @@ development machines where restoring is wanted. The `manage.py restore_db`
|
|
|
702
794
|
command is not affected by this setting, so disaster recovery on a live server
|
|
703
795
|
remains possible from the command line.
|
|
704
796
|
|
|
705
|
-
|
|
797
|
+
## Browsing and verifying folder backups
|
|
706
798
|
|
|
707
799
|
When `BACKUP_DIRS`, `AZURE_BACKUP_DIRS` (or `S3_BACKUP_DIRS`) is configured, the
|
|
708
800
|
enhanced management page shows a `Backup Files` button that backs up all configured
|
|
@@ -742,7 +834,7 @@ other backup button, require a superuser. Note that on an S3-compatible
|
|
|
742
834
|
destination with client-side encryption enabled, listing the checksums costs one
|
|
743
835
|
metadata request per file, so the page can be slow to load for very large trees.
|
|
744
836
|
|
|
745
|
-
|
|
837
|
+
## Configure Azure folder backups
|
|
746
838
|
|
|
747
839
|
Media that django-storages keeps in Azure Blob Storage has no local directory for
|
|
748
840
|
`BACKUP_DIRS` to back up. `AZURE_BACKUP_DIRS` names prefixes ("folders") in the
|
|
@@ -772,10 +864,15 @@ Both are available per config as `azure_dirs` / `azure_source`. Nothing is downl
|
|
|
772
864
|
to decide what needs backing up: a blob is skipped when its md5 (which Azure records
|
|
773
865
|
for single-request uploads - django-storages' normal case) or otherwise its etag
|
|
774
866
|
matches what was stored with the backup, so an unchanged blob costs one listing entry
|
|
775
|
-
and a changed one is re-uploaded. The
|
|
867
|
+
and a changed one is re-uploaded. The destination is listed once, recursively, rather
|
|
868
|
+
than folder by folder, and its stored metadata - a request per object on S3-compatible
|
|
869
|
+
storage - is only read for the files the listing cannot settle by hash (blobs Azure holds
|
|
870
|
+
no md5 for, encrypted copies, and anything that has actually changed), so a nightly run
|
|
871
|
+
over a large, mostly unchanged container is a couple of listings and a few requests, not
|
|
872
|
+
one per file. The `backup_azure_s3.BackupAzureToS3` class is
|
|
776
873
|
different: a standalone rclone-compatible mirror that bypasses this pipeline.
|
|
777
874
|
|
|
778
|
-
|
|
875
|
+
## Configure S3 folder backups
|
|
779
876
|
|
|
780
877
|
settings.py
|
|
781
878
|
|
|
@@ -787,7 +884,7 @@ settings.py
|
|
|
787
884
|
('S3-source-folder2', 'google-drive-folder2')
|
|
788
885
|
]
|
|
789
886
|
|
|
790
|
-
|
|
887
|
+
## Configure cleaning of old datatabase backups
|
|
791
888
|
|
|
792
889
|
settings.py
|
|
793
890
|
|
|
@@ -803,7 +900,7 @@ not kept by some entry is deleted after each backup. On an S3-compatible destina
|
|
|
803
900
|
deleting instead, and the application never needs delete permission.
|
|
804
901
|
|
|
805
902
|
|
|
806
|
-
|
|
903
|
+
## Schedule backup with celery beat
|
|
807
904
|
|
|
808
905
|
CELERY_BEAT_SCHEDULE = {
|
|
809
906
|
'backup': {
|
|
@@ -812,3 +909,68 @@ deleting instead, and the application never needs delete permission.
|
|
|
812
909
|
}
|
|
813
910
|
}
|
|
814
911
|
|
|
912
|
+
|
|
913
|
+
## Checking that the backups are current
|
|
914
|
+
|
|
915
|
+
Error tracking only tells you about a backup that ran and *failed*. A celery beat that has
|
|
916
|
+
stopped, or a worker that never picks the task up, raises nothing anywhere - so the package
|
|
917
|
+
answers the positive question itself. Every run of `backup`, `promote_db_tiers` and
|
|
918
|
+
`extend_retention` is recorded in the database (`BackupRun`; rows are pruned after
|
|
919
|
+
`BACKUP_RUN_HISTORY_DAYS`, default 90), and the status check lists what is actually at each
|
|
920
|
+
destination and grades it against your beat schedule:
|
|
921
|
+
|
|
922
|
+
python manage.py backup_status # every config; exit code 1 if anything is not OK
|
|
923
|
+
python manage.py backup_status --json
|
|
924
|
+
|
|
925
|
+
OK database: Latest database dump Sat 29 Aug 09:50 (27 min ago), 285.8 MiB [older than the 09:50 run]
|
|
926
|
+
OK database: Dump size vs previous 285.8 MiB vs 285.8 MiB (100%) [< 80% of previous]
|
|
927
|
+
OK database: Latest daily copy Fri 28 Aug, 285.8 MiB [before Fri 28 Aug]
|
|
928
|
+
OK database: Latest monthly copy Jul 2026, 280.1 MiB [before Jul 2026]
|
|
929
|
+
OK database: Version audit nothing unexplained - 9 hidden by expiry, 214 entries listed [any hidden version or overwrite the retention policy does not explain]
|
|
930
|
+
OK database: Backup run succeeded Sat 29 Aug 09:51 (26 min ago) [older than the 09:50 run]
|
|
931
|
+
OK database: Tier promotion run succeeded Sat 29 Aug 06:00 (4 h 17 min ago) [older than the 06:00 run]
|
|
932
|
+
OK files: Destination reachable unity-backup is accessible [not accessible]
|
|
933
|
+
OK files: Backup run succeeded Sat 29 Aug 01:31 (8 h 46 min ago) [older than the 01:30 run]
|
|
934
|
+
|
|
935
|
+
The same rows are served as json at `backup/status/` (`?config=<name>` to limit it,
|
|
936
|
+
`?refresh=1` to bypass the five-minute cache) for a monitoring agent to read. The view
|
|
937
|
+
only admits a superuser or the backup permission; subclass `cloud_backup.views
|
|
938
|
+
.BackupStatusView`, override `has_permission(request)` to accept your monitor's credential,
|
|
939
|
+
and pass it as `backup_urlpatterns(status_view=...)`.
|
|
940
|
+
|
|
941
|
+
Rows are graded against the `crontab` entries in `CELERY_BEAT_SCHEDULE` for the config
|
|
942
|
+
(a run is late once `grace_minutes` past its slot, counting only the days the crontab
|
|
943
|
+
fires - a `mon-fri` schedule is not stale over the weekend), or by plain age
|
|
944
|
+
(`max_age_hours`) on a server where the task is not scheduled.
|
|
945
|
+
|
|
946
|
+
The run history behind those rows is browsable too: the enhanced UI has a Run Log page
|
|
947
|
+
at `backup/runs/` (a button on each destination's page), and `BackupRun` is registered
|
|
948
|
+
read-only in the Django admin for projects on the basic UI. A dump smaller than `size_drop` of the one before it
|
|
949
|
+
is flagged, and with `BACKUP_DB_TIERS` the daily and monthly copies must be there by
|
|
950
|
+
`promotion_deadline`. The defaults are in `cloud_backup.config.DEFAULT_STATUS`; override
|
|
951
|
+
them for every config with `BACKUP_STATUS = {...}` or per config with a `'status': {...}` key.
|
|
952
|
+
|
|
953
|
+
## Migrating from django-gdrive-backup
|
|
954
|
+
|
|
955
|
+
This package was previously published as `django-gdrive-backup`. The rename is a breaking
|
|
956
|
+
release; upgrading requires the following changes in your project:
|
|
957
|
+
|
|
958
|
+
- Install `django-cloud-backup` (and its extras, e.g. `django-cloud-backup[s3]`) instead of
|
|
959
|
+
`django-gdrive-backup`
|
|
960
|
+
- `INSTALLED_APPS`: `'gdrive_backup'` → `'cloud_backup'`
|
|
961
|
+
- urls.py: `include('gdrive_backup.urls')` → `include('cloud_backup.urls')`, and any
|
|
962
|
+
reverses/`{% url %}` tags use the `cloud_backup:` namespace instead of `gdrive_backup:`
|
|
963
|
+
- Celery beat schedules: task names are now `cloud_backup.tasks.*`
|
|
964
|
+
(e.g. `cloud_backup.tasks.backup`)
|
|
965
|
+
- Settings renamed: `BACKUP_GDRIVE_DIR` → `BACKUP_ROOT`, `BACKUP_GDRIVE_DB` → `BACKUP_DB_DIR`
|
|
966
|
+
(they apply to every destination backend, not just Google Drive). `BACKUP_TEAM_DRIVE` is
|
|
967
|
+
unchanged.
|
|
968
|
+
- Removed legacy method aliases `backup_db_gdrive`, `restore_gdrive_db` and
|
|
969
|
+
`restore_gdrive_folder` - use `backup_db_to_storage`, `restore_db_from_storage` and
|
|
970
|
+
`restore_folder`
|
|
971
|
+
- Client-side encryption: the file format constants changed with the rename, so files
|
|
972
|
+
encrypted by pre-release versions of the encryption feature cannot be read. No published
|
|
973
|
+
release included encryption, so this affects no production backups.
|
|
974
|
+
|
|
975
|
+
Backups already in your storage destination are unaffected - folder layout and metadata
|
|
976
|
+
are unchanged, and existing backups restore as before.
|