This repo is linked to touch4it Docker Hub - https://hub.docker.com/r/touch4it/rancher-backup/
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 /opt/backup/config to explain how discover the service witch must be dumped and how to do that.
The first time we try to apply regex on label called backup.type, and if not match we try to apply on image name.
Next, all the contains of BACKUP_duplicity_source-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 (use develop branch).
No extra need, use dump tools utilities to do remote dump.
MySQL: the docker image must have mysql on name. Use mysqldump to perform the dump.MariaDB: the docker image must have mariadb on name. Use mysqldump to perform the dump.PostgreSQL: the docker image must have postgres on name. Use pgdump to perform the dump.MongoDB: the docker image must have mongo on name. Use mongodump to perform the dump.Elasticsearch: the docker image must have elasticsearch on name. Use elasticdump 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
First it search on label called backup.type and if doesn't found, it search on image name.
It's mean that if you should backup MySQL database, you need to set label backup.type=mysql or use docker image that contains name mysql.
We use Confd to configure backup options.
Confd settings:
/backupenvThe following options permit to set the backup policy :
0 0 0 * * *. Default is 0 0 0 * * *true.true.true.true or false./backup./.ftp://[email protected] and add environment variable FTP_PASSWORD. For Amazon S3, set s3://host[:port]/bucket_name[/prefix]. Read the ducplicity man for all supported backend. There are no default value.7D. The default value is 7D.3. The default value is 3.1. The default value is set to 1.200.PASSPHRASE environment to allow crypt/decrypt without user interaction. You need to mount your GPG keys on /opt/backup/.gnupg.3306.rancher.rancher.To set the Rancher API connection prefer to add special label that generate access on the flow:
io.rancher.container.create_agent=trueio.rancher.container.agent.role=environmentOr you can define them manually :
You need to dump another service before to save it (note yet supported) ? Just clone this repository and 2 files per service:
backup/index/service.yml: contain the regex to identifiy the new servicebackup/template/service.yml: caontain the instruction about how dump the new service. We use Jinja2 templating.Then, add your new entry (sample with MySQL):
backup/index/mysql.yml
mysql:
regex: "mysql"
template: "mysql.yml"
Few explanation:
backup.type and then to image docker used in service.backup/template/mysql.yml
image: "mysql:latest"
commands:
{% if env.MYSQL_USER and env.MYSQL_DATABASE %}
{# When user, password and database setted #}
- "sh -c 'mysqldump -h {{ ip }} -u {{ env.MYSQL_USER }} {{env.MYSQL_DATABASE}} > {{ target_dir }}/{{ env.MYSQL_DATABASE }}.dump'"
{% elif env.MYSQL_USER and not env.MYSQL_DATABASE %}
{# When user, password setted #}
- "sh -c 'mysqldump -h {{ ip }} -u {{ env.MYSQL_USER }} --all-databases > {{ target_dir }}/all-databases.dump'"
{% elif not env.MYSQL_USER and env.MYSQL_DATABASE %}
{# When database setted #}
- "sh -c 'mysqldump -h {{ ip }} -u root {{env.MYSQL_DATABASE}} > {{ target_dir }}/{{ env.MYSQL_DATABASE }}.dump'"
{% elif not env.MYSQL_USER and not env.MYSQL_DATABASE %}
{# When just root setted #}
- "sh -c 'mysqldump -h {{ ip }} -u root --all-databases > {{ target_dir }}/all-databases.dump'"
{% endif %}
environments:
{% if env.MYSQL_PASSWORD %}
- MYSQL_PWD:{{ env.MYSQL_PASSWORD }}
{% elif env.MYSQL_ROOT_PASSWORD %}
- MYSQL_PWD:{{ env.MYSQL_ROOT_PASSWORD }}
{% endif %}
Few explanation:
We use Jinja2 templating and we add some variable that you can use in template:
{{ip}}: the IP to join the container to perform a remote dump{{env.SERVICE_ENV}}: Take the value of service environment called SERVICE_ENV{{target_dir}}: It's the path where store the dump (BACKUP_PATH/dump/STACK_NAME/SERVICE_NAME)Your PR are welcome, but please use develop branch and not master.
Content type
Image
Digest
Size
109.1 MB
Last updated
about 8 years ago
docker pull touch4it/rancher-backup