
### MongoDB
MongoDB + Backups & Retention
[](https://git.zakscode.com/ztimson/mongodb/tags)
[](https://git.zakscode.com/ztimson/mongodb/pulls)
[](https://git.zakscode.com/ztimson/mongodb/issues)
---
---
## Table of Contents
- [MongoDB](#top)
- [About](#about)
- [Environment Variables](#environment-variables)
- [Built With](#built-with)
- [Setup](#setup)
- [Production](#production)
## 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
[](https://docker.com/)
[](https://www.mongodb.com/)
## Setup