generated from ztimson/template
All checks were successful
Build and publish / Build Container (push) Successful in 13s
97 lines
3.5 KiB
Markdown
97 lines
3.5 KiB
Markdown
<!-- Header -->
|
|
<div id="top" align="center">
|
|
<br />
|
|
|
|
<!-- Logo -->
|
|
<img src="https://git.zakscode.com/repo-avatars/07b972bff6cb72ac002083726471fff9b2396e2f50a6be3b0529271a629f9228" alt="Logo" width="200" height="200">
|
|
|
|
<!-- Title -->
|
|
|
|
### MongoDB
|
|
|
|
<!-- Description -->
|
|
MongoDB + Backups & Retention
|
|
|
|
<!-- Repo badges -->
|
|
[](https://git.zakscode.com/ztimson/mongodb/tags)
|
|
[](https://git.zakscode.com/ztimson/mongodb/pulls)
|
|
[](https://git.zakscode.com/ztimson/mongodb/issues)
|
|
|
|
<!-- Links -->
|
|
|
|
---
|
|
<div>
|
|
<a href="https://git.zakscode.com/ztimson/mongodb/wiki" target="_blank">Documentation</a>
|
|
• <a href="https://git.zakscode.com/ztimson/mongodb/releases" target="_blank">Release Notes</a>
|
|
• <a href="https://git.zakscode.com/ztimson/mongodb/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
|
• <a href="https://git.zakscode.com/ztimson/mongodb/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
|
</div>
|
|
|
|
---
|
|
</div>
|
|
|
|
## 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 that will be backedup | `$MONGO_INITDB_DATABASE` | `admin` | |
|
|
| `BACKUP_RETENTION` | Number of backups to keep | - | `7` |
|
|
|
|
### Built With
|
|
|
|
[](https://docker.com/)
|
|
[](https://www.mongodb.com/)
|
|
|
|
## Setup
|
|
|
|
<details>
|
|
<summary>
|
|
<h3 id="production" style="display: inline">
|
|
Production
|
|
</h3>
|
|
</summary>
|
|
|
|
#### Prerequisites
|
|
|
|
- [Docker](https://docs.docker.com/install/)
|
|
|
|
#### Instructions
|
|
|
|
1. Run the docker image:
|
|
|
|
```shell
|
|
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
|
|
```
|
|
|
|
</details>
|