Skip to content

Backup mongodb databases - also as a container

License

Notifications You must be signed in to change notification settings

DoctorEvidence/automongobackup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

automongobackup

A simple bash script to backup Mongo databases.

Source code is published at github.com/DoctorEvidence/automongobackup .

Image is published at doctorevidence/automongobackup .

Features

  • Backup a full cluster
  • Specify retention time in days
  • Choose a specific day per month to keep forever

Usage

As a standalone script

# Download the script
curl https://raw.githubusercontent.com/DoctorEvidence/automongobackup/main/automongobackup.sh --output automongobackup.sh && \
chmod +x automongobackup.sh

# Use a connection uri for mongo
export MONGO_URL='mongodb://user@password@localhost:27017/?tls=true&authSource=admin'

# Test connection using mongosh
mongosh $MONGO_URL

# Choose the day of month to keep backups forever
export BACKUP_DAY_TO_KEEP="03"
# Choose backup path
export DB_BACKUP_PATH="dbackup"

# Run the backup
./automongobackup.sh

As a docker container

You can run periodic mongodb backups with swarm-cronjob

services:

  mongo-backup:
    image: docker.io/mongo-backup:latest
    environment:
      MONGO_URL: "mongodb://user@password@my-mongodb:27017/?tls=true&authSource=admin"
      DB_BACKUP_PATH: /backups
    deploy:
      mode: replicated
      replicas: 0
      labels:
        - "swarm.cronjob.enable=true"
        - "swarm.cronjob.schedule=0 7 * * *"
        - "swarm.cronjob.skip-running=false"
      restart_policy:
        # https://github.com/crazy-max/swarm-cronjob/issues/44
        condition: on-failure
        max_attempts: 3
     volumes:
       /path/to/backup:/backups

How to build and release

You will need to have docker-engine installed or podman.

docker login docker.io -u doctorevidence

# Build image for arm64 and amd64
docker buildx build --no-cache \
--platform linux/arm64 \
--platform linux/amd64 \
-t docker.io/doctorevidence/automongobackup:6 . \
--push

# push image to docker registry
docker push docker.io/doctorevidence/automongobackup:6

About

Backup mongodb databases - also as a container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published