Skip to main content

djbackup(django backup) is an installable module for Django that is used for backup purposes, specifically for backing up the database and media files.

Project description

dj_backup

DJ Backup Logo

What is this ?

DJ Backup is a Django app that provides the capability to back up your files and databases.

PyPI version Python Django Documentation License Code Style Coverage

Overview

DJ Backup is a powerful and flexible Django application designed to automate and manage backups for your project files and databases. With support for multiple storage providers and databases, it’s an essential tool for developers and system administrators looking to ensure data safety.

Links

Key Features

  • Multiple Database Support: Backup MySQL, PostgreSQL, and SQLite databases effortlessly.
  • Flexible Storage Options: Store backups locally or on remote services like SFTP, FTP, Dropbox, or Telegram Bot.
  • Web Dashboard: Intuitive interface to manage and monitor backup tasks.
  • Highly Configurable: Customize backup directories, storage locations, and logging levels.
  • Lightweight & Modular: Install only the dependencies you need for your setup.
  • Open Source: Licensed under MIT, with a welcoming community for contributions.

Supported Databases

  • MySQL
  • PostgreSQL
  • SQLite

Supported Storage Providers

  • Local
  • SFTP Server
  • FTP Server
  • Dropbox
  • Telegram Bot

Installation

Prerequisites

  • Python 3.8 or higher
  • Django 3.2 or higher

How to use?(Step-by-Step Guide)

  1. Install DJ Backup

    pip install djbackup
    

    To include all optional features (databases and storages):

    pip install djbackup[all]
    
  2. Add dj_backup to INSTALLED_APPS

    # settings.py
    
    INSTALLED_APPS = [
        # Other apps
        'dj_backup',
    ]
    
  3. Configure Static Files

    # settings.py
    
    from dj_backup.core.utils.static import load_static
    
    STATICFILES_DIRS = [
        # Other static directories
        load_static(),
    ]
    
  4. Add DJ Backup URLs

    # urls.py
    
    from django.urls import include, path
    
    urlpatterns = [
        # Other URLs
        path('dj-backup/', include('dj_backup.urls', namespace='dj_backup')),
    ]
    
  5. Set Up Basic Configuration

    # settings.py
    
    DJ_BACKUP_CONFIG = {
        'STORAGES': {
            'LOCAL': {
                'OUT': BASE_DIR / 'backup/result'
            },
        }
    }
    
  6. Run Migrate and Collect Static Files

    # cmd
    python manage.py migrate
    python manage.py collectstatic
    
  7. Execute Backup

    # cmd
    python manage.py run-backup
    
  8. Start the Django Server

    # cmd
    python manage.py runserver
    

    Note: For production, use a WSGI/ASGI server like Gunicorn or uWSGI instead of runserver.

Access the Dashboard

Navigate to:

http://127.0.0.1:8000/dj-backup/

Or your custom domain:

http://your-domain:port/dj-backup/

Advanced Configuration

A complete example of DJ_BACKUP_CONFIG:

# settings.py

DJ_BACKUP_CONFIG = {
    'MAX_WORKERS': 5,  # Maximum concurrent backup tasks
    'NOTIFICATION_OBJECT_LOG_LEVEL': 'WARNING',  # Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL
    'POSTGRESQL_DUMP_PATH': None,  # Path to PostgreSQL dump executable (if needed)
    'MYSQL_DUMP_PATH': None,  # Path to MySQL dump executable (if needed)
    # External databases(Optional)
    'EXTERNAL_DATABASES': {
        'default2': {
            'ENGINE': 'postgresql',
            'NAME': 'test_db',
            'USER': 'postgres',
            'PASSWORD': 'your_password',
            'HOST': '127.0.0.1',
        },
        'default3': {
            'ENGINE': 'mysql',
            'NAME': 'test_db',
            'USER': 'root',
            'PASSWORD': 'your_password',
            'HOST': '127.0.0.1',
        },
    },
    'BASE_ROOT_DIRS': [BASE_DIR],  # Directories to include in backups
    'BACKUP_TEMP_DIR': BASE_DIR / 'backup/temp',  # Temporary backup storage
    'BACKUP_SYS_DIR': BASE_DIR / 'backup/sys',  # System backup storage
    'STORAGES': {
        'LOCAL': {
            'OUT': BASE_DIR / 'backup/result'
        },
        'TELEGRAM_BOT': {
            'BOT_TOKEN': 'your_bot_token',
            'CHAT_ID': 'your_chat_id'
        },
        'SFTP_SERVER': {
            'HOST': 'sftp.example.com',
            'USERNAME': 'your_username',
            'PASSWORD': 'your_password',
            'OUT': 'backups'
        },
        'FTP_SERVER': {
            'HOST': 'ftp.example.com',
            'USERNAME': 'your_username',
            'PASSWORD': 'your_password',
            'OUT': 'backups'
        },
        'DROPBOX': {
            'APP_KEY': 'your_app_key',
            'OUT': '/dj_backup/'
        }
    }
}

Additional Dependencies

Install specific dependencies for your needs:

Storage Providers

Provider Install Command
Telegram Bot pip install djbackup[telegram]
SFTP Server pip install djbackup[sftpserver]
FTP Server pip install djbackup[ftpserver]
Dropbox pip install djbackup[dropbox]

Databases

Database Install Command
MySQL pip install djbackup[mysql]
PostgreSQL pip install djbackup[postgresql]

Notes

  • Remove unused storage configurations to prevent connection errors.
  • Specify POSTGRESQL_DUMP_PATH or MYSQL_DUMP_PATH if the default dump executables are not found.
  • Regularly update dependencies and check the documentation for new features.
  • For secure backups, consider encrypting sensitive data before uploading to remote storage.

Contributing

We welcome contributions! Please read our Contributing Guidelines for details on how to submit pull requests, report bugs, or suggest features.

License

DJ Backup is licensed under the MIT License.

Contact

For bugs, feature requests, or questions, please open an issue on GitHub Issues.


Star this project on GitHub to support its development!

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

djbackup-2.3.2.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djbackup-2.3.2-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

Details for the file djbackup-2.3.2.tar.gz.

File metadata

  • Download URL: djbackup-2.3.2.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for djbackup-2.3.2.tar.gz
Algorithm Hash digest
SHA256 1efdadb803de5302a0b8f5770c832396d6fce7f1c6c9e0c8946f1de775e78fec
MD5 bbfc97035fc22ed7cced241773817ee9
BLAKE2b-256 bb2994e92d649fd6f4f0a6f6d29b4ae52d73842dd4ac5ab73b32320b7ff4154e

See more details on using hashes here.

File details

Details for the file djbackup-2.3.2-py3-none-any.whl.

File metadata

  • Download URL: djbackup-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for djbackup-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c60ab9867ce803d17cb025266f1fe7744b22d8c3c774fa3bef26d8811592c50
MD5 ed26da13a181e3ee2f2e7ee94d30176b
BLAKE2b-256 2999bf4d5aa99239a2d73535d019ec67c889e04dfb4f22bcb6a0f880b019a6f8

See more details on using hashes here.

Supported by

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