Nards DB Backup is a database backup system configurable via Docker. It supports automated backups and the automatic restoration of the last backup on startup (if configured), ensuring that the database is always aligned with the most recent backups. This project is ideal for users who use databases via Docker Compose or Kubernetes and are looking for a solution to automate backups.
A Flask application that schedules and manages database backups using cron jobs. It supports both MySQL and PostGIS databases and can restore backups via command-line arguments.
Configure the application via environment variables. Create a .env
file with the following variables:
DB_HOST=localhost
DB_PORT=5432
DB_USER=user
DB_PASSWORD=password
DB_MAINTENANCE_NAME=mydb
DB_TYPE=mysql
or postgis
CRON_CONFIGS='[{"cron": "0 0 * * *", "retention_max": 90, "name": "default"}]'
RESTORE_CONFIG_NAME=""
retention_max
will default to 90 and name
will default to "default".Example of CRON_CONFIGS:
[{"cron": "0 0 * * *", "retention_max": 90, "name": "default"}]
: creates a backup every day a midnight and keep for 90 days[{"cron": "0 * * * *", "retention_max": 24, "name": "hourly"}, {"cron": "0 0 * * *", "retention_max": 24, "name": "monthly"}]
: creates a backup every hour and keep for a day in folder named 'hourly', a backup every 1 of the month and keep for 2 years in folder named 'monthly'An example of docker compose is provided into docker-compose.yml file. The same example is provided below:
services:
nards_db_backup:
image: nards/nards-db-backup:latest
build: .
environment:
DB_HOST: 'database'
DB_PORT: '5432' # postgres/postgis: 5432; mysql: 3306
DB_USER: 'user'
DB_PASSWORD: 'password'
DB_MAINTENANCE_NAME: 'mydatabase' # defaults to DB_USER
DB_TYPE: 'postgres' # postgres/postgis/mysql
BACKUP_DIR: /backups
CRON_CONFIGS: '[{"cron": "0 * * * *", "retention_max": 15, "name": "every"},{"cron": "0 * * * *", "retention_max": 1, "name": "hourly"}]'
# RESTORE_CONFIG_NAME: 'hourly' # When you have to restore some content
volumes:
- ./backups:/backups
HealthCheck is automatically included into Docker image and provides an url to verify if backups works correctly:
http://localhost:5000/health
Restore the database from a given configuration name or backup file path:
docker exec <container_name> flask restore <name_or_path>
If a valid name_or_path is provided it restores this file to the database as configured with environment variables, else it tries to restore the latest backup from the backup configuration name provided with RESTORE_CONFIG_NAME
.
If a configuration name is provided, the application will log the chosen backup file for restore.
There are currently no planned activities:
However, we invite the community to suggest new features and improvements! Send us your ideas and help extend the project roadmap!
You could contribute to project as you like.
You could open issue when you want to propose a feature, a fix, report a bug or anythink else!
When you report a bug I ask you to include into Issue:
You're welcome to implement features too:
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
You can also mail me: [giuseppe\@nards.it](mailto:giuseppe@nards.it?subject=[nards-db-backup] Request)
Build the Docker image:
docker build -t flask_backup_app .
Run the Docker container:
docker run -p 5000:5000 --env-file .env flask_backup_app
Install the required Python packages:
pip install -r requirements.txt
Run the application:
python app.py
This project is licensed under the GPL v3. See the LICENSE file for details.