Docker image with mongodump running as a cron task.
Attach a target mongo container to this container and mount a volume to container /backup
folder. The backups will appear in this volume as gzip-archives with names like 20170218_025718
, where mask is %Y%m%d_%H%M%S
.
docker run -d \
-v /path/to/my-folder:/backup \ # path to put backups
--link my-mongo-container:mongo \ # linked container with running mongo
tenorok/mongodumper
To run manual backup without cron job, add no-cron
parameter.
docker run --rm \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
tenorok/mongodumper no-cron # manual start
mongorestore --gzip --archive=/path/to/my-folder/20170218_025718
For customize backups schedule.
Default schedule is 0 0 * * *
โ runs every day at 00:00.
Recommend useful online helper for decoding crontab.
docker run -d \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
-e 'CRON_SCHEDULE=0 3 */5 * *' \ # custom cron job schedule
tenorok/mongodumper
For dump selective databases specify they names through space. This will create archives with names like 20170218_025718-db1
and 20170218_025718-db2
for each database from option.
Unfortunately now mongodump not providing opportunity to backups multiple databases at one time (TOOLS-22, TOOLS-31).
docker run -d \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
-e 'MONGO_DB_NAMES=db1 db2' \ # names (through space) of databases for dumping
tenorok/mongodumper
For remove unnecessary archives older than specified number of days.
docker run -d \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
-e 'BACKUP_EXPIRE_DAYS=30' \ # number of days for remove old backups
tenorok/mongodumper
For save backup with custom name. This option is more relevant for manual backup, because with scheduled backups file with specified name will overwritten each time.
docker run -d \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
-e 'BACKUP_FILE_NAME=express' \ # custom name for backup archive
tenorok/mongodumper
If your mongodb need user and password to access, you need set them in your environment.
docker run -d \
-v /path/to/my-folder:/backup \
--link my-mongo-container:mongo \
-e 'MONGO_USERNAME=root' \ # mongo -u $MONGO_USERNAME
-e 'MONGO_PASSWORD=rootpassword' \ # mongo -p $MONGO_PASSWORD
tenorok/mongodumper