https://github.com/megahertz/mongo-backup-alpine
Simple MongoDB backup service in Docker
https://github.com/megahertz/mongo-backup-alpine
alpine backup docker mongodb tools
Last synced: about 2 months ago
JSON representation
Simple MongoDB backup service in Docker
- Host: GitHub
- URL: https://github.com/megahertz/mongo-backup-alpine
- Owner: megahertz
- License: mit
- Created: 2018-02-27T13:11:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-04T10:56:14.000Z (about 8 years ago)
- Last Synced: 2025-03-16T19:55:25.451Z (about 1 year ago)
- Topics: alpine, backup, docker, mongodb, tools
- Language: Shell
- Homepage: https://hub.docker.com/r/megahertz/mongo-backup-alpine/
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongo-backup-alpine
[](https://microbadger.com/images/megahertz/mongo-backup-alpine "Get your own image badge on microbadger.com")
Simple MongoDB backup service in Docker built on
[alpine image](https://hub.docker.com/_/alpine/)
and [Supercronic](https://github.com/aptible/supercronic)
## Usage
### Run the backup service
```sh
docker run -e MONGO_URL=mongodb://host \
-v /backup:/data/backup megahertz/mongo-backup-alpine
```
#### Volumes
The image writes backups to /data/backup, so you need to mount this
path on a host machine to store backups.
#### Environment variables:
Name | Default | Description
----------------|-----------------------|------------
MONGO_URL | (required) | Connection string to MongoDB
BACKUP_COMMAND | /usr/local/bin/backup | You can override it to pass mongodump args
BACKUP_LIFETIME | 10 | Delete backups older than N days
BACKUP_PATTERN | "+%Y-%m-%d-%H-%M-%S" | Pattern for backup name
BACKUP_SCHEDULE | "0 4 * * *" | How often to make backups, crontab format
By default, the service makes backup each day at 4am. If you're not
familiar with crontab, you can
[check the examples](https://crontab.guru/examples.html)
### Run using Compose
```yaml
version: "3"
services:
mongo:
image: mvertes/alpine-mongo:3.4.7-0
networks:
- mynet
restart: always
volumes:
- ./db:/data/db
mongo-backup:
image: megahertz/mongo-backup-alpine:0.5
depends_on:
- mongo
environment:
- MONGO_URL=mongodb://mongo/my_db
networks:
- mynet
restart: always
volumes:
- ./backup:/data/backup
networks:
mynet:
```
With this docker-compose.yml, you can restore the database using:
```sh
docker-compose run --rm mongo-backup restore 2018-01-01-00-00-00.gz --drop
```
## Scripts
### Make backup manually
`backup [mongodump args]`
Example:
```sh
docker run -e MONGO_URL=mongodb://host \
-v /backup:/data/backup megahertz/mongo-backup-alpine backup
```
### Get the list of existing backups
`list`
Example:
```sh
docker run -v /backup:/data/backup megahertz/mongo-backup-alpine list
```
### Restore from backup
`restore BACKUP_FILE [mongorestore args]`
Example:
```sh
docker run -e MONGO_URL=mongodb://host \
-v /backup:/data/backup megahertz/mongo-backup-alpine \
restore 2018-02-01-04-00-00.gz --drop
```
## License
Licensed under MIT.