Skip to content

glensc/docker-mongodb-hotbackup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

MongoDB Hot Backup for Docker

Usage

This project provides script to run Hot Backup for percona/percona-server-mongodb.

The mongo container needs to be setup with local mount:

version: "3"

services:
  mongo:
    image: percona/percona-server-mongodb:3.4
    # (case sensitive) engine: mmapv1, rocksdb, wiredTiger, inMemory
    command: --storageEngine=wiredTiger
    volumes:
      - /srv/backups/mongodb:/backup
    ports:
      - 27017:27017

# vim:ts=2:sw=2:et

To run the backup, specify container name or id on commandline:

./backup-mongodb.sh CONTAINER BACKUP_DIR [USER] [PASSWORD]
  • CONTAINER can be id, name, label, or swarm service name
  • BACKUP_DIR is path that is bind mounted into container: -v $EXTERNAL_BACKUP_DIR:$CONTAINER_BACKUP_DIR the value for local dir is detected automatically
  • USER mongodb username, optional (will try to autheticate only when filled)
  • PASSWORD mongodb password, optional

Hot Backup

Percona Server for MongoDB includes an integrated open-source hot backup system for the default WiredTiger and alternative MongoRocks storage engine. It creates a physical data backup on a running server without notable performance and operating degradation.

To take a hot backup of the database in your current dbpath, run the createBackup command as administrator on the admin database and specify the backup directory.

> use admin
switched to db admin
> db.runCommand({createBackup: 1, backupDir: "/my/backup/data/path"})
{ "ok" : 1 }

If the backup was successful, you should receive an { "ok" : 1 } object. If there was an error, you will receive a failing ok status with the error message, for example:

> db.runCommand({createBackup: 1, backupDir: ""})
{ "ok" : 0, "errmsg" : "Destination path must be absolute" }

https://www.percona.com/doc/percona-server-for-mongodb/LATEST/hot-backup.html