diff --git a/README.rst b/README.rst index f87a7a1e..adf51769 100644 --- a/README.rst +++ b/README.rst @@ -148,16 +148,26 @@ The backups are `mongorestore `__ and `scripts/docker-persistent.example.conf `__ as an example/demo of how to implement persistence. +To persist logs, configs and backup data 3 directories should be mapped to be inside the Docker containter. + +The 'docker run' command -v/--volume flags in the examples below map container paths to paths on your Docker host. The example below assumes there is a path on the Docker host named *'/data/mongobackup'* with *'data'*, *'conf'* and *'logs'* subdirectories mapped to inside the container. Replace any instance of *'/data/mongobackup'* below to a different path if necessary. + +*Note: store a copy of your mongodb-consistent-backup.conf in the 'conf' directory and pass it's container path as the --config= flag if you wish to use config files.* **Via Docker Hub** :: - $ docker run -i timvaillancourt/mongodb_consistent_backup + $ mkdir -p /data/mongobackup/{conf,data,logs} + $ cp -f /path/to/mongodb-consistent-backup.conf /data/mongobackup/conf + $ docker run -it \ + -v "/data/mongobackup/conf:/conf:Z" \ + -v "/data/mongobackup/data:/var/lib/mongodb-consistent-backup:Z" \ + -v "/data/mongobackup/logs:/var/log/mongodb-consistent-backup:Z" \ + timvaillancourt/mongodb_consistent_backup:latest --config=/conf/mongodb-consistent-backup.conf **Build and Run Docker Image** @@ -165,8 +175,13 @@ Note: you need to use persistent volumes to store backups and/or config files lo $ cd /path/to/mongodb_consistent_backup $ make docker - $ docker run -t mongodb_consistent_backup - + $ mkdir -p /data/mongobackup/{conf,data,logs} + $ cp -f /path/to/mongodb-consistent-backup.conf /data/mongobackup/conf + $ docker run -it \ + -v "/data/mongobackup/conf:/conf:Z" \ + -v "/data/mongobackup/data:/var/lib/mongodb-consistent-backup:Z" \ + -v "/data/mongobackup/logs:/var/log/mongodb-consistent-backup:Z" \ + mongodb_consistent_backup --config=/conf/mongodb-consistent-backup.conf ZBackup Archiving (Optional) ~~~~~~~ diff --git a/scripts/docker-persistent.example.conf b/scripts/docker-persistent.example.conf deleted file mode 100644 index fc750025..00000000 --- a/scripts/docker-persistent.example.conf +++ /dev/null @@ -1,15 +0,0 @@ -# 'log_dir' and 'backup.location' flags are auto-overriden -# when using with scripts/docker-persistent.sh. No need to -# add them here. -production: - host: mongodb01.example.com - port: 27017 - backup: - method: mongodump - name: default - archive: - method: tar - notify: - method: none - upload: - method: none diff --git a/scripts/docker-persistent.sh b/scripts/docker-persistent.sh deleted file mode 100755 index 8e262f19..00000000 --- a/scripts/docker-persistent.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -# -# Script for running mongodb_consistent_backup under Docker -# with persistent data container for data, config and logs. -# -# See: scripts/docker-persistent.example.conf for an example -# config to pass to this script during backup. 'log_dir' and -# 'backup.location' variables are auto-set by this script. -# -# Run backup: -# $ scripts/docker-persistent.sh backup scripts/docker-persistent.example.conf -# # Loading config file scripts/docker-persistent.example.conf into container -# # Running Docker image: timvaillancourt/mongodb_consistent_backup:latest -# [2017-04-27 11:22:04,255] [INFO] [MainProcess] [Main:init:127] Starting mongodb-consistent-backup version 1.0.0 (git commit: d780ad545b603d3a2f807e1813f1de407e81f1ba) -# ... -# ... -# -# List backups (in persistent Docker volume): -# $ scripts/docker-persistent.sh list -# /mongodb_consistent_backup/data/default/20170427_1122 -# /mongodb_consistent_backup/data/default/20170427_1123 -# -# Get a backup: -# $ scripts/docker-persistent.sh get /mongodb_consistent_backup/data/default/20170427_1122 -# $ ls -ald ./20170427_112 -# drwxr-xr-x. 3 root root 59 Apr 27 13:22 ./20170427_1122 -# - -ACTION=$1 -[ -z $1 ] && echo "Usage: $0 [backup|list|get] [action flags]" && exit 1 - -BACKUP_DIR=/mongodb_consistent_backup -BACKUP_CNF=$BACKUP_DIR/mongodb-consistent-backup.conf -BACKUP_IMAGE=mongodb_consistent_backup -BACKUP_DATA_IMAGE=mongodb_consistent_backup-data -MCB_FLAGS="-c $BACKUP_CNF -L $BACKUP_DIR/logs -l $BACKUP_DIR/data" -DOCKER_IMAGE=timvaillancourt/mongodb_consistent_backup:latest - -if [ "$ACTION" = "backup" ]; then - CNF=$2 - [ -z $2 ] && echo "Usage: $0 backup [mongodb-consistent-backup config file]" && exit 1 - - docker ps -a | grep -q "$BACKUP_DATA_IMAGE" - if [ $? -gt 0 ]; then - echo "# Creating persistent volume for Docker image: $DOCKER_IMAGE" - docker create -v $BACKUP_DIR --name $BACKUP_DATA_IMAGE $DOCKER_IMAGE - fi - - if [ -f $CNF ]; then - echo "# Loading config file $CNF into container" - docker cp $CNF ${BACKUP_DATA_IMAGE}:${BACKUP_CNF} - - echo "# Running Docker image: $DOCKER_IMAGE" - docker run -i --name $BACKUP_IMAGE --rm --volumes-from $BACKUP_DATA_IMAGE $DOCKER_IMAGE $MCB_FLAGS - else - echo "# Config file $CNF does not exist!" - exit 1 - fi -elif [ "$ACTION" = "list" ]; then - echo "# Listing backups in $BACKUP_DATA_IMAGE" - docker run -it --name $BACKUP_IMAGE --rm --volumes-from $BACKUP_DATA_IMAGE --entrypoint /bin/find $DOCKER_IMAGE $BACKUP_DIR/data -maxdepth 2 -type d -name "[0-9]*_*" -elif [ "$ACTION" = "get" ]; then - DIR=$2 - [ -z $DIR ] && echo "Usage: $0 get [backup path]" && exit 1 - docker cp $BACKUP_DATA_IMAGE:$DIR . -fi