Create MongoDB snapshots to an encrypted S3 bucket. Handle snapshot restoration from backup. Can be easily monitored by Prometheus.
# Launch server & scheduler
./mongodb-backups --config ./config.yaml
# List backup
./mongodb-backups --config ./config.yaml --list
# Restore specific backup
./mongodb-backups --config ./config.yaml --restore [id] --args '--drop'
# Restore last backup
./mongodb-backups --config ./config.yaml --restore-last --args '--drop'
# Arbitrary dump
./mongodb-backups --config ./config.yaml --dump
Parameters:
--config
: Config path. Default./config.yaml
--list
: list backups--restore
: Restore specific backup from snapshot--restore-last
: Restore last backup from snaphost--args
: MongoDB restore additional arguments
name
: backup nameschedule
: cronjob schedule. Example:0 * * * *
retention
: max retention. Example:2d
,1w
,1M
,720h
timeout
: mongodb dump timeouttmpPath
: path to store tempory backup before s3 uploadmongodb
:host
: MongoDB hostport
: MongoDB port
bucket
(fill only one option):s3
:name
: bucket nameregion
: bucket region
gs
:name
: bucket name
minio
:name
: bucket namehost
: bucket hostname (and port if required)region
: (optional) bucket regionssl
: (optional) Enable SSL
Example:
name: integration
retention: 1w
schedule: '0 0 * * *'
timeout: 15m
tmpPath: /tmp
mongodb:
host: localhost
port: 27017
bucket:
s3:
name: bucket-name
region: eu-west-1
Example of instant backup start :
kubectl apply -f ./k8s/backup.yaml
# then watch status
watch kubectl -n tools get jobs
mongodb_backups_scheduler_backup_total
: Total number of backups (status: success / error)mongodb_backups_scheduler_retention_total
: Total number of successful retention cleanup (status: success / error)mongodb_backups_scheduler_bucket_snapshot_count
: Current number of snapshots in the bucketmongodb_backups_scheduler_snapshot_size
: Last snapshot size in bytesmongodb_backups_scheduler_snapshot_latency
: Last snapshot duration in secondsmongodb_backups_scheduler_last_successful_snaphot
: Last successful snapshot timestamp
All metrics have the label name
equals to the config name
key.
MONGODB_USER
: MongoDB userMONGODB_PASSWORD
: MongoDB passwordMONGODB_AUTH_ARGS
: MongoDB additional authentication arguments
AWS_ACCESS_KEY_ID
: AWS secret key IDAWS_SECRET_ACCESS_KEY
: AWS secret access key
MINIO_ACCESS_KEY_ID
: Minio secret key IDMINIO_SECRET_ACCESS_KEY
: Minio secret access key
S3 policy example:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::my-bucket-name",
"arn:aws:s3:::my-bucket-name/*"
]
}
]
}
The changelog is generated by git-chglog
You must follow the given commit syntax: <item>: <description>
Generate the changelog:
git-chglog -o CHANGELOG.md
# With Go
go run ./cmd --config config.yaml
# With Docker
docker build -t n9-backup .
docker run --rm -v /tmp/config:/tmp/config n9-backup mongodb-backup --config /tmp/config/config.yaml