Skip to content

Commit cba8431

Browse files
Merge remote-tracking branch 'upstream/master' into location_and_name_defaults_update
2 parents c49da09 + ea5626a commit cba8431

30 files changed

+591
-189
lines changed

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
FROM centos:centos7
2-
ARG RELEASE
32
MAINTAINER Tim Vaillancourt <tim.vaillancourt@percona.com>
3+
44
RUN yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm epel-release && \
55
yum install -y Percona-Server-MongoDB-34-tools zbackup && yum clean all
6-
RUN curl -Lo /usr/bin/mongodb-consistent-backup https://github.com/Percona-Lab/mongodb_consistent_backup/releases/download/$RELEASE/mongodb-consistent-backup.el7.centos.x86_64 && \
7-
chmod +x /usr/bin/mongodb-consistent-backup
6+
7+
ADD build/rpm/RPMS/x86_64/mongodb_consistent_backup*.el*.centos.x86_64.rpm /
8+
RUN yum localinstall -y /mongodb_consistent_backup*.el*.centos.x86_64.rpm && \
9+
yum clean all && rm -f /mongodb_consistent_backup*.el*.centos.x86_64.rpm
10+
11+
USER mongodb_consistent_backup
812
ENTRYPOINT ["mongodb-consistent-backup"]
913
CMD ["--help"]

Makefile

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
#
33

44
NAME=mongodb_consistent_backup
5+
BIN_NAME?=mongodb-consistent-backup
56
VERSION=$(shell cat VERSION | cut -d- -f1)
7+
GIT_COMMIT?=$(shell git show 2>/dev/null | awk 'NR==1{print $$2}')
68
PREFIX?=/usr/local
9+
ARCH?=x86_64
710
BASEDIR?=$(DESTDIR)$(PREFIX)
811
BINDIR?=$(BASEDIR)/bin
912
SHAREDIR?=$(BASEDIR)/share
1013
DOCKER_TAG?="$(NAME):$(VERSION)"
14+
DOCKER_BASE_IMAGE?=$(shell awk '/FROM/{print $$2}' Dockerfile)
15+
MAKE_DIR=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
1116

17+
all: bin/$(BIN_NAME)
1218

13-
all: bin/mongodb-consistent-backup
19+
bin/$(BIN_NAME): setup.py requirements.txt README.rst VERSION scripts/build.sh $(NAME)/*.py $(NAME)/*/*.py $(NAME)/*/*/*.py
20+
BIN_NAME=$(BIN_NAME) GIT_COMMIT=$(GIT_COMMIT) PYTHON_BIN=$(PYTHON_BIN) VIRTUALENV_BIN=$(VIRTUALENV_BIN) bash scripts/build.sh
1421

15-
bin/mongodb-consistent-backup: setup.py requirements.txt README.rst VERSION scripts/build.sh $(NAME)/*.py $(NAME)/*/*.py $(NAME)/*/*/*.py
16-
PYTHON_BIN=$(PYTHON_BIN) VIRTUALENV_BIN=$(VIRTUALENV_BIN) bash scripts/build.sh
17-
18-
install: bin/mongodb-consistent-backup
22+
install: bin/$(BIN_NAME)
1923
mkdir -p $(BINDIR) $(SHAREDIR)/$(NAME) || true
20-
install -m 0755 bin/mongodb-consistent-backup $(BINDIR)/mongodb-consistent-backup
24+
install -m 0755 bin/$(BIN_NAME) $(BINDIR)/mongodb-consistent-backup
2125
install -m 0644 conf/mongodb-consistent-backup.example.conf $(SHAREDIR)/$(NAME)/example.conf
2226
install -m 0644 LICENSE $(SHAREDIR)/$(NAME)/LICENSE
2327
install -m 0644 README.rst $(SHAREDIR)/$(NAME)/README.rst
@@ -26,21 +30,90 @@ flake8:
2630
# Ignore long-lines and space-aligned = and : for now
2731
flake8 --ignore E221,E241,E501 $(PWD)/$(NAME)
2832

33+
rpm: bin/$(BIN_NAME)
34+
mkdir -p $(MAKE_DIR)/build/rpm/SOURCES
35+
cp -f $(MAKE_DIR)/{LICENSE,README.rst} build/rpm/SOURCES
36+
cp -f $(MAKE_DIR)/bin/$(BIN_NAME) build/rpm/SOURCES/mongodb-consistent-backup
37+
cp -f $(MAKE_DIR)/conf/mongodb-consistent-backup.example.conf build/rpm/SOURCES/mongodb-consistent-backup.conf
38+
rpmbuild -D "_topdir $(MAKE_DIR)/build/rpm" -D "version $(VERSION)" -bb $(MAKE_DIR)/scripts/$(NAME).spec
39+
2940
uninstall:
3041
rm -f $(BINDIR)/mongodb-consistent-backup
3142
rm -rf $(SHAREDIR)/$(NAME)
3243

33-
rpm: bin/mongodb-consistent-backup
34-
rm -rf build/rpm 2>/dev/null || true
35-
mkdir -p build/rpm/SOURCES
36-
cp -f $(PWD)/{LICENSE,README.rst} build/rpm/SOURCES
37-
cp -f $(PWD)/bin/mongodb-consistent-backup build/rpm/SOURCES/mongodb-consistent-backup
38-
cp -f $(PWD)/conf/mongodb-consistent-backup.example.conf build/rpm/SOURCES/mongodb-consistent-backup.conf
39-
rpmbuild -D "_topdir $(PWD)/build/rpm" -D "version $(VERSION)" -bb scripts/$(NAME).spec
44+
# Build CentOS7 RPM (in Docker)
45+
build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm:
46+
mkdir -p $(MAKE_DIR)/build/rpm/RPMS/$(ARCH)
47+
docker run --rm \
48+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
49+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
50+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
51+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
52+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
53+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
54+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
55+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
56+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
57+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
58+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
59+
-v "$(MAKE_DIR)/build/rpm/RPMS/$(ARCH):/src/build/rpm/RPMS/$(ARCH):Z" \
60+
-it centos:centos7 \
61+
/bin/bash -c "yum install -y python-devel python-virtualenv gcc make libffi-devel openssl-devel rpm-build && \
62+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.el7.centos.$(ARCH) rpm && \
63+
/src/bin/mongodb-consistent-backup.el7.centos.$(ARCH) --version"
64+
65+
centos7: build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm
66+
67+
# Build Debian8 Binary (in Docker - .deb package soon!)
68+
bin/mongodb-consistent-backup.debian8.$(ARCH):
69+
docker run --rm \
70+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
71+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
72+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
73+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
74+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
75+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
76+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
77+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
78+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
79+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
80+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
81+
-it debian:jessie \
82+
/bin/bash -c "apt-get update && apt-get install -y python2.7-minimal python2.7-dev python-virtualenv gcc make libffi-dev libssl-dev && \
83+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.debian8.$(ARCH).tmp && \
84+
mv -vf /src/bin/mongodb-consistent-backup.debian8.$(ARCH).tmp /src/bin/mongodb-consistent-backup.debian8.$(ARCH) && \
85+
/src/bin/mongodb-consistent-backup.debian8.$(ARCH) --version"
4086

41-
docker: bin/mongodb-consistent-backup
42-
docker build --no-cache --tag $(DOCKER_TAG) --build-arg "RELEASE=$(VERSION)" .
87+
debian8: bin/mongodb-consistent-backup.debian8.$(ARCH)
88+
89+
# Build Debian9 Binary (in Docker - .deb package soon!)
90+
bin/mongodb-consistent-backup.debian9.$(ARCH):
91+
docker run --rm \
92+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
93+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
94+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
95+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
96+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
97+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
98+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
99+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
100+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
101+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
102+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
103+
-it debian:stretch \
104+
/bin/bash -c "apt-get update && apt-get install -y python2.7-minimal python2.7-dev python-virtualenv gcc make libffi-dev libssl-dev && \
105+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.debian9.$(ARCH).tmp && \
106+
mv -vf /src/bin/mongodb-consistent-backup.debian9.$(ARCH).tmp /src/bin/mongodb-consistent-backup.debian9.$(ARCH) && \
107+
/src/bin/mongodb-consistent-backup.debian9.$(ARCH) --version"
108+
109+
debian9: bin/mongodb-consistent-backup.debian9.$(ARCH)
110+
111+
docker: build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm
112+
docker build --no-cache --tag $(DOCKER_TAG) .
43113
docker tag $(DOCKER_TAG) $(NAME):latest
114+
docker run --rm -it $(DOCKER_TAG) --version
115+
116+
release: centos7 debian8 debian9 docker
44117

45118
clean:
46119
rm -rf bin build $(NAME).egg-info tmp 2>/dev/null

README.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ Features
3131
archiving method (*optional*)
3232
- `AWS S3 <https://aws.amazon.com/s3/>`__ Secure Multipart backup uploads (*optional*)
3333
- `Google Cloud Storage <https://cloud.google.com/storage/>`__ Secure backup uploads (*optional*)
34+
- Rsync (over SSH) secure backup uploads (*optional*)
3435
- `Nagios NSCA <https://sourceforge.net/p/nagios/nsca>`__ push
3536
notification support (*optional*)
3637
- Modular backup, archiving, upload and notification components
38+
- Support for MongoDB Authentication and SSL database connections
3739
- Multi-threaded, single executable
3840
- Auto-scales to number of available CPUs by default
3941

@@ -77,6 +79,7 @@ To build an CentOS/RedHat RPM of the tool *(recommended)*:
7779
::
7880

7981
$ cd /path/to/mongodb_consistent_backup
82+
$ sudo yum install -y rpm-build
8083
$ make rpm
8184

8285
To build and install from source *(to default '/usr/local/bin/mongodb-consistent-backup')*:
@@ -148,25 +151,40 @@ The backups are `mongorestore <https://docs.mongodb.com/manual/reference/program
148151
...
149152
$ mongorestore --host mongod12.example.com --port 27017 -u admin -p 123456 --oplogReplay --dir /var/lib/mongodb-consistent-backup/default/20170424_0000/rs0/dump
150153

151-
Run as Docker Container (Experimental)
154+
Run as Docker Container
152155
~~~~~~~~~~~~~~~~~~~~~~~
153156

154-
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.
157+
To persist logs, configs and backup data 3 directories should be mapped to be inside the Docker containter.
158+
159+
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.
160+
161+
*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.*
155162

156163
**Via Docker Hub**
157164

158165
::
159166

160-
$ docker run -i timvaillancourt/mongodb_consistent_backup <mongodb_consistent_backup-flags>
167+
$ mkdir -p /data/mongobackup/{conf,data,logs}
168+
$ cp -f /path/to/mongodb-consistent-backup.conf /data/mongobackup/conf
169+
$ docker run -it \
170+
-v "/data/mongobackup/conf:/conf:Z" \
171+
-v "/data/mongobackup/data:/var/lib/mongodb-consistent-backup:Z" \
172+
-v "/data/mongobackup/logs:/var/log/mongodb-consistent-backup:Z" \
173+
timvaillancourt/mongodb_consistent_backup:latest --config=/conf/mongodb-consistent-backup.conf
161174

162175
**Build and Run Docker Image**
163176

164177
::
165178

166179
$ cd /path/to/mongodb_consistent_backup
167180
$ make docker
168-
$ docker run -t mongodb_consistent_backup <mongodb_consistent_backup-flags>
169-
181+
$ mkdir -p /data/mongobackup/{conf,data,logs}
182+
$ cp -f /path/to/mongodb-consistent-backup.conf /data/mongobackup/conf
183+
$ docker run -it \
184+
-v "/data/mongobackup/conf:/conf:Z" \
185+
-v "/data/mongobackup/data:/var/lib/mongodb-consistent-backup:Z" \
186+
-v "/data/mongobackup/logs:/var/log/mongodb-consistent-backup:Z" \
187+
mongodb_consistent_backup --config=/conf/mongodb-consistent-backup.conf
170188

171189
ZBackup Archiving (Optional)
172190
~~~~~~~

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.2.0

conf/mongodb-consistent-backup.example.conf

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ production:
44
#username: [auth username] (default: none)
55
#password: [auth password] (default: none)
66
#authdb: [auth database] (default: admin)
7+
#ssl:
8+
# enabled: [true|false] (default: false)
9+
# insecure: [true|false] (default: false)
10+
# ca_file: [path]
11+
# crl_file: [path]
12+
# client_cert_file: [path]
713
log_dir: /var/log/mongodb-consistent-backup
814
backup:
915
method: mongodump
1016
name: default
1117
location: /var/lib/mongodb-consistent-backup
1218
# mongodump:
1319
# binary: [path] (default: /usr/bin/mongodump)
14-
# compression: [auto|none|gzip] (default: auto - enable gzip if supported)
15-
# threads: [1-16] (default: auto-generated - shards/cpu)
20+
# compression: [auto|none|gzip] (default: auto = enable gzip if supported)
21+
# threads: [1-16] (default: auto-generated, shards/cpu)
1622
#replication:
1723
# max_lag_secs: [1+] (default: 10)
1824
# min_priority: [0-999] (default: 0)
@@ -23,18 +29,19 @@ production:
2329
# wait_secs: [1+] (default: 300)
2430
# ping_secs: [1+] (default: 3)
2531
#oplog:
26-
# compression: [none|gzip] (default: gzip - if gzip is used by backup stage)
32+
# compression: [none|gzip] (default: gzip, if used by backup stage)
2733
# flush:
28-
# max_docs: 100
29-
# max_secs: 1
30-
# resolver_threads: [1+] (default: 2 per CPU)
34+
# max_docs: [1+] (default: 100)
35+
# max_secs: [1+] (default: 1)
36+
# resolver:
37+
# threads: [1+] (default: 2 per CPU)
3138
# tailer:
3239
# enabled: true
3340
# status_interval: 30
3441
archive:
3542
method: tar
3643
# tar:
37-
# compression: [none|gzip] (default: gzip - none if backup is already compressed)
44+
# compression: [none|gzip] (default: gzip, none if backup already compressed)
3845
# threads: [1+] (default: 1 per CPU)
3946
# zbackup:
4047
# binary: [path] (default: /usr/bin/zbackup)
@@ -52,21 +59,26 @@ production:
5259
upload:
5360
method: none
5461
# remove_uploaded: [true|false] (default: false)
62+
# retries: [1+] (default: 5)
63+
# threads: [1+] (default: 4)
5564
# gs:
5665
# project_id: [Google Cloud Project ID]
57-
# access_key: [Google Cloud Storage Access Key]
58-
# secret_key: [Google Cloud Storage Secret Key]
66+
# access_key: [Google Cloud Storage Interoperability API Access Key]
67+
# secret_key: [Google Cloud Storage Interoperability API Secret Key]
5968
# bucket_name: [Google Cloud Storage Bucket Name]
6069
# bucket_prefix: [prefix] (default: /)
61-
# threads: [1+] (default: 1 per CPU)
70+
# rsync:
71+
# path: [Rsync Destination Path]
72+
# user: [SSH Username]
73+
# host: [SSH Hostname/IP]
74+
# port: [SSH Port Number] (default: 22)
75+
# delete: [true|false] (default: false)
6276
# s3:
6377
# region: [AWS S3 Region] (default: us-east-1)
6478
# access_key: [AWS S3 Access Key]
6579
# secret_key: [AWS S3 Secret Key]
6680
# bucket_name: [AWS S3 Bucket Name]
6781
# bucket_prefix: [prefix] (default: /)
68-
# threads: [1+] (default: 1 per CPU)
6982
# chunk_size_mb: [1+] (default: 50)
7083
# secure: [true|false] (default: true)
71-
# retries: [1+] (default: 5)
7284
# acl: [acl_str] (default: none)

mongodb_consistent_backup/Archive/Archive.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from mongodb_consistent_backup.Archive.Tar import Tar # NOQA
2+
from mongodb_consistent_backup.Archive.Zbackup import Zbackup # NOQA
13
from mongodb_consistent_backup.Pipeline import Stage
24

35

mongodb_consistent_backup/Backup/Mongodump/Mongodump.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import logging
3-
import sys
43

54
from math import floor
65
from subprocess import check_output
@@ -57,22 +56,21 @@ def parse_mongodump_version(self):
5756
raise OperationError("Could not parse mongodump --version output!")
5857

5958
def choose_compression(self):
60-
if self.can_gzip():
59+
if self.can_compress():
6160
if self.compression() == 'auto':
6261
logging.info("Mongodump binary supports gzip compression, auto-enabling gzip compression")
6362
self.compression('gzip')
6463
elif self.compression() == 'gzip':
6564
raise OperationError("mongodump gzip compression requested on binary that does not support gzip!")
6665

67-
def can_gzip(self):
66+
def can_compress(self):
6867
if os.path.isfile(self.binary) and os.access(self.binary, os.X_OK):
69-
logging.debug("Mongodump binary supports gzip")
68+
logging.debug("Mongodump binary supports gzip compression")
7069
if tuple("3.2.0".split(".")) <= tuple(self.version.split(".")):
7170
return True
7271
return False
7372
else:
74-
logging.fatal("Cannot find or execute the mongodump binary file %s!" % self.binary)
75-
sys.exit(1)
73+
raise OperationError("Cannot find or execute the mongodump binary file %s!" % self.binary)
7674

7775
def summary(self):
7876
return self._summary

0 commit comments

Comments
 (0)