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.
- 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.
- MySQL
- PostgreSQL
- SQLite
- Local
- SFTP Server
- FTP Server
- Dropbox
- Telegram Bot
- Python 3.8 or higher
- Django 3.2 or higher
-
Install DJ Backup
pip install djbackup
To include all optional features (databases and storages):
pip install djbackup[all]
-
Add
dj_backuptoINSTALLED_APPS# settings.py INSTALLED_APPS = [ # Other apps 'dj_backup', ]
-
Configure Static Files
# settings.py from dj_backup.core.utils.static import load_static STATICFILES_DIRS = [ # Other static directories load_static(), ]
-
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')), ]
-
Set Up Basic Configuration
# settings.py DJ_BACKUP_CONFIG = { 'STORAGES': { 'LOCAL': { 'OUT': BASE_DIR / 'backup/result' }, } }
-
Run Migrate and Collect Static Files
# cmd python manage.py migrate python manage.py collectstatic -
Execute Backup
# cmd python manage.py run-backup -
Start the Django Server
# cmd python manage.py runserverNote: For production, use a WSGI/ASGI server like Gunicorn or uWSGI instead of
runserver.
Navigate to:
http://127.0.0.1:8000/dj-backup/
Or your custom domain:
http://your-domain:port/dj-backup/
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/'
}
}
}Install specific dependencies for your needs:
| 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] |
| Database | Install Command |
|---|---|
| MySQL | pip install djbackup[mysql] |
| PostgreSQL | pip install djbackup[postgresql] |
- Remove unused storage configurations to prevent connection errors.
- Specify
POSTGRESQL_DUMP_PATHorMYSQL_DUMP_PATHif 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.
We welcome contributions! Please read our Contributing Guidelines for details on how to submit pull requests, report bugs, or suggest features.
DJ Backup is licensed under the MIT License.
For bugs, feature requests, or questions, please open an issue on GitHub Issues.
⭐ Star this project on GitHub to support its development! ⭐
