docker-db-dump

Ansible Docker Database Dump

This playbook deploys backups scripts to backup docker container running a mysql or postgres database. It deploys the scripts docker-mysql-dump.sh and docker-postgres-dump.sh, and creates entries in crontab to run the scripts each morning.

How to use

  1. Clone this repo in roles

    cd roles
    git clone https://github.com/sebastian13/ansible-docker-db-dump.git
    
  2. Create a playbook docker-db-dump.yml

    ---
    - name: Docker Databse Dump
      hosts: "{{ hostname | default('docker-db-dump') }}"
      become: true
    
      roles:
        - docker-db-dump
    
  3. Define hosts in the hosts file

    [docker-db-dump]
    v01
    v02
    
  4. Create a file for each host in host_vars

    docker_mysql:
      - name: wordpress.example.com
        path: '/docker/wordpress.example.com'
      - name: joomla.example.com
        path: '/docker/joomla.example.com'
    docker_postgres:
      - name: confluence.example.com
        path: '/docker/confluence.example.com'
    
  5. Run the playbook. Optionally limit the deployment to a single server.

    ansible-playbook docker-db-dump.yml --limit v01
    

Requirements

The docker-compose.yml within the specified path must include a service called mysql or postgres. The environment varaibles must be linked and specified in the file .env.

  • Example docker-compose.yml

    services:
      mysql:
        image: mariadb
        env_file: .env
        
      other:
        image: wordpress
        environment:
          - WORDPRESS_DB_PASSWORD=${MYSQL_ROOT_PASSWORD}
          - WORDPRESS_DB_NAME=${MYSQL_DATABASE}
    
    services:
      postgres:
        image: postgres:9.6
        env_file: .env
    
  • Example .env

    MYSQL_DATABASE=example
    MYSQL_ROOT_PASSWORD=123456
    
    POSTGRES_USER=example
    POSTGRES_DB=example
    POSTGRES_PASSWORD=123456
    
About

Deploy backups scripts to create dumps of docker containers running mysql or postgres

Install
ansible-galaxy install sebastian13/ansible-docker-db-dump
GitHub repository
License
gpl-3.0
Downloads
7