#!/bin/bash # This script performs a backup of key data in the Docker Compose Alfresco # environment that is started using the companion `docker-compose.yml` # file. It backs up the binary data and database. It ignores the search # engine and MQ server. This is not proper for a production environment. # Notice that we are not compressing any of this backup. We are counting on # Git's ability to only deal with differences to get far better effective # compression over of the data as it is verioned. Git also compresses these # files in transit and in storage anyway. By not putting them in ZIP files, we # use just as little disk space with one commit and probably 90% smaller over # 10 commits and 99% smaller over 100 commits. prepare() { echo "Preparing for the backup ..." export THISDIR=`dirname "$(readlink -f "$0")"` export DOCKER_COMPOSE_DIR=$THISDIR export DATA_DIR=$DOCKER_COMPOSE_DIR/data source "$THISDIR/common.sh" echo "Clearing previous backup (if one exists) ..." sudo rm -rf "$DATA_DIR" mkdir -p "$DATA_DIR" } backup() { echo "Performing a backup ..." } backup_database() { CONTAINER_ID=$1 SQL_SCHEMA_FILENAME=$2 SQL_DATA_FILENAME=$3 DB_NAME=$4 DB_USERNAME=$5 DB_DISPLAY=$6 echo "Backing up the $DB_DISPLAY database ..." echo "Dumping $DB_DISPLAY database schema ..." docker container exec $CONTAINER_ID pg_dump -U $DB_USERNAME -s -f /tmp/$SQL_SCHEMA_FILENAME $DB_NAME echo "Dumping $DB_DISPLAY database data ..." docker container exec $CONTAINER_ID pg_dump -U $DB_USERNAME -a -f /tmp/$SQL_DATA_FILENAME $DB_NAME echo "Copying $DB_DISPLAY database schema from Docker container ..." docker cp $CONTAINER_ID:/tmp/$SQL_SCHEMA_FILENAME "${DOCKER_COMPOSE_DIR}/data" echo "Copying $DB_DISPLAY database data from Docker container ..." docker cp $CONTAINER_ID:/tmp/$SQL_DATA_FILENAME "${DOCKER_COMPOSE_DIR}/data" } backup_binaryData() { CONTAINER_ID=$1 DATA_DIRECTORY=$2 CONTAINER_PATH=$3 DISPLAY=$4 echo "Backing up the $DISPLAY binary data ..." echo "Copying $DISPLAY binary data ..." docker cp -a "$CONTAINER_ID:$CONTAINER_PATH/$DATA_DIRECTORY" "${DOCKER_COMPOSE_DIR}/data" } prepare backup