Skip to content

Commit dd7c372

Browse files
Merge pull request #113 from timvaillancourt/dockerfile_version1.0
Build Docker image using 1.0.0 release, add ZBackup to Dockerfile, add script for persistent Docker data
2 parents d780ad5 + b98eab7 commit dd7c372

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
FROM centos:centos7
22
MAINTAINER Tim Vaillancourt <tim.vaillancourt@percona.com>
3-
RUN yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm && \
4-
yum install -y Percona-Server-MongoDB-32-tools && yum clean all && \
5-
curl -Lo /usr/bin/mongodb-consistent-backup https://github.com/Percona-Lab/mongodb_consistent_backup/releases/download/0.4.0/mongodb-consistent-backup.el7.x86_64 && \
3+
RUN yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm epel-release && \
4+
yum install -y Percona-Server-MongoDB-32-tools zbackup && yum clean all && \
5+
curl -Lo /usr/bin/mongodb-consistent-backup https://github.com/Percona-Lab/mongodb_consistent_backup/releases/download/1.0.0/mongodb-consistent-backup.el7.centos.x86_64 && \
66
chmod +x /usr/bin/mongodb-consistent-backup
77
ENTRYPOINT ["mongodb-consistent-backup"]
88
CMD ["--help"]

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ The backups are mongorestore compatible and stored in a directory per backup. Th
141141
Run as Docker Container (Experimental)
142142
~~~~~~~~~~~~~~~~~~~~~~~
143143

144-
*Note: you need to use persistent volumes to store backups and/or config files long-term when using Docker. Data in Docker containers is destroyed when the container is deleted.*
144+
Note: you need to use persistent volumes to store backups and/or config files long-term when using Docker. Data in Docker containers is destroyed when the container is deleted. See `scripts/docker-persistent.sh <scripts/docker-persistent.sh>`__ and `scripts/docker-persistent.example.conf <scripts/docker-persistent.example.conf>`__ as an example/demo of how to implement persistence.
145145

146146
**Via Docker Hub**
147147

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 'log_dir' and 'backup.location' flags are auto-overriden
2+
# when using with scripts/docker-persistent.sh. No need to
3+
# add them here.
4+
production:
5+
host: mongodb01.example.com
6+
port: 27017
7+
backup:
8+
method: mongodump
9+
name: default
10+
archive:
11+
method: tar
12+
notify:
13+
method: none
14+
upload:
15+
method: none

scripts/docker-persistent.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
#
3+
# Script for running mongodb_consistent_backup under Docker
4+
# with persistent data container for data, config and logs.
5+
#
6+
# See: scripts/docker-persistent.example.conf for an example
7+
# config to pass to this script during backup. 'log_dir' and
8+
# 'backup.location' variables are auto-set by this script.
9+
#
10+
# Run backup:
11+
# $ scripts/docker-persistent.sh backup scripts/docker-persistent.example.conf
12+
# # Loading config file scripts/docker-persistent.example.conf into container
13+
# # Running Docker image: timvaillancourt/mongodb_consistent_backup:latest
14+
# [2017-04-27 11:22:04,255] [INFO] [MainProcess] [Main:init:127] Starting mongodb-consistent-backup version 1.0.0 (git commit: d780ad545b603d3a2f807e1813f1de407e81f1ba)
15+
# ...
16+
# ...
17+
#
18+
# List backups (in persistent Docker volume):
19+
# $ scripts/docker-persistent.sh list
20+
# /mongodb_consistent_backup/data/default/20170427_1122
21+
# /mongodb_consistent_backup/data/default/20170427_1123
22+
#
23+
# Get a backup:
24+
# $ scripts/docker-persistent.sh get /mongodb_consistent_backup/data/default/20170427_1122
25+
# $ ls -ald ./20170427_112
26+
# drwxr-xr-x. 3 root root 59 Apr 27 13:22 ./20170427_1122
27+
#
28+
29+
ACTION=$1
30+
[ -z $1 ] && echo "Usage: $0 [backup|list|get] [action flags]" && exit 1
31+
32+
BACKUP_DIR=/mongodb_consistent_backup
33+
BACKUP_CNF=$BACKUP_DIR/mongodb-consistent-backup.conf
34+
BACKUP_IMAGE=mongodb_consistent_backup
35+
BACKUP_DATA_IMAGE=mongodb_consistent_backup-data
36+
MCB_FLAGS="-c $BACKUP_CNF -L $BACKUP_DIR/logs -l $BACKUP_DIR/data"
37+
DOCKER_IMAGE=timvaillancourt/mongodb_consistent_backup:latest
38+
39+
if [ "$ACTION" = "backup" ]; then
40+
CNF=$2
41+
[ -z $2 ] && echo "Usage: $0 backup [mongodb-consistent-backup config file]" && exit 1
42+
43+
docker ps -a | grep -q "$BACKUP_DATA_IMAGE"
44+
if [ $? -gt 0 ]; then
45+
echo "# Creating persistent volume for Docker image: $DOCKER_IMAGE"
46+
docker create -v $BACKUP_DIR --name $BACKUP_DATA_IMAGE $DOCKER_IMAGE
47+
fi
48+
49+
if [ -f $CNF ]; then
50+
echo "# Loading config file $CNF into container"
51+
docker cp $CNF ${BACKUP_DATA_IMAGE}:${BACKUP_CNF}
52+
53+
echo "# Running Docker image: $DOCKER_IMAGE"
54+
docker run -i --name $BACKUP_IMAGE --rm --volumes-from $BACKUP_DATA_IMAGE $DOCKER_IMAGE $MCB_FLAGS
55+
else
56+
echo "# Config file $CNF does not exist!"
57+
exit 1
58+
fi
59+
elif [ "$ACTION" = "list" ]; then
60+
echo "# Listing backups in $BACKUP_DATA_IMAGE"
61+
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]*_*"
62+
elif [ "$ACTION" = "get" ]; then
63+
DIR=$2
64+
[ -z $DIR ] && echo "Usage: $0 get [backup path]" && exit 1
65+
docker cp $BACKUP_DATA_IMAGE:$DIR .
66+
fi

0 commit comments

Comments
 (0)