Skip to main content

django-project-backup

Django project backup application.

(This is alpha software and is under heavy development)

Setup

Add the following lines to settings.py

# django
INSTALLED_APPS += [
    'django_project_backup'
]

# django-project-backup
SERIALIZATION_MODULES = {
    'dpb_couchdb_datastore': 'django_project_backup.utils.couchdb.serializers'
}

DJANGO_PROJECT_BACKUP_MODE = env('DJANGO_PROJECT_BACKUP_MODE', default='incremental')

DJANGO_PROJECT_BACKUP_PROJECT_NAME = env('DJANGO_PROJECT_BACKUP_PROJECT_NAME', default='django_project_backup')
DJANGO_PROJECT_BACKUP_SHARD_NAME = env('DJANGO_PROJECT_BACKUP_SHARD_NAME', default='1')

# realtime
DJANGO_PROJECT_BACKUP_REALTIME = env.bool('DJANGO_PROJECT_BACKUP_REALTIME', default=True)
DJANGO_PROJECT_BACKUP_DO_REALTIME_COUCHDB_BACKUP = env.bool('DJANGO_PROJECT_BACKUP_DO_REALTIME_COUCHDB_BACKUP',
                                                            default=True)
DJANGO_PROJECT_BACKUP_DO_REALTIME_LOG_BACKUP = env.bool('DJANGO_PROJECT_BACKUP_DO_REALTIME_LOG_BACKUP',
                                                        default=True)

DJANGO_PROJECT_BACKUP_EXCLUDED_MODELS = env.list('DJANGO_PROJECT_BACKUP_EXCLUDED_MODELS', default=[
    'sessions.session',
    'admin.logentry',
    'django_sso_app.passepartout',
    'django_sso_app.device',
    'easy_thumbnails.thumbnail'
])

DJANGO_PROJECT_BACKUP_PUBLIC_ASSETS_FOLDERS = env.list('DJANGO_PROJECT_BACKUP_PUBLIC_ASSETS_FOLDERS',
                                                        default=[str(PUBLIC_ROOT)])

DJANGO_PROJECT_BACKUP_PRIVATE_ASSETS_FOLDERS = env.list('DJANGO_PROJECT_BACKUP_PRIVATE_ASSETS_FOLDERS',
                                                        default=[str(PRIVATE_ROOT)])

DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER = env('DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER',
                                               default=os.path.join(ROOT_DIR, 'backups'))

DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_URL = env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_URL', default='http://127.0.0.1:5984')
DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_USER = env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_USER', default='admin')
DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_PASSWORD = env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_PASSWORD', default='couchdb')
# couchdb db index
DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_DATABASE_NAME = env('DJANGO_PROJECT_BACKUP_COUCHDB_DATASTORE_DATABASE_NAME',
                                                            default='django_project_backup')

DJANGO_PROJECT_BACKUP_DO_FAILSAFE_BACKUP = env.bool('DJANGO_PROJECT_BACKUP_DO_FAILSAFE_BACKUP',
                                                    default=True)
DJANGO_PROJECT_BACKUP_FAILSAFE_BACKUP_PATH = env('DJANGO_PROJECT_BACKUP_FAILSAFE_BACKUP_PATH',
                                                 default=os.path.join(DJANGO_PROJECT_BACKUP_DESTINATION_FOLDER, 'failed'))

# log realtime
LOGGING = {
    ...

    "formatters": {
        "dpb_serialized_model": {
            "format": "%(message)s"
        }
    },
    'handlers': {
        "dpb_realtime_log_backup_file": {
            "level": "INFO",
            "class": "logging.handlers.RotatingFileHandler",
            "filename": os.path.join(ROOT_DIR, "logs", "django_project_backup.realtime.log"),
            "maxBytes": 1024 * 1024 * 4000,  # 4GB
            "backupCount": 10,
            "formatter": "dpb_serialized_model",
        },
    },
    'loggers': {
        ...

        'django_project_backup.backup_logger': {
            'handlers': ['dpb_realtime_log_backup_file'],
            'level': 'INFO',
            'propagate': False,
        },
    },
}

# django-filer
# store files as payload
FILER_DUMP_PAYLOAD = True

Usage

Filesystem

  • Backup DB

    $ python manage.py dpb_filesystem_dumpdata
    
  • Backup assets

    $ python manage.py dpb_filesystem_assets_backup
    

Couchdb

  • Backup all

    $ python manage.py dpb_couchdb_dumpdata
    
  • Restore all

    $ python manage.py dpb_couchdb_loaddata
    

Sandbox

Docker

Dependencies

Installation

Run the following commands:

git clone https://bitbucket.org/pai/django-project-backup.git
cd django-project-backup
# build containers
docker-compose up --build -d
# start containers
docker-compose up
# load initial data
docker-compose run app /venv/bin/python manage.py load_initial_data
# perform first backup
docker-compose run app /venv/bin/python manage.py dbp_couchdb_dumpdata

The demo site will now be accessible at http://localhost:8000/ and the django admin interface at http://localhost:8000/admin/.

Log into the admin with the credentials admin / admin.

Important: This docker-compose.yml is configured for local testing only, and is not intended for production use.

Debugging

To tail the logs from the Docker containers in realtime, run:

docker-compose logs -f

Setup with Virtualenv

You can run the demo locally without setting up Docker and simply use Virtualenv, which is the recommended installation approach for Django itself.

Dependencies

Installation

With PIP and virtualenvwrapper installed, run:

mkvirtualenv django_project_backup
python --version

Confirm that this is showing a compatible version of Python 3.x. If not, and you have multiple versions of Python installed on your system, you may need to specify the appropriate version when creating the virtualenv:

deactivate
rmvirtualenv django_project_backup
mkvirtualenv django_project_backup --python=python3.7
python --version

Now we're ready to set up the sandbox demo project itself:

cd ~/dev [or your preferred dev directory]
git clone https://bitbucket.org/pai/django-project-backup.git
cd django_project_backup/
pip install -r requirements/base.txt

Next, we'll set up our local environment variables. We use django-dotenv to help with this. It reads environment variables located in a file name .env in the top level directory of the project. The only variable we need to start is DJANGO_SETTINGS_MODULE:

$ cp backend/settings/local.py.example backend/settings/local.py
$ echo "DJANGO_SETTINGS_MODULE=backend.settings.local" > .env

To set up your database and load initial data, run the following commands:

./manage.py migrate
./manage.py load_initial_data
./manage.py runserver

Log into the admin with the credentials admin / admin.

Known issues

Since django-project-backup relies on natural primary keys when in realtime mode if one of those fields is updated there is no efficient way to update related objects keys.

Note

This project has been set up using PyScaffold 3.2.3. For details and usage information on PyScaffold see https://pyscaffold.org/.

Metadata

Release files for django-project-backup 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-project-backup 0.1.8
File Size Uploaded Provenance Actions
django-project-backup-0.1.8.tar.gz 33.8 kB Without provenance Details for django-project-backup-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-project-backup 0.1.8
File Interpreter ABI Platform Actions
django_project_backup-0.1.8-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_project_backup-0.1.8-py2.py3-none-any.whl

Total release size: 52.6 kB

Release files / django-project-backup-0.1.8.tar.gz

Download URL django-project-backup-0.1.8.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3c72787ccee3ca3be72c824ad78f5d3c62d09737e45848c1cd88dacdf74a4f1f
BLAKE2b-256 checksum
How to use checksums
73fcd4fe975d24f4624559b926e4eeb598de51abf1e0a9c4deb3dcfa8afd0283
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3

Release files / django_project_backup-0.1.8-py2.py3-none-any.whl

Download URL django_project_backup-0.1.8-py2.py3-none-any.whl
Size 18.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fd9eda369d933ee2b7c6feb9733e8e5eac26b255bd5fe542924c5fe326b5dc77
BLAKE2b-256 checksum
How to use checksums
c7d0246658b4bc289f1bf72459e3cbbfde201e3e816bbea24c473a8ae593e7d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.3

Security for django-project-backup 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page