Files
mongodb/README.md
ztimson 2ed87ffdd6
All checks were successful
Build and publish / Build Container (push) Successful in 1m22s
Fixed backups & added replica recovery
2026-05-29 21:51:22 -04:00

4.0 KiB


Logo

MongoDB

MongoDB + Backups & Retention

Version Pull Requests Issues



Table of Contents

About

Custom MongoDB Docker image extending mongo:latest with automated backup functionality.

Installs cron to run scheduled mongodump operations with compression and retention management, while preserving all native MongoDB server functionality.

Backups can be manually triggered with: docker --exec -t mongodb backup

To restore a backup, uncompress it and use the official mongorestore

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

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