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 --dumpParameters:
--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,720htimeout: mongodb dump timeouttmpPath: path to store tempory backup before s3 uploadmongodb:host: MongoDB host (ignored ifMONGO_URIis set)port: MongoDB port (ignored ifMONGO_URIis set)
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
# host and port can be omitted when MONGO_URI environment variable is provided
createDump:
maxRetries: 3
retryDelay: 60
bucket:
s3:
name: bucket-name
region: eu-west-1Example of instant backup start :
kubectl apply -f ./k8s/backup.yaml
# then watch status
watch kubectl -n tools get jobsmongodb_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 argumentsMONGO_URI: MongoDB connection string URI (overrides host, port, user and password)
AWS_ACCESS_KEY_ID: AWS access key ID (optional)AWS_SECRET_ACCESS_KEY: AWS secret access key (optional)
When running in Kubernetes with a service account that has the appropriate bucket permissions (for example IAM Roles for Service Accounts), the application automatically uses the service account credentials and these variables are not required.
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-backups --config /tmp/config/config.yaml
#With Docker compose
docker-compose -f docker-compose.yaml up
docker exec n9-backup-dev mongodb-backups --config ./home/config.yaml