Skip to content

mongoshield export

Export a backup as mongodump output for mongorestore.

Terminal window
mongoshield export [backup] [options]

Writes a backup as a mongodump directory (restore with mongorestore --dir) or archive (restore with mongorestore --archive), decrypted and checked. With --gzip the files are gzipped like mongodump --gzip (then restore with mongorestore --gzip). Time-series collections become mongorestore's bucket documents; users and roles are written for mongorestore --restoreDbUsersAndRoles.

ArgumentDescription
[backup]optionalBackup id, or "latest" (default)
OptionDescription
--format <directory|archive|jsonl|csv>mongodump directory or archive, or one collection as JSON Lines or CSV. Default: directory.
--output <path>New directory or file; "-" writes an archive, JSONL or CSV to stdout.
--namespace <db.collection>With jsonl/csv: the collection to export.
--fields <a,b.c>With jsonl/csv: dotted field paths (required for csv: its columns).
--filter <json>With jsonl/csv: only documents matching this Extended JSON filter.
--ejson <relaxed|canonical>With jsonl/csv: Extended JSON flavour (canonical keeps every BSON type). Default: relaxed.
--gzipgzip the output, like mongodump --gzip.
--from <storage-url>Where backups are stored: ./dir, file:///abs, s3://bucket/prefix (default: config).
--include <pattern>Only these namespaces, e.g. app.* or app.users. Repeatable.
--exclude <pattern>Skip these namespaces, e.g. *.audit_*. Repeatable.
--identity-file <path>age identity file for encrypted backups (from mongoshield keygen). Repeatable.
--passphrase-env <VAR>Read the encryption passphrase from this environment variable.

The global options (--config, --json, --quiet, --verbose, --no-color, --yes) work here too.

Export the latest backup to a directory for mongorestore:

Terminal window
mongoshield export --output ./dump && mongorestore --dir ./dump

Export one database of an encrypted backup as a gzipped archive:

Terminal window
mongoshield export latest --include 'app.*' --format archive --gzip --output app.archive.gz --identity-file ~/keys/backup.key

Pipe straight into mongorestore:

Terminal window
mongoshield export --format archive --output - | mongorestore --uri $TARGET --archive

One collection as CSV for a spreadsheet:

Terminal window
mongoshield export --format csv --namespace app.users --fields _id,name,address.city --output users.csv