Config file
The CLI reads mongoshield.config.ts (or .js, .mjs) from the current
directory, or the file given with --config. Write it with defineConfig for type checking:
import { defineConfig } from "mongoshield";
export default defineConfig({ source: { uri: process.env.MONGODB_URI }, storage: "s3://acme-backups/prod", encryption: { recipients: [process.env.BACKUP_PUBLIC_KEY] }, decryption: { identityFiles: ["./mongoshield-identity.txt"] }, backup: { exclude: ["*.sessions"] }, retention: { last: 3, daily: 7, weekly: 4, monthly: 12 },});Any value may be undefined in the file (an unset environment variable, say). Validation
runs after MONGOSHIELD_* environment variables and command-line flags are merged in, so
an error names what is actually missing. Unknown keys are rejected, which catches typos.
In the tables, a.b is a key inside a, and a[].b a key of each object in the array a.
preset
Section titled “preset”Defaults for a kind of deployment, applied under everything else the config, environment and flags set: "atlas-free" (Atlas Free / M0, legacy M2/M5) or "atlas-flex". See src/config/presets.ts and docs/guides/atlas-free-tier.md.
Type: "atlas-free" \| "atlas-flex"
source
Section titled “source”The database to back up (and the default restore target).
Type: object
| Key | Type | Description |
|---|---|---|
source.uri | string required | MongoDB connection string |
storage
Section titled “storage”Where backups live: a URL like s3://bucket/prefix, a path, or an adapter object.
Type: string or StorageAdapter (required)
compression
Section titled “compression”Compression for new backups. Defaults to zstd.
Type: "zstd" \| "gzip" \| "none"
encryption
Section titled “encryption”Encryption for new backups. Omit to store backups unencrypted.
Type: object
| Key | Type | Description |
|---|---|---|
encryption.recipients | string[] (at least 1) | Public age recipients (age1…). Recommended for unattended backups. |
encryption.passphrase | string | A passphrase instead of recipients. Cannot be combined with recipients. |
encryption.kms | object[] (at least 1) | Cloud KMS keys that protect each backup's key. Can be combined with recipients (recommended: keep one offline recipient as a recovery key). |
encryption.kms[].provider | "aws" | "gcp" | "azure" required | Which cloud KMS: AWS KMS, Google Cloud KMS or Azure Key Vault. |
encryption.kms[].key | string required | The key: an AWS key ARN or alias, a GCP key resource name (projects/…/cryptoKeys/…), or an Azure Key Vault key URL. |
decryption
Section titled “decryption”Secrets used to read encrypted backups (restore, verify --deep).
Type: object
| Key | Type | Description |
|---|---|---|
decryption.identities | string[] | age identities (AGE-SECRET-KEY-1…). Prefer identityFiles so keys stay out of config. |
decryption.identityFiles | string[] | Paths to files containing age identities, one per line (age's key file format). |
decryption.passphrase | string | The passphrase of passphrase-encrypted backups. |
backup
Section titled “backup”Defaults for mongoshield backup.
Type: object
| Key | Type | Description |
|---|---|---|
backup.include | string[] | Namespace patterns to back up, e.g. app.*. Default: everything. |
backup.exclude | string[] | Namespace patterns to leave out, e.g. *.sessions. |
backup.consistency | "auto" | "none" | "snapshot" | "converge" | Point-in-time consistency across collections. Defaults to auto (see Concepts → Consistency). |
backup.parallelism | integer, 1–64 | Collections (and parts) backed up at the same time. Defaults to 4. |
backup.retainDays | integer, > 0, ≤ 36500 | Make every backup write-once for this many days (S3 Object Lock, GCS object retention, Azure immutability). The storage must support it. |
backup.labels | object of string | Labels attached to every backup, e.g. { env: "prod" }. |
backup.partSizeBytes | integer, > 0 | Split collections larger than this (raw BSON bytes) into parts. Defaults to 256 MiB. |
backup.maxDurationMs | integer, > 0 | Stop after about this long and save a checkpoint; mongoshield run resumes it on its next invocation. Implies consistency "none". |
backup.readPreference | "primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest" | Where data is read from. Defaults to "secondaryPreferred". |
backup.readPreferenceTags | array of object of string | Tag sets for readPreference, e.g. [{ use: "backup" }, {}]. |
backup.maxDocumentsPerSecond | number, > 0 | Read at most this many documents per second (all collections together). |
backup.maxBytesPerSecond | number, > 0 | Read at most this many raw BSON bytes per second (all collections together). |
backup.usersAndRoles | boolean | Also back up users and custom roles (with their password hashes: encrypt such backups). Off by default. See BackupOptions.includeUsersAndRoles. |
backup.incremental | object | Incremental backups for scheduled runs (mongoshield run / schedule, console plans): each run stores only the changes since the previous backup, and a full backup starts a new chain when there is none to continue, the chain's full backup is older than fullEveryDays, or the chain reached maxChainLength. "Full weekly, incremental hourly" is schedule.cron: "0 * * * *" with incremental: { fullEveryDays: 7 }. See docs/guides/incremental-backups.md. |
backup.incremental.fullEveryDays | number, > 0, ≤ 366 | Start a new chain once its full backup is this many days old. Defaults to 7. |
backup.incremental.maxChainLength | integer, 1–100000 | Start a new chain once it holds this many incrementals. No limit by default. |
retention
Section titled “retention”Policy used by mongoshield prune.
Type: object
| Key | Type | Description |
|---|---|---|
retention.last | integer, > 0 | Keep the N newest backups. |
retention.hourly | integer, > 0 | Keep the newest backup from each of the last N hours / days / weeks / months / years. |
retention.daily | integer, > 0 | Keep the newest backup from each of the last N days that have one (UTC). |
retention.weekly | integer, > 0 | Keep the newest backup from each of the last N ISO weeks that have one. |
retention.monthly | integer, > 0 | Keep the newest backup from each of the last N months that have one. |
retention.yearly | integer, > 0 | Keep the newest backup from each of the last N years that have one. |
retention.minVerified | integer, ≥ 0 | Never prune below this many verified backups. |
retention.scopeLabels | object of string | Labels that mark this job's backups and scope its retention to them (together with the source's cluster). mongoshield run and schedule add them to every backup they write and prune only backups that carry all of them; mongoshield prune scopes by them too (unless --scope-label is given). Without them the scope is the mongoshield.shape label (the include/exclude selection), so two jobs with the same source and selection that share a storage location need different scope labels, e.g. { "mongoshield.plan": "nightly" }, or they prune each other's backups. |
schedule
Section titled “schedule”Running backups on a schedule (mongoshield schedule).
Type: object
| Key | Type | Description |
|---|---|---|
schedule.cron | string required | Standard 5-field cron expression, e.g. "15 3 * * *" for 03:15 every day. |
schedule.timezone | string | IANA time zone for the cron expression. Defaults to UTC. |
schedule.lock | "storage" | "mongo" | "none" | Prevents two schedulers (for example several app replicas) from running the same backup: "storage" (default) uses a lock object next to the backups, "mongo" a lock document in the source database, "none" no lock. |
schedule.jitterSeconds | integer, 0–3600 | Random delay before each run, so many deployments don't all start at once. |
schedule.retries | integer, 0–10 | Retries after a failed run, with exponential backoff. Defaults to 2. |
schedule.timeoutMinutes | number, > 0 | Abort a run that takes longer than this. |
schedule.prune | boolean | Prune with the retention policy after each successful backup. Defaults to true. |
schedule.verify | "none" | "fast" | "deep" | "drill" | Verify each new backup. Defaults to "fast". "drill" restores it into the scratch deployment configured in drill and checks it, which also measures how long a real restore takes (your RTO). |
journal
Section titled “journal”The change journal for point-in-time recovery (mongoshield journal start; its flags override these). See docs/guides/point-in-time-recovery.md.
Type: object
| Key | Type | Description |
|---|---|---|
journal.segmentSeconds | integer, 1–86400 | Close a segment after this many seconds: the normal worst-case RPO. Default 300. |
journal.segmentBytes | integer, ≥ 1024 | …or once it holds this many bytes of change data (at least 1 KiB). Default 64 MiB. |
journal.onGap | "backup" | "fail" | When change history is lost: take a new base backup (default), or stop the writer. |
notify
Section titled “notify”Where to send success and failure notifications.
Type: object[]
| Key | Type | Description |
|---|---|---|
notify[].type | "webhook" | "slack" | "discord" required | webhook (a JSON POST), slack or discord (incoming webhooks). |
notify[].url | URL required | The webhook URL. Treat it as a secret. |
notify[].on | array of "success" | "failure" (at least 1) | Which outcomes to report. Defaults to failures only. |
heartbeat
Section titled “heartbeat”A "dead man's switch" URL (healthchecks.io, Cronitor, Better Stack…). Pinged on success, and with /fail appended on failure, so the service alerts you when backups stop arriving.
Type: URL
Restore drills (mongoshield drill, schedule.verify: "drill").
Type: object
| Key | Type | Description |
|---|---|---|
drill.targetUri | string required | A scratch deployment to restore into. Never the production source. |
drill.sample | integer, ≥ 0 | Documents per collection to compare byte for byte with the backup. |
drill.assertions | string | A .ts/.js file whose default export checks the restored data. |
drill.prefix | string | Prefix of the temporary database names. Defaults to msdrill_. |
Refuse to commit a backup that looks like data was lost since the previous one.
Type: object
| Key | Type | Description |
|---|---|---|
guard.maxDocumentDropPercent | number, 0–100 | Fail if any collection lost more than this percentage of its documents. |
guard.maxSizeDropPercent | number, 0–100 | Fail if the backup's total raw size dropped by more than this percentage. |
guard.failOnMissingCollection | boolean | Fail if a collection present in the previous backup is missing. Defaults to true. |
guard.action | "fail" | "warn" | "fail" (default) refuses to commit the backup; "warn" only reports. |
replicate
Section titled “replicate”Copies of every new backup in other storage locations (3-2-1): mongoshield run replicates each successful backup to each target (src/extras/replicate.ts).
Type: object[] (at least 1)
| Key | Type | Description |
|---|---|---|
replicate[].storage | string or StorageAdapter required | A storage URL (s3://offsite-bucket/prod) or adapter, like storage. |
replicate[].retainDays | integer, > 0, ≤ 36500 | Make the copies write-once there for this many days (needs object lock). |
erasures
Section titled “erasures”The GDPR erasure ledger (src/extras/erasure.ts).
Type: object
| Key | Type | Description |
|---|---|---|
erasures.secret | string | Keys the hashes of erasure filters, so the ledger cannot confirm guessed emails. At least 16 characters; keep it with your other secrets. |
MongoShield is MIT licensed and is not affiliated with, endorsed by or sponsored by MongoDB, Inc. MongoDB is a trademark of MongoDB, Inc.Privacy policy