Restore backup with Docker

This quick tutorial shows how to quickly restore a Simplicité Backup. It shows an example with a PostgreSQL database and a dbdoc on a CentOS 7 instance.

Pre-requisites

  • Docker Registry Access
  • Simplicité backup (database.dump + dbdoc)
  • VM

Setting up an instance

Follow this tutorial but with the bellow docker-compose file, adapted to your SGBD

DO NOT START THE APP CONTAINER IN THE PROCESS

https://docs.simplicite.io/documentation/90-operation/docker-tutorial.md

See resulting shell commands as of today (following above tutorial is better)
sudo yum update -y && sudo yum clean all
sudo reboot
sudo yum install -y firewalld && sudo yum clean all
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
sudo yum install -y docker && sudo yum clean all
sudo systemctl enable docker
sudo systemctl start docker
sudo docker login
sudo yum install -y epel-release && sudo yum install -y docker-compose && sudo yum clean all

Create a docker-compose.yml similar to the ones in the above tutorial, but adding volumes for the database backup (app-db-backup) and the dbdoc (app-dbdoc). In case the app you backup is “Blob only”, you won’t need the dbdoc volume.

See docker-compose.yml
version: "3"
services:
  db:
    image: postgres:9.6
    restart: always
    container_name: db
    environment:
      POSTGRES_USER: "simplicite"
      POSTGRES_PASSWORD: "simplicite"
      POSTGRES_DB: "simplicite"
    volumes:
      - app-db-data:/var/lib/postgresql/data
      - app-db-backup:/var/lib/backup
  simplicite:
    image: simplicite/platform:5.0
    restart: always
    container_name: app
    environment:
      DB_SETUP: "true"
      DB_VENDOR: "postgresql"
      DB_HOST: db
      DB_USER: "simplicite"
      DB_PASSWORD: "simplicite"
      DB_NAME: "simplicite"
      DB_WAIT: 10
    ports:
      - 80:8080
    volumes:
      - app-git:/usr/local/tomcat/webapps/ROOT/WEB-INF/git
      - app-dbdoc:/usr/local/tomcat/webapps/ROOT/WEB-INF/dbdoc
    depends_on:
      - db
volumes:
  app-db-data:
  app-db-backup:
  app-git:
  app-dbdoc:

After this, you should have you backup and docker-compose files ready to use:

[centos@backupvm ~]$ find . -maxdepth 2 -not -path '*/.*'
.
./docker-compose.yml
./backup
./backup/dbdoc
./backup/database.dump
[centos@backupvm ~]$

Preparing containers with backed up data

Create containers and volumes, without starting them to avoid initiating database

sudo docker-compose up --no-start

Check volumes list and write down prefixed volume names for app-db-backup and app-dbdoc

sudo docker volume list

Cleanly copy data to volumes

sudo docker run -v centos_app-db-backup:/data --name helper busybox true
sudo docker cp backup/database.dump helper:/data/
sudo docker rm helper
sudo docker run -v centos_app-dbdoc:/data --name helper busybox true
sudo docker cp backup/dbdoc/. helper:/data/
sudo docker rm helper

Start database only and import dump

sudo docker-compose up -d db
sudo docker ps
sudo docker exec -it db bash
> psql -U simplicite simplicite < /var/lib/backup/database.dump

Start app

sudo docker-compose up -d
2 Likes