Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This Docker image provides a backup service to backup a PostgreSQL or MySQL database of a docker volume. The service can be added into a docker stack with an PSQL or MySQL instance to backup the database periodically. The service also backups optional files from a mounted docker volume.

All backup files are organized in a backup directory and can optional be transfered into a backup space. The service is designed to backup only one database. In case you want to use this service to backup a complete PSQL or MySQL server, than you should use the command "pg_dumpall" instead of "pg_dump". See the script for details.


  • backup PostgreSQL or MySQL database
  • backup file content from a docker volume
  • sftp/scp support to move backups to an external backup space
  • chron job
  • restore feature.


The imixs/backup image is based on the official postgres image with additional mysql-client support.

imixs/backup provides the following environment variables which need to be set during container startup:

  • SETUP_CRON - the cron timer setting (e.g. "0 3 * * *")
  • BACKUP_SERVICE_NAME - name of the backup service (defines the target folder on FTP space)
  • BACKUP_DB_HOST - datbase server
  • BACKUP_DB_USER - database user
  • BACKUP_DB_PASSWORD - database user password
  • BACKUP_DB - the postgres or mysql database name
  • BACKUP_VOLUME - optional file directory from a mapped docker volume
  • BACKUP_SPACE_HOST - backup space connected via SFTP/SCP
  • BACKUP_SPACE_USER - backup space user
  • BACKUP_LOCAL_ROLLING - number of backup files to be kept locally
  • BACKUP_SPACE_ROLLING - number of backup files to be kept in the backup space

All backups are located in the following local directory


In the backup space, the files are located at:


Each backup file has a time stamp prefix indicating the backup time:



Based on the cron settings provided in the environment variable "BACKUP_CRON" the backup_init script starts a cron job to schedule the script.


 # Run every day at 03:00
 0 3 * * *   

See details here.


All backup scripts are located in the root home directory (/root/).

  • - initializes the backup service via cron
  • - the backup script
  • - the restore script
  • - to get a file form the remote backup space

The scripts can be called manually:

$ docker exec -it 2f4b2feaa412 /root/

Rolling Backup Files

The backup script automatically holds a number of backup files locally. The default number of files to keep is set to 5. You can change this parameter with the environment variable "BACKUP_LOCAL_ROLLING".

The Backup Space

In case the optional environment variable "BACKUP_SPACE_HOST" is provided, the service will push backup files automatically into a backup space via SFTP/SCP. The backup directory on the backup space is


The optional environment variable "BACKUP_SERVICE_NAME" can be set to name the backup directory on the backup space. If no service name is set, the docker container ID will be used instead.

Create a SSH Key

To transfers files to the backup space this service uses SFTP/SCP. For this reason a RFC4716 Public Key need to be provided on the backup space.

The backup service expects that a private key file is provided by a docker secret. Docker secrets can be used only in docker swarm. So in this case you are forced to run the backup service in a docker swarm.

To copy a ssh key provided in the file /root/.ssh/backupspace_rsa into a docker secret run:

docker secret create backupspace_key /root/.ssh/backupspace_rsa

You can add the key as an environment variable to the stack definition:

version: '3.1'

    image: imixs/backup:latest
     BACKUP_SPACE_KEY_FILE: "/run/secrets/backupspace_key"
     - backupspace_key
     external: true

How to Deploy the Service

The imixs/backup service is supposed to be run as part of a docker service stack. This means that the service is included in a docker-compose.yml file which already contains PQSL or MYSQL Database Server and optional a mounted volume. The database service is typically bound using an internal network.

The following example shows a service definition of the backup service to backup a Wordpress Service with a MySQL database and a volume named 'wp-content' containing the wordpress content.

    image: imixs/backup:1.2.1
      SETUP_CRON: "0 4 * * *"
      BACKUP_SERVICE_NAME: "my-service"
      BACKUP_DB_USER: "wordpress_dms"
      BACKUP_DB_PASSWORD: "xxxxxxxxxxx"
      BACKUP_DB_HOST: "db"
      BACKUP_DB: "wordpress"
      BACKUP_VOLUME: "/var/www/html/wp-content"
      - wp-content:/var/www/html/wp-content
      - backend
      - wp-content:/var/www/html/wp-content

If you add a backup space the following optional environment settings are needed:

      BACKUP_SERVICE_NAME: "my-app"
      BACKUP_SPACE_USER: "yyyy"
      BACKUP_SPACE_KEY_FILE: "/run/secrets/backupspace_key"

If you want to backup file directories form a mounted volume:

      BACKUP_VOLUME: "/home/imixs" 
     - appdata:/home/imixs

Manual Backup

A backup can be started manually by the backup script. The backup script can be run either from outside the container:

$ docker exec -it 82526abbabfe /root/

(You need to replace the container ID with the id of your backup service.)

or you can first log into the backup container with:

$ docker exec -it 82526abbabfe bash

(You need to replace the container ID with the id of your backup service.)

and than start the backup script directly:

root@82526abbabfe:/# /root/

To list all locally available backups run:

ls -la /root/backups


The Backup Service provides scripts to restore and load backup files. All scripts can be started either from outside the container:

docker exec -it 82526abbabfe [SCRIPT]

(You need to replace the container ID with the id of your backup service.)

or you can first log into the backup container with:

docker exec -it 82526abbabfe bash

(You need to replace the container ID with the id of your backup service.)

and than start the scripts directly.

Restore Local Backup Files:

All backup files are stored in the folder /root/backups/. The files include a time stamp in ISO format indicating the backup time.

To list all locally available backups run:

ls -la /root/backups

To restore the latest backup run:


To restore a specific backup run the script followed by the timestamp of the backupfile:

/root/ 2018-01-05_03:00

Restore Remote Backup Files:

In case you have no local backup files available, you can pull a backup file first from the backup space.

Run the following command to get a list of all backup files available on the backupspace:


You can pull a specific backup file with the script followed by the filename:


The remote backupfile will be written to the directory /root/backups/. Now you can restore the backup as explained before.


The source is available on Github. Please report any issues.

To build the image from the Dockerfile run:

docker build --tag=imixs/backup .