Skip to content

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:

mongoshield.config.ts
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.

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"

The database to back up (and the default restore target).

Type: object

KeyTypeDescription
source.uristring requiredMongoDB connection string

Where backups live: a URL like s3://bucket/prefix, a path, or an adapter object.

Type: string or StorageAdapter (required)

Compression for new backups. Defaults to zstd.

Type: "zstd" \| "gzip" \| "none"

Encryption for new backups. Omit to store backups unencrypted.

Type: object

KeyTypeDescription
encryption.recipientsstring[] (at least 1)Public age recipients (age1…). Recommended for unattended backups.
encryption.passphrasestringA passphrase instead of recipients. Cannot be combined with recipients.
encryption.kmsobject[] (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" requiredWhich cloud KMS: AWS KMS, Google Cloud KMS or Azure Key Vault.
encryption.kms[].keystring requiredThe key: an AWS key ARN or alias, a GCP key resource name (projects/…/cryptoKeys/…), or an Azure Key Vault key URL.

Secrets used to read encrypted backups (restore, verify --deep).

Type: object

KeyTypeDescription
decryption.identitiesstring[]age identities (AGE-SECRET-KEY-1…). Prefer identityFiles so keys stay out of config.
decryption.identityFilesstring[]Paths to files containing age identities, one per line (age's key file format).
decryption.passphrasestringThe passphrase of passphrase-encrypted backups.

Defaults for mongoshield backup.

Type: object

KeyTypeDescription
backup.includestring[]Namespace patterns to back up, e.g. app.*. Default: everything.
backup.excludestring[]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.parallelisminteger, 1–64Collections (and parts) backed up at the same time. Defaults to 4.
backup.retainDaysinteger, > 0, ≤ 36500Make every backup write-once for this many days (S3 Object Lock, GCS object retention, Azure immutability). The storage must support it.
backup.labelsobject of stringLabels attached to every backup, e.g. { env: "prod" }.
backup.partSizeBytesinteger, > 0Split collections larger than this (raw BSON bytes) into parts. Defaults to 256 MiB.
backup.maxDurationMsinteger, > 0Stop 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.readPreferenceTagsarray of object of stringTag sets for readPreference, e.g. [{ use: "backup" }, {}].
backup.maxDocumentsPerSecondnumber, > 0Read at most this many documents per second (all collections together).
backup.maxBytesPerSecondnumber, > 0Read at most this many raw BSON bytes per second (all collections together).
backup.usersAndRolesbooleanAlso back up users and custom roles (with their password hashes: encrypt such backups). Off by default. See BackupOptions.includeUsersAndRoles.
backup.incrementalobjectIncremental 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.fullEveryDaysnumber, > 0, ≤ 366Start a new chain once its full backup is this many days old. Defaults to 7.
backup.incremental.maxChainLengthinteger, 1–100000Start a new chain once it holds this many incrementals. No limit by default.

Policy used by mongoshield prune.

Type: object

KeyTypeDescription
retention.lastinteger, > 0Keep the N newest backups.
retention.hourlyinteger, > 0Keep the newest backup from each of the last N hours / days / weeks / months / years.
retention.dailyinteger, > 0Keep the newest backup from each of the last N days that have one (UTC).
retention.weeklyinteger, > 0Keep the newest backup from each of the last N ISO weeks that have one.
retention.monthlyinteger, > 0Keep the newest backup from each of the last N months that have one.
retention.yearlyinteger, > 0Keep the newest backup from each of the last N years that have one.
retention.minVerifiedinteger, ≥ 0Never prune below this many verified backups.
retention.scopeLabelsobject of stringLabels 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.

Running backups on a schedule (mongoshield schedule).

Type: object

KeyTypeDescription
schedule.cronstring requiredStandard 5-field cron expression, e.g. "15 3 * * *" for 03:15 every day.
schedule.timezonestringIANA 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.jitterSecondsinteger, 0–3600Random delay before each run, so many deployments don't all start at once.
schedule.retriesinteger, 0–10Retries after a failed run, with exponential backoff. Defaults to 2.
schedule.timeoutMinutesnumber, > 0Abort a run that takes longer than this.
schedule.prunebooleanPrune 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).

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

KeyTypeDescription
journal.segmentSecondsinteger, 1–86400Close a segment after this many seconds: the normal worst-case RPO. Default 300.
journal.segmentBytesinteger, ≥ 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.

Where to send success and failure notifications.

Type: object[]

KeyTypeDescription
notify[].type"webhook" | "slack" | "discord" requiredwebhook (a JSON POST), slack or discord (incoming webhooks).
notify[].urlURL requiredThe webhook URL. Treat it as a secret.
notify[].onarray of "success" | "failure" (at least 1)Which outcomes to report. Defaults to failures only.

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

KeyTypeDescription
drill.targetUristring requiredA scratch deployment to restore into. Never the production source.
drill.sampleinteger, ≥ 0Documents per collection to compare byte for byte with the backup.
drill.assertionsstringA .ts/.js file whose default export checks the restored data.
drill.prefixstringPrefix 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

KeyTypeDescription
guard.maxDocumentDropPercentnumber, 0–100Fail if any collection lost more than this percentage of its documents.
guard.maxSizeDropPercentnumber, 0–100Fail if the backup's total raw size dropped by more than this percentage.
guard.failOnMissingCollectionbooleanFail 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.

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)

KeyTypeDescription
replicate[].storagestring or StorageAdapter requiredA storage URL (s3://offsite-bucket/prod) or adapter, like storage.
replicate[].retainDaysinteger, > 0, ≤ 36500Make the copies write-once there for this many days (needs object lock).

The GDPR erasure ledger (src/extras/erasure.ts).

Type: object

KeyTypeDescription
erasures.secretstringKeys the hashes of erasure filters, so the ledger cannot confirm guessed emails. At least 16 characters; keep it with your other secrets.