ztimson f81e6cd951
All checks were successful
Build and publish / Build Container (push) Successful in 1m47s
Added replica init
2026-06-12 02:24:35 -04:00
2026-03-04 12:36:44 -05:00
2026-03-04 10:24:08 -05:00
2026-03-04 10:24:08 -05:00
2026-06-12 02:24:35 -04:00
2026-03-04 11:27:27 -05:00
2026-06-12 02:24:35 -04:00
2026-06-12 02:24:35 -04:00


Logo

MongoDB

MongoDB + Backups & Retention

Version Pull Requests Issues



Table of Contents

About

Custom MongoDB Docker image extending mongo:latest with automated backups, retention management, and replica set configuration.

Includes cron-based scheduled mongodump operations with compression, automatic stale lock recovery on unclean shutdowns, and zero-config replica set initialization — while preserving all native MongoDB functionality.

Manually trigger a backup: docker exec -t mongodb backup

Restore a backup: Decompress the archive and use the official mongorestore tool.

Environment Variables

Variable Description Default Example
BACKUP_CRON Cron schedule expression 0 */6 * * *
BACKUP_DIR Directory to store backups /data/backups /backups
BACKUP_DB Database to backup $MONGO_INITDB_DATABASE admin
BACKUP_RETENTION Number of backups to keep, defaults to unlimited 7
MONGO_INITDB_DATABASE Default database name momentum
MONGO_INITDB_ROOT_USERNAME Root username for mongodump auth root
MONGO_INITDB_ROOT_PASSWORD Root password for mongodump auth secret
REPLICA Comma-separated list of replica hostnames to init/join a replica set db1:27017,db2:27017

Built With

Docker MongoDB

Setup

Production

Prerequisites

Instructions

  1. Run the docker image:
docker run -d \
  --name mongodb \
  --restart unless-stopped \
  -p 27017:27017 \
  -e MONGO_INITDB_DATABASE=myapp \
  -e BACKUP_CRON="0 3 * * *" \
  -e BACKUP_RETENTION=7 \
  -v ./mongodb/data:/data/db \
  -v ./mongodb/backups:/data/backups \
  ztimson/mongodb:latest
Description
MongoDB wiht integrated backups
Readme 49 KiB
Languages
Shell 86.4%
Dockerfile 13.6%