MongoDB dockerized backup agent. Runs schedule backups with retention, S3 & SFTP upload, notifications, instrumentation with Prometheus and more.
MongoDB dockerized backup agent. Runs schedule backups with retention, S3 & SFTP upload, notifications, instrumentation with Prometheus and more.
This project is no longer maintained. I lost interest in MongoDB some years ago and I can't drive an OSS project forward in my spare time without being passioned about it.
But MGOB lives on thanks to @maxisam. The new home of MGOB is https://github.com/maxisam/mgob
MGOB is a MongoDB backup automation tool built with Go.
MGOB is available on Docker Hub at stefanprodan/mgob.
Supported tags:
stefanprodan/mgob:latest latest stable releasestefanprodan/mgob:edge master branch latest successful buildCompatibility matrix:
| MGOB | MongoDB |
|---|---|
stefanprodan/mgob:0.9 |
3.4 |
stefanprodan/mgob:0.10 |
3.6 |
stefanprodan/mgob:1.0 |
4.0 |
stefanprodan/mgob:1.1 |
4.2 |
Docker:
docker run -dp 8090:8090 --name mgob \
-v "/mgob/config:/config" \
-v "/mgob/storage:/storage" \
-v "/mgob/tmp:/tmp" \
-v "/mgob/data:/data" \
stefanprodan/mgob \
-LogLevel=infoKubernetes:
A step by step guide on running MGOB as a StatefulSet with PersistentVolumeClaims can be found here.
Define a backup plan (yaml format) for each database you want to backup inside the config dir.
The yaml file name is being used as the backup plan ID, no white spaces or special characters are allowed.
Backup plan
…ReplicaSet example:
target:
host: "mongo-0.mongo.db,mongo-1.mongo.db,mongo-2.mongo.db"
port: 27017
database: "test"Sharded cluster with authentication and SSL example:
target:
host: "mongos-0.db,mongos-1.db"
port: 27017
database: "test"
username: "admin"
password: "secret"
params: "--ssl --authenticationDatabase admin"mgob-host:8090/storage file servermgob-host:8090/status backup jobs statusmgob-host:8090/metrics Prometheus endpointmgob-host:8090/version mgob version and runtime infomgob-host:8090/debug pprof endpointOn demand backup:
mgob-host:8090/backup/:planIDcurl -X POST http://mgob-host:8090/backup/mongo-debug{
"plan": "mongo-debug",
"file": "mongo-debug-1494256295.gz",
"duration": "3.635186255s",
"size": "455 kB",
"timestamp": "2017-05-08T15:11:35.940141701Z"
}Scheduler status:
mgob-host:8090/statusmgob-host:8090/status/:planIDcurl -X GET http://mgob-host:8090/status/mongo-debug{
"plan": "mongo-debug",
"next_run": "2017-05-13T14:32:00+03:00",
"last_run": "2017-05-13T11:31:00.000622589Z",
"last_run_status": "200",
"last_run_log": "Backup finished in 2.339055539s archive mongo-debug-1494675060.gz size 527 kB"
}View scheduler logs with docker logs mgob:
…The success/fail logs will be sent via SMTP and/or Slack if notifications are enabled.
The mongodump log is stored along with the backup data (gzip archive) in the storage dir:
aleph-mbp:test aleph$ ls -lh storage/mongo-dev
total 4160
-rw-r--r-- 1 aleph staff 410K May 3 17:46 mongo-dev-1493822760.gz
-rw-r--r-- 1 aleph staff 1.9K May 3 17:46 mongo-dev-1493822760.log
-rw-r--r-- 1 aleph staff 410K May 3 17:47 mongo-dev-1493822820.gz
-rw-r--r-- 1 aleph staff 1.5K May 3 17:47 mongo-dev-1493822820.logSuccessful backups counter
mgob_scheduler_backup_total{plan="mongo-dev",status="200"} 8Successful backups duration
mgob_scheduler_backup_latency{plan="mongo-dev",status="200",quantile="0.5"} 2.149668417
mgob_scheduler_backup_latency{plan="mongo-dev",status="200",quantile="0.9"} 2.39848413
mgob_scheduler_backup_latency{plan="mongo-dev",status="200",quantile="0.99"} 2.39848413
mgob_scheduler_backup_latency_sum{plan="mongo-dev",status="200"} 17.580484907
mgob_scheduler_backup_latency_count{plan="mongo-dev",status="200"} 8Failed jobs count and duration (status 500)
mgob_scheduler_backup_latency{plan="mongo-test",status="500",quantile="0.5"} 2.4180213
mgob_scheduler_backup_latency{plan="mongo-test",status="500",quantile="0.9"} 2.438254775
mgob_scheduler_backup_latency{plan="mongo-test",status="500",quantile="0.99"} 2.438254775
mgob_scheduler_backup_latency_sum{plan="mongo-test",status="500"} 9.679809477
mgob_scheduler_backup_latency_count{plan="mongo-test",status="500"} 4In order to restore from a local backup you have two options:
Browse mgob-host:8090/storage to identify the backup you want to restore.
Login to your MongoDB server and download the archive using curl and restore the backup with mongorestore command line.
curl -o /tmp/mongo-test-1494056760.gz http://mgob-host:8090/storage/mongo-test/mongo-test-1494056760.gz
mongorestore --gzip --archive=/tmp/mongo-test-1494056760.gz --dropYou can also restore a backup from within mgob container.
Exec into mgob, identify the backup you want to restore and use mongorestore to connect to your MongoDB server.
docker exec -it mgob sh
ls /storage/mongo-test
mongorestore --gzip --archive=/storage/mongo-test/mongo-test-1494056760.gz --host mongohost:27017 --dropNo open issues yet, or sync has not completed.