It's a general purpose to solve backup matter on Rancher. The goal, it's to have ability to use docker command to perform dump (when needed) before to start external backup with duplicity.
To do the job in easiest way, we use the power of Rancher API to discover the service witch must be dumped before to start the backup.
We use some settings files on /app/config
to explain how discover the service witch must be dumped and how to do that.
Next, all the contains of BACKUP_PATH
(default is /backup) is backuped on remote backend with duplicity. So you can map your data volume on this container to backup it in the same time.
You are welcome to contribute on github to extend the supported service.
No extra need, use dump tools utilities to do remote dump.
MySQL
: the docker image must havemysql
on name. Usemysqldump
to perform the dump.MariaDB
: the docker image must havemariadb
on name. Usemysqldump
to perform the dump.PostgreSQL
: the docker image must havepostgres
on name. Usepgdump
to perform the dump.MongoDB
: the docker image must havemongo
on name. Usemongodump
to perform the dump.Elasticsearch
: the docker image must haveelasticsearch
on name. Useelasticdump
to perform the dump.
Need to have shared volume (like glusterfs, S3, Ceph, etc.) between each database nodes and the backup service. To to dump, we use tools utilities to ask each nodes perform a local dump (on shared volume) and we mount this shared volume on backup service to perform the remote backup.
For example, if you have 3 Cassandra nodes on 3 hosts, you must to have sharded storage on each hosts (/mnt/cassandra
) witch is mounted on each nodes (/dump
).
Then, you need to mount the shared storage on backup service (/mnt/cassandra:/backup/cassandra
).
When we detect Cassandra service, we send command to Cassandra to ask it to perform a dump of each nodes on /dump
, ans next we perform a backup with duplicity of /backup
folder.
If you should to not dump a particular service witch is supported, you can add label on service backup.disable=true
The following options permit to set the backup policy :
CRON_SCHEDULE
: when you should start backup (incremental if full is not needed). For example, to start backup each day set0 0 0 * * *
BACKEND
: this is the target URL to externalize the backup. For example, to use FTP as external backup setftp://[email protected]
and add environment variableFTP_PASSWORD
. For Amazon S3, sets3://host[:port]/bucket_name[/prefix]
. Read the ducplicity man for all supported backend. There are no default value.TARGET_PATH
: The path were store backup on local and remote. The default value is/backup
.BK_FULL_FREQ
: The frequency when you should make a full backup. For example, if you should make a full backup each 7 days, set7D
. The default value is7D
.BK_KEEP_FULL
: How many full backup you should to keep. For example, to keep 3 full backup set3
. The default value is3
.BK_KEEP_FULL_CHAIN
: The number of intermediate incremental backup you should keep with the full backup. For example, if you should keep only the incremental backend after the last full backup set1
. The default value is set to1
.VOLUME_SIZE
: The volume size to store the backup (in MB). The default value is25
.
To set the Rancher API connection prefer to add special label that generate access on the flow:
io.rancher.container.create_agent=true
io.rancher.container.agent.role=environment
Or you can define them manually :
CATTLE_URL
: the API URL with your project IDCATTLE_ACCESS_KEY
: the API keyCATTLE_SECRET_KEY
: the API secret key
You need to dump another service before to save it (note yet supported) ? Just clone this repository and add the file in backup/config/new-service.yml
Then, add your new entry (sample with MySQL):
mysql:
regex: "mysql"
image: "mysql:latest"
commands:
- "mysqldump -h %ip% -u %env_MYSQL_USER% %env_MYSQL_DATABASE% > %target_dir%/%env_MYSQL_DATABASE%.dump"
environment:
- MYSQL_PWD:%env_MYSQL_PASSWORD%
Few explanation:
regex
: It's the regex to discover service witch must be dumped. This regex is applied to image docker used in service.image
: It's the docker image to use to run the dump (generaly the latest tag). If you not add image entry, it use the service docker image.commands
: It's the list of commands to launch on container to perform the dumpenvironment
: It's the list of environment variables you need to perform the dump
There are few macro you can use in command and in environment section:
%ip%
: the IP to join the container to perform a remote dump%env_SERVICE_ENV%
: Take the value of service environment calledSERVICE_ENV
%target_dir%
: It's the path where store the dump (BACKUP_PATH/STACK_NAME/SERVICE_NAME
)