nards-it / nards-db-backup

Docker utility for database backup
https://hub.docker.com/r/nards/nards-db-backup
GNU General Public License v3.0
0 stars 0 forks source link

Docker Image Version (latest semver) Docker Image Size (latest semver) Docker Pulls Docker Stars GitHub Repo forks GitHub Repo stars

GitHub Workflow Status GitHub Workflow Status GitHub issues GitHub pull requests GitHub commits since latest release (by SemVer) GitHub Licence

Nards DB Backup

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.

Flask Backup Application

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.

Features

Configuration

Configure the application via environment variables. Create a .env file with the following variables:

CRON_CONFIGS

Example of CRON_CONFIGS:

Usage

Docker compose

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

Health Check

HealthCheck is automatically included into Docker image and provides an url to verify if backups works correctly:

http://localhost:5000/health

Restore Database

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.

Roadmap

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!

Contributing

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:

  1. What is the bug you found
  2. When your bug appears
  3. How to build a replicable test case

You're welcome to implement features too:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

You can also mail me: [giuseppe\@nards.it](mailto:giuseppe@nards.it?subject=[nards-db-backup] Request)

Development

Requirements

Build using Docker

  1. Build the Docker image:

    docker build -t flask_backup_app .

  2. Run the Docker container:

    docker run -p 5000:5000 --env-file .env flask_backup_app

Build without Docker

  1. Install the required Python packages:

    pip install -r requirements.txt

  2. Run the application:

    python app.py

License

This project is licensed under the GPL v3. See the LICENSE file for details.