django-cloud-backup 0.1.0__tar.gz → 0.1.1__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.
Files changed (55) hide show
  1. django_cloud_backup-0.1.1/PKG-INFO +814 -0
  2. django_cloud_backup-0.1.1/README.md +791 -0
  3. django_cloud_backup-0.1.1/cloud_backup/backup.py +213 -0
  4. django_cloud_backup-0.1.1/cloud_backup/backup_azure.py +214 -0
  5. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/backup_db.py +71 -10
  6. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/backup_local_files.py +53 -0
  7. django_cloud_backup-0.1.1/cloud_backup/config.py +274 -0
  8. django_cloud_backup-0.1.1/cloud_backup/db_tiers.py +294 -0
  9. django_cloud_backup-0.1.1/cloud_backup/enhanced_views.py +823 -0
  10. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/management/commands/backup_website.py +39 -3
  11. django_cloud_backup-0.1.1/cloud_backup/management/commands/storage_setup.py +48 -0
  12. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/modals.py +43 -29
  13. django_cloud_backup-0.1.1/cloud_backup/storage_setup.py +550 -0
  14. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/storages/__init__.py +16 -0
  15. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/storages/azure.py +26 -2
  16. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/storages/base.py +54 -4
  17. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/storages/gdrive.py +20 -2
  18. django_cloud_backup-0.1.1/cloud_backup/storages/s3.py +491 -0
  19. django_cloud_backup-0.1.1/cloud_backup/tasks.py +121 -0
  20. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/templates/cloud_backup/backup_content.html +3 -1
  21. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/templates/cloud_backup/info.html +4 -2
  22. django_cloud_backup-0.1.1/cloud_backup/templates/cloud_backup/storage_setup_content.html +13 -0
  23. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/urls.py +17 -6
  24. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/utils.py +2 -0
  25. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/views.py +8 -3
  26. django_cloud_backup-0.1.1/django_cloud_backup.egg-info/PKG-INFO +814 -0
  27. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/django_cloud_backup.egg-info/SOURCES.txt +5 -0
  28. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/django_cloud_backup.egg-info/requires.txt +1 -1
  29. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/pyproject.toml +2 -2
  30. django_cloud_backup-0.1.0/PKG-INFO +0 -439
  31. django_cloud_backup-0.1.0/README.md +0 -416
  32. django_cloud_backup-0.1.0/cloud_backup/backup.py +0 -109
  33. django_cloud_backup-0.1.0/cloud_backup/config.py +0 -87
  34. django_cloud_backup-0.1.0/cloud_backup/enhanced_views.py +0 -273
  35. django_cloud_backup-0.1.0/cloud_backup/storages/s3.py +0 -256
  36. django_cloud_backup-0.1.0/cloud_backup/tasks.py +0 -82
  37. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/PKG-INFO +0 -439
  38. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/LICENSE +0 -0
  39. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/MANIFEST.in +0 -0
  40. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/__init__.py +0 -0
  41. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/apps.py +0 -0
  42. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/backup_azure_s3.py +0 -0
  43. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/backup_s3.py +0 -0
  44. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/base_backup.py +0 -0
  45. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/compression.py +0 -0
  46. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/encryption.py +0 -0
  47. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/management/__init__.py +0 -0
  48. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/management/commands/__init__.py +0 -0
  49. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/management/commands/restore_db.py +0 -0
  50. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/prune_backups.py +0 -0
  51. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/sql_functions.py +0 -0
  52. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/cloud_backup/templates/cloud_backup/backup.html +0 -0
  53. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/django_cloud_backup.egg-info/dependency_links.txt +0 -0
  54. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/django_cloud_backup.egg-info/top_level.txt +0 -0
  55. {django_cloud_backup-0.1.0 → django_cloud_backup-0.1.1}/setup.cfg +0 -0
@@ -0,0 +1,814 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-cloud-backup
3
+ Version: 0.1.1
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
+ Author: Ian Jones
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jonesim/django-cloud-backup
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: encrypted-credentials
14
+ Requires-Dist: google-client-helper>=0.0.4
15
+ Requires-Dist: requests
16
+ Provides-Extra: s3
17
+ Requires-Dist: boto3; extra == "s3"
18
+ Provides-Extra: azure
19
+ Requires-Dist: azure-storage-blob; extra == "azure"
20
+ Provides-Extra: encryption
21
+ Requires-Dist: cryptography; extra == "encryption"
22
+ Dynamic: license-file
23
+
24
+ [![PyPI version](https://badge.fury.io/py/django-cloud-backup.svg)](https://badge.fury.io/py/django-cloud-backup)
25
+
26
+
27
+ **django-cloud-backup**
28
+
29
+ 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.
30
+
31
+ **Migrating from django-gdrive-backup**
32
+
33
+ This package was previously published as `django-gdrive-backup`. The rename is a breaking
34
+ release; upgrading requires the following changes in your project:
35
+
36
+ - Install `django-cloud-backup` (and its extras, e.g. `django-cloud-backup[s3]`) instead of
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**
57
+
58
+ This package uses encrypted-credentials and the instructions there could be useful. Adding the following lines to **settings.py** will initialise the package
59
+
60
+ from encrypted_credentials.django_credentials import add_encrypted_settings
61
+
62
+ add_encrypted_settings(globals())
63
+
64
+
65
+ **Create service account**
66
+
67
+ Requires a Google service account with the Google Drive API enabled
68
+
69
+ https://console.cloud.google.com/apis/credentials/serviceaccountkey
70
+
71
+ **Add to cloud_backup installed apps**
72
+
73
+ settings.py
74
+
75
+ INSTALLED_APPS = [ ..
76
+ 'cloud_backup',
77
+ ]
78
+
79
+ **Store service account key**
80
+
81
+ 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
+
83
+ settings.py
84
+
85
+ CREDENTIAL_FOLDER = os.path.join(BASE_DIR, 'credentials')
86
+ CREDENTIAL_FILES = {
87
+ 'drive': 'service-account.json',
88
+ }
89
+
90
+
91
+ **Create Google Drive folder and share with service account**
92
+
93
+ With a Google Drive account create a folder and share with the email address of the service account.
94
+
95
+
96
+ **Ensure psql is available to python subprocess**
97
+
98
+ For docker containers you may need to something similar to the following line in the Dockerfile dependent on the version of Postgres.
99
+
100
+ RUN apt-get -y install postgresql-client-11
101
+
102
+ **Configure database backup**
103
+
104
+ settings.py
105
+
106
+ BACKUP_ROOT = 'django_backup'
107
+
108
+ **Choosing a backup destination**
109
+
110
+ Google Drive is the default destination and needs no extra settings beyond those above.
111
+ Backups can instead be stored on any S3-compatible service or Azure Blob Storage by adding
112
+ a `BACKUP_STORAGE` dict to settings.py. The optional `root` key replaces `BACKUP_ROOT`
113
+ as the top-level folder/prefix.
114
+
115
+ AWS S3:
116
+
117
+ BACKUP_STORAGE = {
118
+ 'backend': 's3',
119
+ 'bucket': 'my-backups',
120
+ 'access_key_id': '...',
121
+ 'secret_key': '...',
122
+ 'root': 'django_backup',
123
+ }
124
+
125
+ Backblaze B2 (the S3 endpoint is discovered from the key automatically):
126
+
127
+ BACKUP_STORAGE = {
128
+ 'backend': 's3',
129
+ 'b2': True,
130
+ 'bucket': 'my-backups',
131
+ 'access_key_id': '...', # B2 keyID
132
+ 'secret_key': '...', # B2 applicationKey
133
+ }
134
+
135
+ Cloudflare R2:
136
+
137
+ BACKUP_STORAGE = {
138
+ 'backend': 's3',
139
+ 'bucket': 'my-backups',
140
+ 'endpoint_url': 'https://<account-id>.r2.cloudflarestorage.com',
141
+ 'region': 'auto',
142
+ 'access_key_id': '...',
143
+ 'secret_key': '...',
144
+ }
145
+
146
+ Azure Blob Storage:
147
+
148
+ BACKUP_STORAGE = {
149
+ 'backend': 'azure',
150
+ 'container': 'backups',
151
+ 'connection_string': '...', # or account_url + credential
152
+ }
153
+
154
+ S3 backends require `pip install django-cloud-backup[s3]` and Azure
155
+ `pip install django-cloud-backup[azure]`.
156
+
157
+ Note that unlike Google Drive, S3 and Azure destinations have no trash - pruned
158
+ database backups are deleted permanently, so consider enabling bucket versioning
159
+ (S3/B2/R2 lifecycle rules) or soft delete (Azure) if you want a safety net. The
160
+ backup page queries the destination and shows whether versioning, soft delete and
161
+ Object Lock/immutability (WORM) are actually enabled, so a missing safety net is
162
+ visible at a glance.
163
+
164
+ **Ransomware protection**
165
+
166
+ If backups re-sync whenever a source file changes, an attacker encrypting your files
167
+ would overwrite the good backups on the next scheduled run. Protection is layered:
168
+
169
+ *Changed-file handling* - settings.py:
170
+
171
+ BACKUP_CHANGED_FILES = 'overwrite' # default: re-upload changed files
172
+ BACKUP_CHANGED_FILES = 'protect' # never touch the existing backup: skip the
173
+ # file, log a warning and fail the backup run
174
+ # (raises ChangedFilesError after everything
175
+ # else has completed, so monitoring alerts)
176
+ BACKUP_CHANGED_FILES = 'history' # keep the previous version (S3 server-side
177
+ # copy named <file>.<timestamp>, Azure
178
+ # snapshot, Google Drive rename), then upload
179
+ # the new version; warns but succeeds
180
+
181
+ Use `'protect'` when your file store is immutable (e.g. UUID-named uploads that are
182
+ never edited) - any change is corruption or an attacker. Use `'history'` when changes
183
+ can be legitimate but you still want every previous version recoverable.
184
+
185
+ *Object Lock retention (S3 and B2)* - create the bucket with Object Lock enabled and
186
+ add a `lock` section to `BACKUP_STORAGE`:
187
+
188
+ BACKUP_STORAGE = {
189
+ 'backend': 's3', ...,
190
+ 'lock': {
191
+ 'mode': 'COMPLIANCE', # not even the bucket owner can shorten or delete
192
+ 'db_days': 35, # each database dump is locked for 35 days at upload
193
+ 'file_days': 7, # each file backup is locked for 7 days at upload
194
+ 'min_days': 7, # extend_retention keeps every file locked >= 7 days ahead
195
+ },
196
+ }
197
+
198
+ Locking at upload costs nothing (extra headers on the existing request). To keep
199
+ long-lived file backups permanently locked, schedule the top-up task daily - it
200
+ extends any object whose remaining lock is below `min_days`:
201
+
202
+ CELERY_BEAT_SCHEDULE = {
203
+ 'extend_retention': {
204
+ 'task': 'cloud_backup.tasks.extend_retention',
205
+ 'schedule': crontab(hour=3, minute=0),
206
+ },
207
+ }
208
+
209
+ or run `python manage.py backup_website --extend_retention`. The top-up costs 1-2 API
210
+ calls per file (roughly a minute per 10,000 files), which is why it is a scheduled
211
+ task rather than part of every backup. Backups only become deletable `min_days` after
212
+ the top-up task stops running.
213
+
214
+ Pruning still works on a locked bucket: Object Lock buckets are versioned, so deleting
215
+ an old dump just writes a delete marker (allowed even while versions are locked) and
216
+ the locked versions physically remain. Add a bucket lifecycle rule such as "expire
217
+ noncurrent versions after 40 days" to clean them up once their lock has passed. The
218
+ same versioning means even `'overwrite'` mode cannot physically destroy data on a
219
+ locked bucket - the prior locked version survives underneath.
220
+
221
+ *Credential and bucket hardening* (outside this package):
222
+
223
+ - **AWS S3**: give the backup IAM user no `s3:DeleteObject`/`s3:PutBucketLifecycle`;
224
+ prune via lifecycle rules instead of `BACKUP_DB_RETENTION`
225
+ - **Backblaze B2**: use an application key without the `deleteFiles` capability
226
+ - **Azure**: enable blob soft delete or a container immutability policy
227
+ - **Google Drive**: deletes go to trash and are recoverable, but the service account
228
+ can empty the trash - treat the credential file accordingly
229
+
230
+ With delete-less credentials, pruning logs a warning instead of failing the backup;
231
+ leave `BACKUP_DB_RETENTION` unset and let bucket lifecycle rules do the pruning - the
232
+ tiered layout below is the supported way to do that.
233
+
234
+ **Lifecycle-managed database backups (S3/B2/R2)**
235
+
236
+ `BACKUP_DB_RETENTION` prunes from the application: it lists the dumps and deletes the
237
+ ones it does not want to keep. `BACKUP_DB_TIERS` is the alternative - the application
238
+ only ever writes, and the bucket's own lifecycle rules do all the deleting:
239
+
240
+ BACKUP_DB_TIERS = True # requires the 's3' backend
241
+ BACKUP_DB_RETENTION = [] # tiering replaces client-side pruning
242
+
243
+ Every dump then goes to a unique, date-partitioned key under `hourly/`, and a
244
+ scheduled job promotes one dump per day into `daily/` and one per month into
245
+ `monthly/` using server-side copies (no download, no re-upload, no egress):
246
+
247
+ <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 expire after ~91 days
249
+ <root>/db/monthly/db_2026-07.dump no rule - kept forever
250
+
251
+ The retention you get is the lifecycle rules you create; this package never writes
252
+ them, so the backup credential needs neither `DeleteObject` nor
253
+ `PutBucketLifecycleConfiguration`. On AWS, two rules with `Expiration.Days` of 15 and
254
+ 91 filtered on the `hourly/` and `daily/` prefixes. On B2, rules are
255
+ `fileNamePrefix` + `daysFromUploadingToHiding` + `daysFromHidingToDeleting`, and B2
256
+ buckets always keep versions, so **both** numbers are needed or "expired" files are
257
+ merely hidden and go on being billed:
258
+
259
+ {"fileNamePrefix": "django_backup/db/hourly/", "daysFromUploadingToHiding": 15,
260
+ "daysFromHidingToDeleting": 1}
261
+ {"fileNamePrefix": "django_backup/db/daily/", "daysFromUploadingToHiding": 91,
262
+ "daysFromHidingToDeleting": 1}
263
+
264
+ B2 rejects overlapping rules, so an existing bucket-wide rule (empty prefix) has to go
265
+ before these can be added. The backup page reads the bucket's lifecycle configuration
266
+ and shows a row per tier, in red when `hourly/` has no rule (dumps accumulate forever)
267
+ or when a catch-all rule would expire the `monthly/` archive.
268
+
269
+ **Promotion runs at the end of every database backup**, so there is no second job that
270
+ has to be working for the backups to survive - the hourly tier expires by itself, and a
271
+ promotion step that quietly stopped would lose everything while the backups carried on
272
+ looking healthy. In that in-backup pass it only looks at days after the newest one
273
+ already promoted, which is normally two listings and no copies at all; after an outage it
274
+ catches every missed day up on the next backup.
275
+
276
+ It is still worth scheduling as well, so promotion happens on a day when no backup runs:
277
+
278
+ CELERY_BEAT_SCHEDULE = {
279
+ 'promote_db_tiers': {
280
+ 'task': 'cloud_backup.tasks.promote_db_tiers',
281
+ 'schedule': crontab(hour=1, minute=30),
282
+ },
283
+ }
284
+
285
+ or `python manage.py backup_website --promote_tiers`. That form does a full 14-day scan,
286
+ warns about days that had no dumps at all, and takes `--as_of YYYY-MM-DD` and `--days N`
287
+ to backfill further. It needs no database connection and re-running it is a no-op.
288
+
289
+ The setup page shows a **Tier promotion** row with the newest daily dump, red when
290
+ nothing has reached the daily tier for more than two days - the one failure that would
291
+ otherwise be invisible until the hourly rule caught up with it.
292
+
293
+ Notes:
294
+
295
+ - Tiers are created inside each database folder, so a schema backed up separately gets
296
+ `<root>/db/<schema>/hourly/...` and needs its own pair of lifecycle rules.
297
+ - One server per prefix: nothing in the key identifies the server, so a second server
298
+ backing up to the same place needs its own config or `db_dir`.
299
+ - Not compatible with Object Lock (`lock` in `BACKUP_STORAGE`): a retention lock stops
300
+ lifecycle expiry, so locked hourly dumps would accumulate forever. Pick one.
301
+ - Dumps written before tiering was turned on stay listed and restorable where they
302
+ are; nothing is migrated or deleted.
303
+ - The web UI lists every tier, which means a metadata request per dump. Set
304
+ `BACKUP_DB_TIERS = {'hourly_days': 3}` to list only the last few days of the hourly
305
+ tier - it is a display window, not a retention setting.
306
+
307
+ **How long each tier is kept** defaults to 15 days hourly, 91 days daily and the monthly
308
+ archive indefinitely. Change it per config, and the setup page generates the matching
309
+ rules and checks the real ones against them:
310
+
311
+ BACKUP_DB_TIERS = {'expire_days': {'monthly': 2557}} # end of month for 7 years
312
+ BACKUP_DB_TIERS = {'expire_days': {'hourly': 30, 'daily': 180, 'monthly': None}}
313
+
314
+ `None` means no rule at all, so that tier is kept until someone deletes it. By default the
315
+ application never applies these numbers - the destination's own rules are what actually
316
+ delete, and the page reads them back: a rule that expires a tier *sooner* than the config
317
+ asks for is a red row, and one that keeps it *longer* an amber one.
318
+
319
+ **Explicit deletes with a locked archive**
320
+
321
+ Lifecycle rules are only as durable as the bucket configuration - anyone with
322
+ `writeBuckets` can shorten them, and they delete silently. `delete: 'app'` moves the
323
+ deleting into the backup run, where it is logged and testable, and `lock_days` puts an
324
+ Object Lock retention on the tier that then has nothing else protecting it:
325
+
326
+ BACKUP_DB_TIERS = {
327
+ 'delete': 'app', # default: 'lifecycle'
328
+ 'expire_days': {'hourly': 15, 'daily': 91, 'monthly': None},
329
+ 'lock_days': {'monthly': 2557}, # 7 years, per object
330
+ 'lock_mode': 'COMPLIANCE', # or 'GOVERNANCE'
331
+ }
332
+
333
+ In this mode no lifecycle rules are generated or expected; the backup run deletes hourly
334
+ dumps older than `expire_days['hourly']` and daily ones older than `expire_days['daily']`,
335
+ straight after promoting - so a dump is only ever deleted once its daily copy exists.
336
+
337
+ Object Lock in B2 is **per object**, not per bucket: enabling it on the bucket only
338
+ permits objects to carry a retention date, and only the tiers in `lock_days` get one. So
339
+ the monthly archive becomes immutable while hourly and daily stay freely deletable in the
340
+ same bucket. `COMPLIANCE` cannot be shortened by anyone, including the account owner -
341
+ which is the point, and also means you are committed to paying for those objects for the
342
+ full period, and cannot delete the bucket while any remain. `GOVERNANCE` allows a key
343
+ with `bypassGovernance` to delete early.
344
+
345
+ The bucket needs Object Lock enabling, which `b2 bucket update --file-lock-enabled
346
+ <bucket>` does on an existing bucket - it cannot be turned off again. The key needs
347
+ `deleteFiles` and the file-retention capabilities; the setup page generates both, and adds
348
+ an **Archive lock** row that HEADs the newest monthly dump to prove it really carries a
349
+ retention date rather than trusting the settings.
350
+
351
+ The trade-off is explicit: the backup credential can now delete, which is what an attacker
352
+ would use it for. What survives that is exactly the tiers in `lock_days`.
353
+
354
+ **Setting up the bucket**
355
+
356
+ Since the package never creates a bucket or writes a lifecycle rule, the *Storage Setup*
357
+ tab on the backup page (`/backup/setup/`) works out what is missing and shows the
358
+ commands to fix it. It has one panel per `BACKUP_CONFIGS` entry - every destination at
359
+ once, rather than the one the other pages are on - and is strictly read-only: it checks
360
+ whether the bucket exists and reads the rules already on it, and changes nothing.
361
+
362
+ For a Backblaze destination it generates commands for the
363
+ [b2 command-line tool v4](https://b2-command-line-tool.readthedocs.io/):
364
+
365
+ b2 account authorize <accountKeyID> <applicationKey>
366
+ b2 bucket create --lifecycle-rule '{"fileNamePrefix": "django_backup/db/hourly/", "daysFromUploadingToHiding": 15, "daysFromHidingToDeleting": 1}' \
367
+ --lifecycle-rule '{"fileNamePrefix": "django_backup/db/daily/", "daysFromUploadingToHiding": 91, "daysFromHidingToDeleting": 1}' \
368
+ my-backups allPrivate
369
+ b2 key create --bucket my-backups --name-prefix django_backup/ django-cloud-backup-default-my-backups listBuckets,listFiles,readFiles,writeFiles
370
+ b2 bucket list
371
+
372
+ Points the page makes, and the reasons behind them:
373
+
374
+ - The first command needs an **account-level key** with `writeBuckets`,
375
+ `readBucketEncryption`, `writeBucketEncryption` and `writeBucketRetentions`. That is not
376
+ the key the application should use - the restricted key from `b2 key create` is, and the
377
+ page works its capabilities out from what the config actually does:
378
+
379
+ | capability | why | when |
380
+ |---|---|---|
381
+ | `listBuckets` | find the bucket; read its versioning, object-lock and lifecycle configuration (the checks on this page) | always |
382
+ | `listFiles` | list backups for the UI, dedup and pruning | always |
383
+ | `readFiles` | download for restore, and read metadata (md5, schema, ip) | always |
384
+ | `writeFiles` | upload backups, and server-side copies (tier promotion, `changed_files='history'`) | always |
385
+ | `readBuckets` | `Get Bucket Versioning` | always - read-only, for this page |
386
+ | `readBucketRetentions` | `Get Object Lock Configuration` | always - read-only, for this page |
387
+ | `readBucketLifecycleRules` | `Get Lifecycle Configuration` | always - read-only, for this page |
388
+ | `deleteFiles` | `BACKUP_DB_RETENTION` pruning deletes from the application | only when the config prunes; **never** with `db_tiers`, where the bucket does the deleting |
389
+ | `readFileRetentions`, `writeFileRetentions` | stamp Object Lock retention at upload and top it up with `extend_retention` | only when `lock` is set in `BACKUP_STORAGE` |
390
+
391
+ Everything else - `writeBuckets`, `deleteBuckets`, `writeKeys`, `bypassGovernance` - is
392
+ deliberately absent: a key that can undo the protection is not protection.
393
+ `--name-prefix` scopes the key to the backup root so it cannot touch anything else in
394
+ the bucket.
395
+
396
+ A `restore_only` config gets a different key entirely -
397
+ `listBuckets,listFiles,readFiles,readBuckets`, enough to find and download another
398
+ machine's backups and nothing more - and no bucket commands at all, since the bucket and
399
+ its lifecycle rules belong to the machine that writes them.
400
+
401
+ B2 gates each bucket read behind its own capability, and the three `readBucket*` ones
402
+ above exist only in the S3-compatible API - there is no B2 native equivalent, so they
403
+ are easy to miss. Without them the queries fail with `AccessDenied` and the page shows
404
+ `Unknown` rather than "not configured", which is why it names the missing capability in
405
+ the row. **A B2 key cannot be edited after creation** - to add a capability, create a
406
+ new key and update `BACKUP_STORAGE`.
407
+ - `b2 bucket update` **replaces the whole rule set**, so when the bucket already exists
408
+ the generated command carries the rules already on it as well. Rules that overlap a
409
+ tier prefix cannot be kept (B2 rejects overlapping rules) and are listed as removed.
410
+ If the existing rules could not be read, the page says so rather than handing over a
411
+ command that would quietly wipe them.
412
+ - `--file-lock-enabled` is never generated: a retention lock stops lifecycle expiry.
413
+ - `daysFromHidingToDeleting` is always set. B2 buckets keep versions, so expiry only
414
+ *hides* a file - without it the hidden version is kept and charged for forever. The
415
+ per-tier status row flags an existing rule that gets this wrong.
416
+ - A schema backed up separately needs its own pair of rules; the page adds them for the
417
+ schema folders it finds.
418
+ - Only b2 CLI v4 is supported. v3 (`create-bucket`, `--lifecycleRules`) is deliberately
419
+ not generated. AWS, R2, Azure and Drive destinations get a panel describing what to
420
+ create rather than commands.
421
+
422
+ A lifecycle rule is JSON, and every shell mangles it differently, so the panel has
423
+ **bash / PowerShell / cmd.exe** buttons that re-quote the commands - bash gets
424
+ `'{"fileNamePrefix": ...}'`, the Windows shells get `"{\"fileNamePrefix\": ...}"`, and
425
+ the PowerShell form carries the `--%` stop-parsing token because neither PowerShell 5.1
426
+ nor 7 passes a JSON argument to a native command unaltered. Copy the wrong one and b2
427
+ rejects the argument. The page starts on the shell your **browser's** platform suggests -
428
+ not the server's, since the page is usually served from a Linux container to a Windows
429
+ workstation and it is the workstation that runs b2. The management command takes
430
+ `--shell bash|powershell|cmd`, defaulting to the platform it runs on.
431
+
432
+ Each command has a clipboard button, plus a *Copy all* for the whole block. Copying uses
433
+ the browser's clipboard API, which only works over https or on localhost.
434
+
435
+ `python manage.py storage_setup [--config <name>]` prints the same thing on a server
436
+ with no web UI.
437
+
438
+ **Client-side encryption**
439
+
440
+ By default backups are stored as the provider receives them - anyone with access to
441
+ the Drive folder or bucket can read a full database dump. Setting `BACKUP_ENCRYPTION`
442
+ encrypts every backup (database dumps, local folder files and S3-source files) on the
443
+ client before upload, using chunked AES-256-GCM, so the provider only ever holds
444
+ ciphertext:
445
+
446
+ BACKUP_ENCRYPTION = True # reuse the encrypted-credentials SETTINGS_KEY
447
+ BACKUP_ENCRYPTION = '...' # or a dedicated urlsafe-base64 32-byte key
448
+
449
+ `True` derives backup keys from the same `SETTINGS_KEY` that already protects the
450
+ encrypted credentials - nothing new to manage, and the key never sits in the
451
+ repository. The trade-off is coupling: today `SETTINGS_KEY` can be rotated cheaply by
452
+ re-encrypting the `.enc` settings files, but once backups are encrypted with it, old
453
+ backups need the old key forever. A dedicated key avoids that; generate one with:
454
+
455
+ python -c "from encrypted_credentials.encrypted_file import random_key; print(random_key())"
456
+
457
+ and keep it in the encrypted private settings, not plain settings.py.
458
+
459
+ Notes:
460
+
461
+ - Restores are transparent - encrypted and older unencrypted backups are detected by
462
+ content and both restore normally, including `restore_db --local_file`. A wrong or
463
+ missing key fails cleanly before anything reaches `pg_restore`.
464
+ - **Losing the key means losing every backup encrypted with it.** Keep a copy of the
465
+ key somewhere that does not depend on the server or the backups themselves.
466
+ - File deduplication keeps working: the plaintext md5 is recorded in each file's
467
+ metadata at upload and compared on later runs. If you turn encryption off again,
468
+ already-encrypted file backups re-upload once (their metadata is no longer fetched).
469
+ - Database backups briefly need twice the dump size in `BACKUP_LOCAL_DB_DIR` while the
470
+ ciphertext copy is written; folder and S3-source backups encrypt in-stream with no
471
+ extra disk.
472
+ - Requires the `cryptography` package (`pip install django-cloud-backup[encryption]`) -
473
+ already present in practice, as encrypted-credentials depends on it.
474
+ - `BackupAzureToS3` is a separate rclone-compatible mirror and is not encrypted.
475
+ - With multiple backup configurations (below), encryption is set per config rather
476
+ than globally.
477
+
478
+ **Multiple backup configurations**
479
+
480
+ `BACKUP_CONFIGS` lets one project back up to several destinations with different
481
+ behaviour per destination - the classic case being a hardened offsite backup plus an
482
+ unencrypted database copy that a staging server restores from:
483
+
484
+ BACKUP_CONFIGS = {
485
+ 'default': {
486
+ 'storage': {'backend': 's3', 'bucket': 'offsite-backups', ..., 'lock': {...}},
487
+ 'encryption': True,
488
+ 'changed_files': 'protect',
489
+ },
490
+ 'staging': {
491
+ 'storage': {'backend': 's3', 'bucket': 'staging-transfer', ...},
492
+ 'encryption': False,
493
+ 'dirs': [], # database only, no folder backups
494
+ 'retention': [{'days': 1, 'number': 2}], # keep just the latest couple of dumps
495
+ 'changed_files': 'overwrite',
496
+ },
497
+ }
498
+
499
+ Config keys: `storage` (a `BACKUP_STORAGE`-style dict), `encryption`, `db` (include
500
+ the database, default True), `db_dir`, `dirs` (as `BACKUP_DIRS`), `azure_dirs` and
501
+ `azure_source` (as `AZURE_BACKUP_DIRS` / `AZURE_BACKUP_SOURCE`), `s3_dirs` (as
502
+ `S3_BACKUP_DIRS`), `retention`, `changed_files`, `db_tiers`, `restore_only` (read this
503
+ destination, never write to it - see *Live, staging and local machines* below).
504
+ **A key absent from a config
505
+ inherits the corresponding legacy global setting** (`BACKUP_STORAGE`,
506
+ `BACKUP_ENCRYPTION`, `BACKUP_DIRS`, ...), so shared values can stay in the globals -
507
+ but note that means a config without `'dirs': []` backs up the global `BACKUP_DIRS`.
508
+ Without `BACKUP_CONFIGS` the globals simply are the default config, so existing
509
+ installations are unaffected.
510
+
511
+ Running a config:
512
+
513
+ python manage.py backup_website --config staging
514
+ python manage.py restore_db --config staging # e.g. on the staging server
515
+
516
+ CELERY_BEAT_SCHEDULE = {
517
+ 'backup': {'task': 'cloud_backup.tasks.backup',
518
+ 'schedule': crontab(hour='8-19', minute=10)},
519
+ 'backup_staging': {'task': 'cloud_backup.tasks.backup',
520
+ 'schedule': crontab(hour=6, minute=0),
521
+ 'kwargs': {'config': 'staging'}},
522
+ }
523
+
524
+ The enhanced web UI shows a tab per destination - plus a *Storage Setup* tab, which is
525
+ how that page is reached - and everything on the page (the listings, the backup and
526
+ restore buttons, verify and empty trash) works on the selected destination. It opens on
527
+ the first config that includes the database, since a files-only destination has no
528
+ database page: that config's tab goes straight to its file browser instead. A destination whose settings do not resolve gets a warning tab
529
+ pointing at *Storage Setup*, which is the page that explains it. The selection is in
530
+ the url as `?config=<name>`, so a tab is bookmarkable. Un-parameterised tasks and the
531
+ basic (non-enhanced) UI still use the config named `'default'` - or the only entry, if
532
+ there is exactly one. Config names may contain any characters; the UI never puts the
533
+ name in a modal url.
534
+
535
+ Note that the file browser's directory index is per config: `/backup/files/0/` is the
536
+ first entry in *that* config's `dirs`.
537
+
538
+ For the staging pattern, the staging server's own
539
+ settings point a config at the same transfer bucket and `restore_db` pulls from it -
540
+ production never shares its offsite credentials or encryption key with staging. If
541
+ the transfer bucket holds an unencrypted production dump, treat the bucket itself as
542
+ production-sensitive, or give that config a dedicated key the staging server also
543
+ has.
544
+
545
+ Backups made by one config restore with that config's key: restoring an encrypted
546
+ backup through a config with a different key (or none) fails cleanly.
547
+
548
+
549
+ **Live, staging and local machines**
550
+
551
+ The usual three-role setup: one server produces the backups, and the others restore them
552
+ to get a copy of live data to work with.
553
+
554
+ | Role | Backs up | Restores | Backup root |
555
+ |---|---|---|---|
556
+ | Live | yes, on a schedule | no - web restore off | `backup/live` |
557
+ | Staging | occasionally, its own data | from live's dumps | `backup/staging` |
558
+ | Local machine | occasionally, its own data | from live's dumps | `backup/local` |
559
+
560
+ Staging never touches the live server: it reads live's dumps out of the bucket live backs
561
+ up to. That destination is marked **`'restore_only': True`**, which is what stops staging
562
+ writing into another machine's backups - every write refuses
563
+ (`RestoreOnlyConfig`), the web UI offers no backup, empty-trash or undelete action for it,
564
+ and *Storage Setup* generates a read-only key for it instead of the usual one. It is a
565
+ config setting rather than a matter of credentials because machines commonly share one
566
+ encrypted settings file, so the same credential is on all of them and only the config can
567
+ tell the roles apart.
568
+
569
+ # live/settings.py
570
+ BACKUP_ALLOW_RESTORE = False # also the default once DEBUG is off
571
+ BACKUP_ENCRYPTION = True
572
+ BACKUP_STORAGE = {'backend': 's3', 'b2': True, 'bucket': 'my-backups',
573
+ 'access_key_id': access_key_id, 'secret_key': secret_key,
574
+ 'root': 'backup/live'}
575
+ BACKUP_DIRS = [(MEDIA_ROOT, 'media')]
576
+
577
+ # staging/settings.py - the local machine is the same with root 'backup/local'
578
+ BACKUP_ALLOW_RESTORE = True # restore from the management page
579
+ BACKUP_ENCRYPTION = True # the shared settings key, so live's dumps decrypt
580
+ BACKUP_STORAGE = {...as above...}
581
+ BACKUP_CONFIGS = {
582
+ 'default': {'storage': dict(BACKUP_STORAGE, root='backup/staging')},
583
+ 'live': {'storage': dict(BACKUP_STORAGE, root='backup/live'),
584
+ 'restore_only': True,
585
+ 'dirs': [], 's3_dirs': []}, # the database is what gets restored
586
+ }
587
+
588
+ Restoring live's latest dump on staging:
589
+
590
+ python manage.py restore_db --config live
591
+
592
+ or from the management page: pick the *live* tab and use **Drop Restore** on a dump.
593
+
594
+ Points worth getting right:
595
+
596
+ - **Give each role its own `root`.** Pruning is scoped to the machine's own public IP so
597
+ servers do not delete each other's dumps, but `db_tiers` promotion has no such filter -
598
+ a staging dump written into live's prefix would be promoted into live's monthly archive.
599
+ Separate roots keep each machine's retention entirely its own.
600
+ - **`BACKUP_ALLOW_RESTORE` off on live**, which is what it already is once `DEBUG` is off.
601
+ It is enforced server-side on every web restore endpoint. `manage.py restore_db` is not
602
+ affected by it, so disaster recovery on live stays possible from the command line.
603
+ - **Never schedule `cloud_backup.tasks.backup` with `kwargs={'config': 'live'}`** anywhere
604
+ but live. It would refuse anyway, but a beat schedule that raises every night is noise.
605
+ - The same encrypted settings file on every machine means `BACKUP_ENCRYPTION = True`
606
+ derives the same key everywhere, so staging can decrypt live's dumps with nothing extra
607
+ to configure. If the machines do **not** share settings, either give the restore_only
608
+ config live's key explicitly, or have live write a second, unencrypted copy to a
609
+ transfer bucket that staging reads (the *Multiple backup configurations* example above).
610
+ - Restoring writes to `DATABASES['default']` of the machine doing the restoring - the
611
+ config picks which dumps to read, never where they land.
612
+
613
+ If a machine only ever restores and backs nothing up at all, `BACKUP_RESTORE_ONLY = True`
614
+ sets the flag globally without needing `BACKUP_CONFIGS`.
615
+
616
+
617
+ **Management commands**
618
+
619
+ python manage.py backup_website
620
+ python manage.py restore_db
621
+ python manage.py storage_setup
622
+
623
+ **Management page**
624
+
625
+ urls.py
626
+
627
+ urlpatterns = [
628
+ path('backup/', include('cloud_backup.urls')),
629
+ ....
630
+
631
+
632
+ All URL names live under the `cloud_backup` namespace (e.g.
633
+ `reverse('cloud_backup:backup-info')`). Previously the basic management page
634
+ used un-namespaced names such as `backup-info`; add the `cloud_backup:` prefix
635
+ if you reverse them yourself.
636
+
637
+ An enhanced version of the management page will be shown if the following django apps are installed
638
+
639
+ 'django_modals', 'django_datatables', 'django_menus', 'ajax_helpers'
640
+
641
+ from the following PyPi packages
642
+
643
+ django-nested-modals, django-filtered-datatables, django-tab-menus, django-ajax-helpers
644
+
645
+ **Branding the management page**
646
+
647
+ The enhanced page views build the whole UI (menus, storage info and tables) into a
648
+ single HTML string, `{{ backup_content }}`, so it can be dropped into your own
649
+ template. Subclass the base views and set `template_name`:
650
+
651
+ from cloud_backup.enhanced_views import (BackupBaseView, BackupFilesBaseView,
652
+ SchemaTableBaseView, StorageSetupBaseView)
653
+
654
+ class MyBackupView(BackupBaseView):
655
+ template_name = 'myapp/backup.html'
656
+
657
+ class MySchemaTableView(SchemaTableBaseView):
658
+ template_name = 'myapp/backup.html'
659
+
660
+ class MyBackupFilesView(BackupFilesBaseView):
661
+ template_name = 'myapp/backup.html'
662
+
663
+ class MyStorageSetupView(StorageSetupBaseView):
664
+ template_name = 'myapp/backup.html'
665
+
666
+ The template must include the ajax_helpers/datatables/modals libraries and the
667
+ page script, then place the content wherever it fits your layout:
668
+
669
+ {% load ajax_helpers %}
670
+ {% lib_include 'ajax_helpers' 'Bootstrap' 'FontAwesome' module='ajax_helpers.includes' %}
671
+ {% lib_include 'datatable' module='django_datatables.includes' %}
672
+ {% lib_include 'Modals' module='django_modals.includes' %}
673
+ {{ ajax_helpers_script }}
674
+ ...
675
+ {{ backup_content }}
676
+
677
+ Register the subclasses with `backup_urlpatterns` so the menu links and modals
678
+ (which reverse the standard `cloud_backup:` URL names) point at your views:
679
+
680
+ from cloud_backup.urls import backup_urlpatterns
681
+
682
+ urlpatterns = [
683
+ path('backup/', include((backup_urlpatterns(
684
+ backup_view=MyBackupView, schema_table_view=MySchemaTableView,
685
+ files_view=MyBackupFilesView, setup_view=MyStorageSetupView), 'cloud_backup'))),
686
+ ]
687
+
688
+ The unbranded standard page remains the default when using
689
+ `include('cloud_backup.urls')`.
690
+
691
+ **Restoring from the management page**
692
+
693
+ Restore and drop-schema actions on the enhanced management page require
694
+
695
+ BACKUP_ALLOW_RESTORE = True
696
+
697
+ which defaults to the value of `DEBUG`. This is enforced server-side on every
698
+ restore endpoint (not just by hiding the buttons), so a production server with
699
+ `DEBUG = False` and no `BACKUP_ALLOW_RESTORE` setting cannot be restored from
700
+ the web UI even by a superuser. Set `BACKUP_ALLOW_RESTORE = True` on staging and
701
+ development machines where restoring is wanted. The `manage.py restore_db`
702
+ command is not affected by this setting, so disaster recovery on a live server
703
+ remains possible from the command line.
704
+
705
+ **Browsing and verifying folder backups**
706
+
707
+ When `BACKUP_DIRS`, `AZURE_BACKUP_DIRS` (or `S3_BACKUP_DIRS`) is configured, the
708
+ enhanced management page shows a `Backup Files` button that backs up all configured
709
+ folders without touching the database, and a single `Files` button opening a file
710
+ browser. Its root level lists each configured backup directory as a folder (a cloud
711
+ icon marks an Azure source); clicking through navigates the backed-up tree one level
712
+ at a time (with breadcrumbs back up), and files show their size, backup date and
713
+ checksum - the plaintext md5 recorded with the file at upload time (so it stays
714
+ comparable when client-side encryption is enabled).
715
+
716
+ The `Verify` button on each row re-hashes the file on the server's local disk
717
+ (or, for an Azure source, reads the blob's current md5/etag) and compares it with
718
+ what was recorded at backup time, reporting:
719
+
720
+ - `Match` - the source file is identical to its backup
721
+ - `Changed` - the source file no longer matches its backup
722
+ - `Missing locally` / `Missing from Azure` - the source file has been deleted since
723
+ it was backed up
724
+ - `No stored checksum` - the backup has no comparable checksum (e.g. a large
725
+ multipart S3 upload made without md5 metadata)
726
+
727
+ `Verify All Files` runs the same comparison over the whole directory as a
728
+ celery task (the worker must be running) and reports a summary.
729
+
730
+ The browser carries the same backup buttons as the management page, so a
731
+ destination that has no database page - a config with `db` off, whose tab opens
732
+ the browser - can still be backed up from the web UI. Its root listing has
733
+ `Backup Files`, and inside one directory there is a `Backup <directory>` button
734
+ that backs up just that folder source (the whole directory, not the sub-folder
735
+ being browsed). The equivalent on the command line is
736
+ `backup_website --folders_only --backup_dir <index>`, where the index counts
737
+ `BACKUP_DIRS` entries first and then `AZURE_BACKUP_DIRS`.
738
+
739
+ The browser and verification are read-only and require the same `access_admin`
740
+ permission as the rest of the management page; the backup buttons, like every
741
+ other backup button, require a superuser. Note that on an S3-compatible
742
+ destination with client-side encryption enabled, listing the checksums costs one
743
+ metadata request per file, so the page can be slow to load for very large trees.
744
+
745
+ **Configure Azure folder backups**
746
+
747
+ Media that django-storages keeps in Azure Blob Storage has no local directory for
748
+ `BACKUP_DIRS` to back up. `AZURE_BACKUP_DIRS` names prefixes ("folders") in the
749
+ container instead, and they are backed up through exactly the same pipeline as a local
750
+ directory: the same destination folders (so `media` below appears in the file browser
751
+ just as a local `media` would), client-side encryption, `BACKUP_CHANGED_FILES`
752
+ protection, object lock and per-file verification. Requires
753
+ `pip install django-cloud-backup[azure]`.
754
+
755
+ settings.py
756
+
757
+ # (blob prefix, destination folder). The prefix has no trailing slash and is
758
+ # relative to the container - include django-storages' `location` if one is set.
759
+ # '' is the whole container.
760
+ AZURE_BACKUP_DIRS = [('media', 'media')]
761
+
762
+ When the project's default file storage is django-storages' `AzureStorage`, its
763
+ container and credentials (the `STORAGES['default']['OPTIONS']` or `AZURE_*`
764
+ settings) are used and nothing else is needed. To back up some other container, or
765
+ when the default storage is not Azure, say which:
766
+
767
+ AZURE_BACKUP_SOURCE = {'container': 'media', 'connection_string': connection_string}
768
+ # or {'container': 'media', 'account_url': 'https://<account>.blob.core.windows.net',
769
+ # 'credential': account_key_or_sas_token}
770
+
771
+ Both are available per config as `azure_dirs` / `azure_source`. Nothing is downloaded
772
+ to decide what needs backing up: a blob is skipped when its md5 (which Azure records
773
+ for single-request uploads - django-storages' normal case) or otherwise its etag
774
+ matches what was stored with the backup, so an unchanged blob costs one listing entry
775
+ and a changed one is re-uploaded. The `backup_azure_s3.BackupAzureToS3` class is
776
+ different: a standalone rclone-compatible mirror that bypasses this pipeline.
777
+
778
+ **Configure S3 folder backups**
779
+
780
+ settings.py
781
+
782
+ AWS_ACCESS_KEY_ID = id
783
+ AWS_SECRET_ACCESS_KEY = key
784
+ AWS_PRIVATE_STORAGE_BUCKET_NAME = bucket
785
+
786
+ S3_BACKUP_DIRS = [('S3-source-folder1', 'google-drive-folder1'),
787
+ ('S3-source-folder2', 'google-drive-folder2')
788
+ ]
789
+
790
+ **Configure cleaning of old datatabase backups**
791
+
792
+ settings.py
793
+
794
+ BACKUP_DB_RETENTION = [{'hours': 1, 'number': 4},
795
+ {'hours': 2, 'number': 10},
796
+ {'days': 1, 'number': 10},
797
+ {'months': 1, 'number': 36},
798
+ ]
799
+
800
+ Each entry keeps the newest dump in each period for that many periods, and everything
801
+ not kept by some entry is deleted after each backup. On an S3-compatible destination
802
+ `BACKUP_DB_TIERS` (above) is the alternative: the bucket's lifecycle rules do the
803
+ deleting instead, and the application never needs delete permission.
804
+
805
+
806
+ **Schedule backup with celery beat**
807
+
808
+ CELERY_BEAT_SCHEDULE = {
809
+ 'backup': {
810
+ 'task': 'cloud_backup.tasks.backup',
811
+ 'schedule': crontab(hour='8-19', minute=10, day_of_week='mon-fri')
812
+ }
813
+ }
814
+