Sign inSign up

vanrienen/backup

By vanrienen

•Updated almost 8 years ago

This image is used as a sidecard container backup persistant data folders of an application.

Image
0

7.2K

vanrienen/backup repository overview

⁠Backup container for docker-compose application

This image is used as a sidecard container backup persistant data folders of an application.

⁠Functionality
  • when the cron job expression is hit the backup starts
  • uses the docker-compose.yml which spawned the container
  • shuts down every application specified in this docker-compose.yml except for itself
  • uses ssh to create the destination folder on the backup server
  • syncs the folder which contains the docker-compose.yml with rsync
  • newest docker images are pulled if parameter is specified
  • the applications are started
    • if the backup container image on the host is not up to date anymore a further docker container is started on the host to restart the whole stack including the backup container
⁠Prerequisites
  • file structure: all persistant data need to be stored in the same folder, where the docker-compose.yml is stored
    $ tree -AL 1 /opt/docker/jira.xalt.de
    .
    ├── docker-compose.yml
    ├── jira
    └── jira-mysql
    2 directories, 1 file
    
  • docker-compose.yml: contains the parameterized backup container as well as the container that are meant to be backed up
    $ cat /opt/docker/jira.xalt.de/docker-compose.yml
    version: '3'
    services:
      backup:
        image: xalt/backup
        environment:
          - BACKUP_HOST=10.0.0.1
          - BACKUP_SUFFIX=-live
          - CRON_DATE=20 1 * * *
          - DOCKER_COMPOSE_PULL=true
          - TIME_ZONE=Europe/Berlin
        restart: always
        volumes:
          - /home/dummy/.ssh/id_rsa:/tmp/id_rsa:ro
          - /opt/docker:/opt/docker
          - .:/path
          - /var/run/docker.sock:/var/run/docker.sock:rw
          - /var/run/docker:/var/run/docker
      jira-mysql:
        image: xalt/mysql:5.7
        environment:
          - MYSQL_ROOT_PASSWORD=dummy
          - MYSQL_DATABASE=jira
          - MYSQL_USER=jira
          - MYSQL_PASSWORD=dummy
        networks:
          jira:
            aliases:
              - db
        restart: always
        volumes:
          - ./jira-mysql:/var/lib/mysql
      jira:
        image: xalt/jira
        depends_on:
          - jira-mysql
        environment:
          - VIRTUAL_HOST=jira.xalt.de
          - VIRTUAL_PORT=8080
          - RAM_MIN=768M
          - RAM_MAX=4096M
          - JAVA_OPTS=-Dfile.encoding=utf-8 -Dsun.jnu.encoding=UTF-8
          - HTTPS=true
          - PROXY_NAME=jira.xalt.de
        networks:
          jira:
          reverse-proxy:
        restart: always
        volumes:
          - ./jira:/var/atlassian/jira
    networks:
      jira:
      reverse-proxy:
        external: true
    
⁠Parameter
  • BACKUP_HOST
    • default: false
    • mandatory: yes
    • needs to be set for the backup to actually happen
    • specifies the host where the persistant data should be stored (can be either DNS name or IP)
  • BACKUP_KEY_FILE
    • default: /tmp/id_rsa
    • mandatory: yes
    • can be modified if the keyfile is supposed to be mounted to a different location
      volumes:
        - /home/dummy/.ssh/id_rsa:/tmp/id_rsa:ro
      
  • BACKUP_PATH
    • default: /backup/docker-applications
    • mandatory: yes
    • is used together with the BACKUP_SUFFIX to specify the path where the persistant data is stored on the backup server
    • the whole path in this example would look like this: /backup/docker-applications/jira.xalt.de-live
  • BACKUP_USER
    • default: root
    • mandatory: yes
    • user that connects to the backup server via ssh and rsync
    • usually it is the easiest way to use root for this connection since only root can create files and folders with the correct ownership and permission on the destination system
  • BACKUP_SUFFIX
    • default: ""
    • mandatory: no
    • is used together with the BACKUP_PATH to specify the path where the persistant data is stored on the backup server
    • the whole path in this example would look like this: /backup/docker-applications/jira.xalt.de-live
  • CRON_DATE
    • default: "0 0 * * *"
    • mandatory: yes
    • this is the cron expression when this backup should be executed
    • every cron expression⁠ that works for ubuntu:18.04 can be used here
  • DOCKER_COMPOSE_PULL
    • default: false
    • mandatory: no
    • if set to "true" this container also pulls the newest version of the docker image before starting the containers
  • TIME_ZONE
    • default: false
    • mandatory: no
    • here you can specify the time zone of the backup container which makes it easier to maintain the cron jobs
    • the default time zone inside the container is UTC

Tag summary

Content type

Image

Digest

Size

115.8 MB

Last updated

almost 8 years ago

docker pull vanrienen/backup