Sign inSign up

megahertz/mongo-backup-alpine

By megahertz

•Updated over 8 years ago

Simple MongoDB backup service

Image
1

957

megahertz/mongo-backup-alpine repository overview

⁠mongo-backup-alpine

Simple MongoDB backup service in Docker built on alpine image⁠ and Supercronic⁠

⁠Usage

⁠Run the backup service
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:
NameDefaultDescription
MONGO_URL(required)Connection string to MongoDB
BACKUP_COMMAND/usr/local/bin/backupYou can override it to pass mongodump args
BACKUP_LIFETIME10Delete 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⁠

⁠Run using Compose
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:

docker-compose run --rm mongo-backup restore 2018-01-01-00-00-00.gz --drop

⁠Scripts

⁠Make backup manually

backup [mongodump args]

Example:

docker run -e MONGO_URL=mongodb://host \
  -v /backup:/data/backup megahertz/mongo-backup-alpine backup
⁠Get the list of existing backups

list

Example:

docker run -v /backup:/data/backup megahertz/mongo-backup-alpine list
⁠Restore from backup

restore BACKUP_FILE [mongorestore args]

Example:

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.

Tag summary

Content type

Image

Digest

Size

9.8 MB

Last updated

over 8 years ago

docker pull megahertz/mongo-backup-alpine