• Stars
    star
    273
  • Rank 145,251 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tool for performing consistent backups of MongoDB Clusters or Replica Sets

MongoDB Consistent Backup Tool - mongodb-consistent-backup

https://github-release-version.herokuapp.com/github/Percona-Lab/mongodb_consistent_backup/release.svg?style=flat https://travis-ci.org/Percona-Lab/mongodb_consistent_backup.svg?branch=master

About

Creates cluster-consistent point-in-time backups of MongoDB with optional archiving, compression/de-duplication, encryption and upload functionality

The motivation for this tool in explained in this Percona blog post (more posts coming soon): "MongoDB Consistent Backups"

Note: Percona does not actively develop this tool since the release of [percona-backup-mongodb](https://github.com/percona/percona-backup-mongodb/) at the beginning of October 2019. This newer tool makes consistent backups for sharded clusters with the same dump and oplog-taking procedures, but uses golang agents rather than shell scripts.

Features

  • Works on a single replset (2+ members) or a sharded cluster
  • Auto-discovers healthy members for backup by considering replication lag, replication 'priority' and by preferring 'hidden' members
  • Creates cluster-consistent backups across many separate shards
  • 'mongodump' is the default (and currently only) backup method. Other methods coming soon!
  • Transparent restore process (just add --oplogReplay flag to your mongorestore command)
  • Archiving and compression of backups (optional)
  • Block de-duplication and optional AES encryption at rest via ZBackup archiving method (optional)
  • AWS S3 Secure Multipart backup uploads (optional)
  • Google Cloud Storage Secure backup uploads (optional)
  • Rsync (over SSH) secure backup uploads (optional)
  • Nagios NSCA push notification support (optional)
  • Zabbix sender notification support (optional)
  • Modular backup, archiving, upload and notification components
  • Support for MongoDB Authentication and SSL database connections
  • Support for Read Preference Tags for selecting specific nodes for backup
  • mongodb+srv:// DNS Seedlist support
  • Rotation of backups by time or count
  • Multi-threaded, single executable
  • Auto-scales to number of available CPUs by default

Limitations

  • MongoDB Replication is required on all nodes (sharding config servers included)
  • The host running 'mongodb-consistent-backup' must have enough disk, network and cpu resources to backup all shards in parallel
  • When MongoDB authentication is used, the same user/password/authdb and role(s) must exist on all hosts

Requirements:

  • MongoDB / Percona Server for MongoDB 3.2 and above with Replication enabled
  • Backup consistency depends on consistent server time across all hosts! Server time must be synchronized on all nodes using ntpd and a consistent time source or virtualization guest agent that syncs time
  • Must have 'mongodump' installed and specified if not at default: /usr/bin/mongodump. Even if you do not run MongoDB 3.2+, it is strongly recommended to use MongoDB 3.2+ mongodump binaries due to inline compression and parallelism features
  • Must have Python 2.7 installed

Releases

Pre-built release binaries and packages are available on our GitHub Releases Page. We recommend most users deploy mongodb_consistent_backup using these packages.

Build/Install

To build on CentOS/RedHat, you will need the following packages installed:

$ yum install python python-devel python-virtualenv gcc git make libffi-devel openssl-devel

To build an CentOS/RedHat RPM of the tool (recommended):

$ cd /path/to/mongodb_consistent_backup
$ yum install -y rpm-build
$ make rpm

To build and install from source (to default '/usr/local/bin/mongodb-consistent-backup'):

$ cd /path/to/mongodb_consistent_backup
$ make
$ make install

Use the PREFIX= variable to change the installation path (default: /usr/local), ie: make PREFIX=/usr install to install to: '/usr/bin/mongodb-consistent-backup'.

MongoDB Authorization

If your replset/cluster uses Authentication, you must add a user with the "backup" and "clusterMonitor" built-in auth roles.

To create a user, execute the following replace the 'pwd' field with a secure password!:

db.getSiblingDB("admin").createUser({
        user: "mongodb_consistent_backup",
        pwd: "PASSWORD-HERE",
        roles: [
                { role: "backup", db: "admin" },
                { role: "clusterMonitor", db: "admin" }
        ]
})

User and password are set using the 'user' and 'password' config-file fields or via the '-u' and '-p' command-line flags not recommended due to security concerns

Run a Backup

Using Command-Line Flags

Note: username+password is visible in process lists when set using the command-line flags. Use a config file (below) to hide credentials!

$ mongodb-consistent-backup -H mongos1.example.com -P 27018 -u mongodb-consistent-backup -p s3cr3t -n prodwebsite -l /var/lib/mongodb-consistent-backup
...
...
$ ls /opt/mongobackups
prodwebsite

Using a Config File

The tool supports a YAML-based config file for settings. The config file is loaded first and any additional command-line arguments override the file based config settings.

$ mongodb-consistent-backup --config /etc/mongodb-consistent-backup.yml
...

An example (with comments) of the YAML-based config file is here: conf/mongodb-consistent-backup.example.conf.

A description of all available config settings can also be listed by passing the '--help' flag to the tool.

Restore a Backup

The backups are mongorestore compatible and stored in a directory per backup. The --oplogReplay flag MUST be present to replay the oplogs to ensure consistency.

$ tar xfvz <shardname>.tar.gz
...
$ mongorestore --host mongod12.example.com --port 27017 -u admin -p 123456 --oplogReplay --gzip --dir /var/lib/mongodb-consistent-backup/default/20170424_0000/rs0/dump

Run as Docker Container

To persist logs, configs and backup data 3 directories should be mapped to be inside the Docker container.

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

$ 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" \
  perconalab/mongodb_consistent_backup:latest --config=/conf/mongodb-consistent-backup.conf

Build and Run Docker Image

$ cd /path/to/mongodb_consistent_backup
$ make docker
$ 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)

Note: the ZBackup archive method is not yet compatible with the 'Upload' phase. Disable uploading by setting 'upload.method' to 'none' in the meantime.

ZBackup (with LZMA compression) is an optional archive method for mongodb_consistent_backup. This archive method significantly reduces disk usage for backups via de-duplication and compression.

ZBackup offers block de-duplication and compression of backups and optionally supports AES-128 (CBC mode with PKCS#7 padding) encryption at rest. The ZBackup archive method causes backups to be stored via ZBackup at archive time.

To enable, ZBackup must be installed on your system and the 'archive.method' config file variable (or --archive.method flag=) must be set to 'zbackup'.

ZBackup's compression is most efficient when compression is disabled in the backup phase, to do this set 'backup.<method>.compression' to 'none'.

Install on CentOS/RHEL

$ yum install zbackup

Install on Debian/Ubuntu

$ apt-get install zbackup

Get Backup from ZBackup

ZBackup data is stored in a storage directory named 'mongodb_consistent_backup-zbackup' and must be restored using a 'zbackup restore ...' command.

$ zbackup restore --password-file /etc/zbackup.passwd /mnt/backup/default/mongodb_consistent_backup-zbackup/backups/20170424_0000.tar | tar -xf

Delete Backup from ZBackup

To remove a backup, first delete the .tar file in 'backups' subdir of the ZBackup storage directory. After, run a 'zbackup gc full' garbage collection to remove unused data.

$ rm -f /mnt/backup/default/mongodb_consistent_backup-zbackup/backups/20170424_0000.tar
$ zbackup gc full --password-file /etc/zbackup.passwd /mnt/backup/default/mongodb_consistent_backup-zbackup

Submitting Code

  • Submitted code must pass Python 'flake8' checks. Run 'make flake8' to test.
  • To make review easier, pull requests must address and solve one problem at a time.

Links

Contact

Contact Percona

More Repositories

1

tpcc-mysql

C
455
star
2

sysbench-tpcc

Sysbench scripts to generate a tpcc-like workload for MySQL and PostgreSQL
Lua
279
star
3

mysql_random_data_load

MySQL random data loader
Go
269
star
4

PromHouse

PromHouse is a long-term remote storage with built-in clustering and downsampling for Prometheus 2.x on top of ClickHouse.
Go
255
star
5

clickhousedb_fdw

PostgreSQL's Foreign Data Wrapper For ClickHouse
C
198
star
6

query-playback

Query Playback
C++
95
star
7

ontime-airline-performance

Shell
95
star
8

pacemaker-replication-agents

Repository of the Percona Pacemaker resource agents
Shell
77
star
9

pg_tde

C
66
star
10

percona-openshift

Set of scripts to run Percona software in OpenShift / Kubernetes
Shell
54
star
11

proxysql-docker

Shell
44
star
12

pxc-docker

All docker related code for PXC
Shell
39
star
13

tuned-percona-mongodb

A performance-focused tuned profile for MongoDB on CentOS/Redhat Linux
Makefile
37
star
14

coredumper

Google coredumper library
C
33
star
15

pxc-proxysql-k8s

Shell
32
star
16

benchmark-results

23
star
17

jenkins-pipelines

Groovy
21
star
18

percona-xtradb-cluster-docker

Shell
21
star
19

tpce-mysql

C++
19
star
20

grafana_mongodb_dashboards

Dashboard for using Grafana and prometheus_mongodb_exporter
17
star
21

prom-migrate

prom-migrate reads all data from Prometheus 1.8 via API and creates a new Prometheus 2.0 storage directory.
Go
16
star
22

sysbench-mongodb-lua

Lua
14
star
23

pmm-submodules

A repo dedicated to building Percona Monitoring and Management (PMM)
Python
12
star
24

pt-mysql-config-diff

A tool like pt-config-diff written in Go
Go
11
star
25

serverless-postgresql-build

Shell
11
star
26

terraform-provider-percona

Terraform modules to deploy Percona Server and Percona XtraDB Cluster
Go
11
star
27

go-tpcc

Go
10
star
28

pt-pmp

Shell
9
star
29

proxysql-ha-experiments

Shell
8
star
30

pmm-custom-queries

Custom queries for Percona Monitoring and Management (PMM)
Shell
8
star
31

tokumx2_to_psmdb3_migration

Instructions and scripts to facilitate migration from TokuMX 2.0.x to PSMDB 3.0.x
JavaScript
7
star
32

percona-images

Packer config to build Percona base boxes
Shell
7
star
33

libeatmydata

libeatmydata library and packaging
M4
7
star
34

slowlog2clickhouse

Parse MySQL Slow log and save into ClickHouse table
Go
7
star
35

k8s-lab

HCL
6
star
36

autotokubackup

AutoTokBackup: A tokubackup commandline tool for running Percona TokuBackup written in Python3
Python
6
star
37

mysql-configs

5
star
38

ognom-toolkit

Go
5
star
39

mysql-group-replication-docker

Shell
5
star
40

percona-dbaas-cli

Go
5
star
41

ps-build

Collection of MySQL build scripts
Shell
4
star
42

proxysql-scheduler

Shell
4
star
43

pmm-ruled

Rules Daemon
Go
4
star
44

group_replication_tools

4
star
45

percona-millipede

Multi-host, sub-second replication delay monitor
Python
4
star
46

mnogo_exporter

Moved to https://github.com/percona/mongodb_exporter (branch exporter_v2)
Go
4
star
47

percona-version-service

Go
3
star
48

pt-mongodb-summary

pt-mongodb-summary
Go
3
star
49

MetricBench

C++
3
star
50

toolkit-tests

Docker container to run Percona Toolkit tests
Shell
3
star
51

minimum_permissions

Get the minimum set of permissions needed to run a particular query
Go
3
star
52

codeceptjs-saucehelper

CodeceptJS Sauce Labs helpers, to update Test Names, Test Results after test execution
JavaScript
2
star
53

codeceptjs-influxdbhelper

CodeceptJS helper to collect Test Execution Metrics with the help of CodeceptJS test events
JavaScript
2
star
54

redo_log_dumper

POC for a innodb redo log dumper
Go
2
star
55

text2json

POC for a text (pt-summary / pt-mysql-summary) reports to json converter
Go
2
star
56

sysbench-blob

Lua
2
star
57

PLG

Recording and replaying exporters
Go
2
star
58

benchmark_automation

Scripts to help automate the running of repeatable benchmarks
Shell
2
star
59

mongodb-fingerprint

Go
2
star
60

pmm-dashboards

PMM compatible dashboards or dashboards done during webinars or presentations
Shell
2
star
61

pmm-api

Moved to https://github.com/percona/pmm
HTML
2
star
62

serverless-postgresql-ansible

Ansible playbook to deploy serverless PostgreSQL
Jinja
2
star
63

wsrpc

Early prototype; dead end
Go
2
star
64

pmm-workloads

Various Workloads to Test and Demo Percona Monitoring and Management (PMM)
PHP
2
star
65

percona-binlog-server

Percona Binary Log Server
C++
2
star
66

star-schema-benchmark

Scala
1
star
67

sst-bench

Shell
1
star
68

sanitizer

POC for a log sanitizer for pt-stalk, pt-mysql-summary, pt-summary
Go
1
star
69

operator-env

Go
1
star
70

vitess-tpcc-lab

Lua
1
star
71

pmm-build

Early prototype; dead end
Go
1
star
72

percona-server-mongodb-openshift

Shell
1
star
73

wikistat-data

Python
1
star
74

mysql-kubernetes-openshift

1
star
75

pmm-client-docker

Shell
1
star
76

install-repo-pmm-server

Shell
1
star
77

pmm-api-tests

API tests for PMM 2.x.
Go
1
star
78

eng-scripts

Scripts from MySQL Engineering Team
Shell
1
star
79

mongodb_systemd_multi

Setup of script for multiple instances in a single host for mongodb (designed for testing) or systemd mongo for mongos, arbiters, config servers and mongod's
Shell
1
star
80

percona-mixins

Jsonnet
1
star
81

percona-on-arm

Unofficial builds
Shell
1
star
82

sysbench-mongodb-loop

A wrapper to run sysbench-mongodb forever
Shell
1
star
83

procfs

C++
1
star
84

visualize-mysql-queries

visualize mysql queries (based on Performance Schema)
JavaScript
1
star
85

rdsosmetrics_exporter

PROOF OF CONCEPT! export RDS Enhanced Monitoring metrics from CloudWatch Logs for prometheus
Go
1
star
86

MyRocks-benchmark

Scripts used too perform MyRocks specific benchmarks, forked from mdcallag/sysbench
1
star
87

single_install

This repo provides a single click installation script to Percona Products
Shell
1
star