django-cloud-backup 0.1.0__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 (42) hide show
  1. django_cloud_backup-0.1.0/LICENSE +21 -0
  2. django_cloud_backup-0.1.0/MANIFEST.in +1 -0
  3. django_cloud_backup-0.1.0/PKG-INFO +439 -0
  4. django_cloud_backup-0.1.0/README.md +416 -0
  5. django_cloud_backup-0.1.0/cloud_backup/__init__.py +0 -0
  6. django_cloud_backup-0.1.0/cloud_backup/apps.py +5 -0
  7. django_cloud_backup-0.1.0/cloud_backup/backup.py +109 -0
  8. django_cloud_backup-0.1.0/cloud_backup/backup_azure_s3.py +119 -0
  9. django_cloud_backup-0.1.0/cloud_backup/backup_db.py +211 -0
  10. django_cloud_backup-0.1.0/cloud_backup/backup_local_files.py +66 -0
  11. django_cloud_backup-0.1.0/cloud_backup/backup_s3.py +159 -0
  12. django_cloud_backup-0.1.0/cloud_backup/base_backup.py +62 -0
  13. django_cloud_backup-0.1.0/cloud_backup/compression.py +36 -0
  14. django_cloud_backup-0.1.0/cloud_backup/config.py +87 -0
  15. django_cloud_backup-0.1.0/cloud_backup/encryption.py +267 -0
  16. django_cloud_backup-0.1.0/cloud_backup/enhanced_views.py +273 -0
  17. django_cloud_backup-0.1.0/cloud_backup/management/__init__.py +0 -0
  18. django_cloud_backup-0.1.0/cloud_backup/management/commands/__init__.py +0 -0
  19. django_cloud_backup-0.1.0/cloud_backup/management/commands/backup_website.py +77 -0
  20. django_cloud_backup-0.1.0/cloud_backup/management/commands/restore_db.py +23 -0
  21. django_cloud_backup-0.1.0/cloud_backup/modals.py +107 -0
  22. django_cloud_backup-0.1.0/cloud_backup/prune_backups.py +43 -0
  23. django_cloud_backup-0.1.0/cloud_backup/sql_functions.py +46 -0
  24. django_cloud_backup-0.1.0/cloud_backup/storages/__init__.py +51 -0
  25. django_cloud_backup-0.1.0/cloud_backup/storages/azure.py +176 -0
  26. django_cloud_backup-0.1.0/cloud_backup/storages/base.py +151 -0
  27. django_cloud_backup-0.1.0/cloud_backup/storages/gdrive.py +135 -0
  28. django_cloud_backup-0.1.0/cloud_backup/storages/s3.py +256 -0
  29. django_cloud_backup-0.1.0/cloud_backup/tasks.py +82 -0
  30. django_cloud_backup-0.1.0/cloud_backup/templates/cloud_backup/backup.html +29 -0
  31. django_cloud_backup-0.1.0/cloud_backup/templates/cloud_backup/backup_content.html +17 -0
  32. django_cloud_backup-0.1.0/cloud_backup/templates/cloud_backup/info.html +165 -0
  33. django_cloud_backup-0.1.0/cloud_backup/urls.py +45 -0
  34. django_cloud_backup-0.1.0/cloud_backup/utils.py +7 -0
  35. django_cloud_backup-0.1.0/cloud_backup/views.py +43 -0
  36. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/PKG-INFO +439 -0
  37. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/SOURCES.txt +40 -0
  38. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/dependency_links.txt +1 -0
  39. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/requires.txt +12 -0
  40. django_cloud_backup-0.1.0/django_cloud_backup.egg-info/top_level.txt +1 -0
  41. django_cloud_backup-0.1.0/pyproject.toml +38 -0
  42. django_cloud_backup-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Ian Jones
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ recursive-include cloud_backup/templates *
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-cloud-backup
3
+ Version: 0.1.0
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
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.
232
+
233
+ **Client-side encryption**
234
+
235
+ By default backups are stored as the provider receives them - anyone with access to
236
+ the Drive folder or bucket can read a full database dump. Setting `BACKUP_ENCRYPTION`
237
+ encrypts every backup (database dumps, local folder files and S3-source files) on the
238
+ client before upload, using chunked AES-256-GCM, so the provider only ever holds
239
+ ciphertext:
240
+
241
+ BACKUP_ENCRYPTION = True # reuse the encrypted-credentials SETTINGS_KEY
242
+ BACKUP_ENCRYPTION = '...' # or a dedicated urlsafe-base64 32-byte key
243
+
244
+ `True` derives backup keys from the same `SETTINGS_KEY` that already protects the
245
+ encrypted credentials - nothing new to manage, and the key never sits in the
246
+ repository. The trade-off is coupling: today `SETTINGS_KEY` can be rotated cheaply by
247
+ re-encrypting the `.enc` settings files, but once backups are encrypted with it, old
248
+ backups need the old key forever. A dedicated key avoids that; generate one with:
249
+
250
+ python -c "from encrypted_credentials.encrypted_file import random_key; print(random_key())"
251
+
252
+ and keep it in the encrypted private settings, not plain settings.py.
253
+
254
+ Notes:
255
+
256
+ - Restores are transparent - encrypted and older unencrypted backups are detected by
257
+ content and both restore normally, including `restore_db --local_file`. A wrong or
258
+ missing key fails cleanly before anything reaches `pg_restore`.
259
+ - **Losing the key means losing every backup encrypted with it.** Keep a copy of the
260
+ key somewhere that does not depend on the server or the backups themselves.
261
+ - File deduplication keeps working: the plaintext md5 is recorded in each file's
262
+ metadata at upload and compared on later runs. If you turn encryption off again,
263
+ already-encrypted file backups re-upload once (their metadata is no longer fetched).
264
+ - Database backups briefly need twice the dump size in `BACKUP_LOCAL_DB_DIR` while the
265
+ ciphertext copy is written; folder and S3-source backups encrypt in-stream with no
266
+ extra disk.
267
+ - Requires the `cryptography` package (`pip install django-cloud-backup[encryption]`) -
268
+ already present in practice, as encrypted-credentials depends on it.
269
+ - `BackupAzureToS3` is a separate rclone-compatible mirror and is not encrypted.
270
+ - With multiple backup configurations (below), encryption is set per config rather
271
+ than globally.
272
+
273
+ **Multiple backup configurations**
274
+
275
+ `BACKUP_CONFIGS` lets one project back up to several destinations with different
276
+ behaviour per destination - the classic case being a hardened offsite backup plus an
277
+ unencrypted database copy that a staging server restores from:
278
+
279
+ BACKUP_CONFIGS = {
280
+ 'default': {
281
+ 'storage': {'backend': 's3', 'bucket': 'offsite-backups', ..., 'lock': {...}},
282
+ 'encryption': True,
283
+ 'changed_files': 'protect',
284
+ },
285
+ 'staging': {
286
+ 'storage': {'backend': 's3', 'bucket': 'staging-transfer', ...},
287
+ 'encryption': False,
288
+ 'dirs': [], # database only, no folder backups
289
+ 'retention': [{'days': 1, 'number': 2}], # keep just the latest couple of dumps
290
+ 'changed_files': 'overwrite',
291
+ },
292
+ }
293
+
294
+ Config keys: `storage` (a `BACKUP_STORAGE`-style dict), `encryption`, `db` (include
295
+ the database, default True), `db_dir`, `dirs` (as `BACKUP_DIRS`), `s3_dirs` (as
296
+ `S3_BACKUP_DIRS`), `retention`, `changed_files`. **A key absent from a config
297
+ inherits the corresponding legacy global setting** (`BACKUP_STORAGE`,
298
+ `BACKUP_ENCRYPTION`, `BACKUP_DIRS`, ...), so shared values can stay in the globals -
299
+ but note that means a config without `'dirs': []` backs up the global `BACKUP_DIRS`.
300
+ Without `BACKUP_CONFIGS` the globals simply are the default config, so existing
301
+ installations are unaffected.
302
+
303
+ Running a config:
304
+
305
+ python manage.py backup_website --config staging
306
+ python manage.py restore_db --config staging # e.g. on the staging server
307
+
308
+ CELERY_BEAT_SCHEDULE = {
309
+ 'backup': {'task': 'cloud_backup.tasks.backup',
310
+ 'schedule': crontab(hour='8-19', minute=10)},
311
+ 'backup_staging': {'task': 'cloud_backup.tasks.backup',
312
+ 'schedule': crontab(hour=6, minute=0),
313
+ 'kwargs': {'config': 'staging'}},
314
+ }
315
+
316
+ The web UI and un-parameterised tasks use the config named `'default'` (or the only
317
+ entry, if there is exactly one). For the staging pattern, the staging server's own
318
+ settings point a config at the same transfer bucket and `restore_db` pulls from it -
319
+ production never shares its offsite credentials or encryption key with staging. If
320
+ the transfer bucket holds an unencrypted production dump, treat the bucket itself as
321
+ production-sensitive, or give that config a dedicated key the staging server also
322
+ has.
323
+
324
+ Backups made by one config restore with that config's key: restoring an encrypted
325
+ backup through a config with a different key (or none) fails cleanly.
326
+
327
+
328
+ **Management commands**
329
+
330
+ python manage.py backup_website
331
+ python manage.py restore_db
332
+
333
+ **Management page**
334
+
335
+ urls.py
336
+
337
+ urlpatterns = [
338
+ path('backup/', include('cloud_backup.urls')),
339
+ ....
340
+
341
+
342
+ All URL names live under the `cloud_backup` namespace (e.g.
343
+ `reverse('cloud_backup:backup-info')`). Previously the basic management page
344
+ used un-namespaced names such as `backup-info`; add the `cloud_backup:` prefix
345
+ if you reverse them yourself.
346
+
347
+ An enhanced version of the management page will be shown if the following django apps are installed
348
+
349
+ 'django_modals', 'django_datatables', 'django_menus', 'ajax_helpers'
350
+
351
+ from the following PyPi packages
352
+
353
+ django-nested-modals, django-filtered-datatables, django-tab-menus, django-ajax-helpers
354
+
355
+ **Branding the management page**
356
+
357
+ The enhanced page views build the whole UI (menus, storage info and tables) into a
358
+ single HTML string, `{{ backup_content }}`, so it can be dropped into your own
359
+ template. Subclass the base views and set `template_name`:
360
+
361
+ from cloud_backup.enhanced_views import BackupBaseView, SchemaTableBaseView
362
+
363
+ class MyBackupView(BackupBaseView):
364
+ template_name = 'myapp/backup.html'
365
+
366
+ class MySchemaTableView(SchemaTableBaseView):
367
+ template_name = 'myapp/backup.html'
368
+
369
+ The template must include the ajax_helpers/datatables/modals libraries and the
370
+ page script, then place the content wherever it fits your layout:
371
+
372
+ {% load ajax_helpers %}
373
+ {% lib_include 'ajax_helpers' 'Bootstrap' 'FontAwesome' module='ajax_helpers.includes' %}
374
+ {% lib_include 'datatable' module='django_datatables.includes' %}
375
+ {% lib_include 'Modals' module='django_modals.includes' %}
376
+ {{ ajax_helpers_script }}
377
+ ...
378
+ {{ backup_content }}
379
+
380
+ Register the subclasses with `backup_urlpatterns` so the menu links and modals
381
+ (which reverse the standard `cloud_backup:` URL names) point at your views:
382
+
383
+ from cloud_backup.urls import backup_urlpatterns
384
+
385
+ urlpatterns = [
386
+ path('backup/', include((backup_urlpatterns(
387
+ backup_view=MyBackupView, schema_table_view=MySchemaTableView), 'cloud_backup'))),
388
+ ]
389
+
390
+ The unbranded standard page remains the default when using
391
+ `include('cloud_backup.urls')`.
392
+
393
+ **Restoring from the management page**
394
+
395
+ Restore and drop-schema actions on the enhanced management page require
396
+
397
+ BACKUP_ALLOW_RESTORE = True
398
+
399
+ which defaults to the value of `DEBUG`. This is enforced server-side on every
400
+ restore endpoint (not just by hiding the buttons), so a production server with
401
+ `DEBUG = False` and no `BACKUP_ALLOW_RESTORE` setting cannot be restored from
402
+ the web UI even by a superuser. Set `BACKUP_ALLOW_RESTORE = True` on staging and
403
+ development machines where restoring is wanted. The `manage.py restore_db`
404
+ command is not affected by this setting, so disaster recovery on a live server
405
+ remains possible from the command line.
406
+
407
+
408
+ **Configure S3 folder backups**
409
+
410
+ settings.py
411
+
412
+ AWS_ACCESS_KEY_ID = id
413
+ AWS_SECRET_ACCESS_KEY = key
414
+ AWS_PRIVATE_STORAGE_BUCKET_NAME = bucket
415
+
416
+ S3_BACKUP_DIRS = [('S3-source-folder1', 'google-drive-folder1'),
417
+ ('S3-source-folder2', 'google-drive-folder2')
418
+ ]
419
+
420
+ **Configure cleaning of old datatabase backups**
421
+
422
+ settings.py
423
+
424
+ BACKUP_DB_RETENTION = [{'hours': 1, 'number': 4},
425
+ {'hours': 2, 'number': 10},
426
+ {'days': 1, 'number': 10},
427
+ {'months': 1, 'number': 36},
428
+ ]
429
+
430
+
431
+ **Schedule backup with celery beat**
432
+
433
+ CELERY_BEAT_SCHEDULE = {
434
+ 'backup': {
435
+ 'task': 'cloud_backup.tasks.backup',
436
+ 'schedule': crontab(hour='8-19', minute=10, day_of_week='mon-fri')
437
+ }
438
+ }
439
+