mongoshield backup
Back up MongoDB to storage.
mongoshield backup [options]Dumps every collection (or the ones selected with --include/--exclude), with indexes and options, compressed and optionally encrypted. The backup only counts as complete once its manifest is written, so an interrupted run never looks like a good backup.
Options
Section titled “Options”| Option | Description |
|---|---|
--uri <mongodb-uri> | Connection string (default: config source.uri, MONGOSHIELD_URI or MONGODB_URI). |
--to <storage-url> | Where to store the backup: ./dir, file:///abs, s3://bucket/prefix. |
--include <pattern> | Only these namespaces, e.g. app.* or app.users. Repeatable. |
--exclude <pattern> | Skip these namespaces, e.g. *.audit_*. Repeatable. |
--compression <zstd|gzip|none> | Compression algorithm. Default: zstd (gzip on Node.js without zstd). |
--recipient <age1…> | Encrypt for this age public key (from mongoshield keygen). Repeatable. |
--passphrase-env <VAR> | Read the encryption passphrase from this environment variable. |
--consistency <auto|none|snapshot|converge> | Point-in-time consistency across collections. Default: auto. |
--label <key=value> | Attach a label to the backup, e.g. env=prod. Repeatable. |
--parallelism <n> | Collections (and parts) backed up at the same time (1–64). Default: 4. |
--part-size <size> | Split collections larger than this into parts, e.g. 256MiB or 1GiB. Default: 256MiB. |
--max-duration <duration> | Stop after about this long and save a checkpoint, e.g. 14m (implies consistency none). |
--resume <id|latest|auto> | Continue a checkpointed backup (auto: the newest one with these options, else start anew). |
--read-preference <primary|primaryPreferred|secondary|secondaryPreferred|nearest> | Which members to read from. Default: secondaryPreferred. |
--max-docs-per-second <n> | Read at most this many documents per second. |
--max-bytes-per-second <size> | Read at most this many bytes per second, e.g. 50MiB. |
--retain-days <days> | Make the backup write-once for this many days (S3 Object Lock, GCS, Azure). |
--users-and-roles | Also back up users and custom roles (password hashes included: encrypt the backup). |
--incremental | Store only the changes since the newest backup of this deployment and selection (a chain: full → incremental → …). |
--from <backup-id> | With --incremental: continue this backup instead of the newest one. |
The global options (--config, --json, --quiet,
--verbose, --no-color, --yes) work here too.
Examples
Section titled “Examples”Back up everything to a local directory:
mongoshield backup --uri mongodb://localhost:27017 --to ./backupsBack up one database to S3, encrypted for a public key:
mongoshield backup --include 'app.*' --to s3://acme-backups/prod --recipient age1…Capture the new backup id in a script:
ID=$(mongoshield backup --quiet)Back up in 14-minute slices (e.g. on AWS Lambda), then continue:
mongoshield backup --max-duration 14m && mongoshield backup --resume latest --max-duration 14mGo easy on production: read from secondaries at most 50 MiB/s:
mongoshield backup --read-preference secondary --max-bytes-per-second 50MiBA full backup on Sunday, then only the changes since the previous backup:
mongoshield backup && mongoshield backup --incrementalMongoShield is MIT licensed and is not affiliated with, endorsed by or sponsored by MongoDB, Inc. MongoDB is a trademark of MongoDB, Inc.Privacy policy