A docker image to back up a MongoDB instance to Google Cloud Storage.
The container runs a cron that backs up the database using mongodump
in a gzipped archive (--gzip --archive
) at 6am UTC (by default) before pushing to GS.
MONGO_HOST
- Host of MongoDB instanceMONGO_DATABASE
- DB to backupGS_PROJECT_ID
- GCE project IDGS_SERVICE_EMAIL
- Email of service account to useGS_BACKUP_BUCKET
- Cloud storage bucket to push backup toCRON_SCHEUDLE
- Optional, defauls to0 6 * * *
The backup script expects a service account auth JSON file in /backup/service-account.json
.
docker run --name backup \
-v /your/service-account.json:/backup/service-account.json:ro \
-e MONGO_HOST=db \
-e MONGO_DATABASE=documents \
-e GS_PROJECT_ID=my-project \
-e [email protected] \
-e GS_BACKUP_BUCKET=my-bucket \
--network default \
--link service_db:db \
tmannherz/mongo-gce-backup
services:
db:
image: mongo
restart: always
volumes:
- db_data:/data/db
db_backup:
image: tmannherz/mongo-gce-backup
depends_on:
- db
restart: always
environment:
MONGO_HOST: db
MONGO_DATABASE: documents
GS_PROJECT_ID: my-project
GS_SERVICE_EMAIL: [email protected]
GS_BACKUP_BUCKET: my-bucket
secrets:
- service_account
secrets:
service_account:
file: service_account.json