Skip to main content

Backs up django postgres databases, local folders and S3 folders to a Google Drive folder through a google service account.

Project description

django-gdrive-backup

Backs up django postgres databases, local folders and S3 folders to a Google Drive folder through a google service account.

Create service account

Requires a Google service account with the Google Drive API enabled

https://console.cloud.google.com/apis/credentials/serviceaccountkey

Store service account key

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.

settings.py

CREDENTIAL_FOLDER = os.path.join(BASE_DIR, 'credentials')
CREDENTIAL_FILES = {
    'drive': 'service-account.json',
}

Create Google Drive folder and share with service account

With a Google Drive account create a folder and share with the email address of the service account.

Configure database backup

settings.py

BACKUP_GDRIVE_DIR = 'django_backup'
BACKUP_GDRIVE_DB = BACKUP_GDRIVE_DIR + '/db'

Management commands

python manage.py backup_website
python manage.py restore_db

Management page

urls.py

urlpatterns = [
                path('backup/', include('gdrive_backup.urls')),
                ....

Configure S3 folder backups

settings.py

        AWS_ACCESS_KEY_ID = id
        AWS_SECRET_ACCESS_KEY = key
        AWS_PRIVATE_STORAGE_BUCKET_NAME = bucket

        S3_BACKUP_DIRS = [('S3-source-folder1', 'google-drive-folder1'),
                          ('S3-source-folder2', 'google-drive-folder2')
        ]

Configure cleaning of old datatabase backups

settings.py

BACKUP_DB_RETENTION = [{'hours': 1, 'number': 4}, 
                       {'hours': 2, 'number': 10},
                       {'days': 1, 'number': 10},
                       {'months': 1, 'number': 36},
                       ]

Schedule backup with celery beat

CELERY_BEAT_SCHEDULE = {
    'backup': {
        'task': 'gdrive_backup.tasks.backup',
        'schedule': crontab(hour='8-19', minute=10, day_of_week='mon-fri')
    }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-gdrive-backup-0.0.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

django_gdrive_backup-0.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file django-gdrive-backup-0.0.1.tar.gz.

File metadata

  • Download URL: django-gdrive-backup-0.0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.3

File hashes

Hashes for django-gdrive-backup-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4e8e080b3f8e1c11a9b18980d5a512b8b6f568eeb2e4b631c8dbd2b528ff9540
MD5 ef8d5bf823325f30c9f92d69a7f74f93
BLAKE2b-256 0b7c7b8a06a97b25406622424b989f225fcc0cead4f7937ef27c78544df9e8d7

See more details on using hashes here.

File details

Details for the file django_gdrive_backup-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_gdrive_backup-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.3

File hashes

Hashes for django_gdrive_backup-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 beb97ca7dcc5a41012b287e37755ece8a60a4615ae987bf770d7fd80850d3cce
MD5 d1de24dd32be04aa95878494e5d774f1
BLAKE2b-256 c78a922bf11115c23f5ead963cad7d2e3a6e308023d001f705b1dba46a620f7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page