Skip to content

Rate this page
Thanks for your feedback
Thank you! The feedback has been submitted.

Get free database assistance or contact our experts for personalized support.

Make a selective logical backup

Before you start

Before taking a backup, verify PBM is installed and running.

  1. Install and set up Percona Backup for MongoDB
  2. Check that pbm agent is running with the pbm status command
  3. Check that all pbm-agents and PBM CLI have the same version. Otherwise we cannot guarantee successful backups and data consistency in them.

    To check the version, run the following commands:

Procedure

Version added: 2.0.0

Before you start, read about selective backups known limitations.

To make a selective backup, run the pbm backup command and provide the value for the –ns flag in the format . The –ns flag value is case sensitive. For example, to back up the “Payments” collection, run the following command:

pbm backup --ns=customers.payments
To back up the Invoices database and all collections that it includes, run the pbm backup command as follows:

pbm backup --ns=invoices.*
To back up multiple namespaces, specify them as a comma-separated list for the –ns flag: <db1.col1>,<db2.*>,<db3.*>. The number of namespaces to specify is unlimited.

Selective backup with users and roles

Version added: 2.13.0

Overview

Percona Backup for MongoDB allows you to create selective backups of databases and collections, including the users and roles defined within the database. This ensures that access control is restored along with the data.

To back up a specific namespace and include users and roles:

Warning

Including users and roles (--with-users-and-roles) isn’t supported for collection-level backups (for example, --ns="db.collection"). To include users and roles, you must back up entire databases only, using --ns="db.*". As a result, mixed patterns like --ns="db1.*,db2.*,db3.col" will fail because db3.col targets a single collection.

pbm backup --ns="mydb.*" --with-users-and-roles

Where:

  • --ns="mydb.*" specifies the namespace (all collections in mydb).

  • --with-users-and-roles includes all users and custom roles defined in mydb in the backup.

What happens under the hood?
  • Percona Backup for MongoDB captures all collections within mydb.
  • Percona Backup for MongoDB filters the users and roles for entities where the db field matches mydb.
  • Global administrative roles or users defined in other databases are excluded.

Next steps

List backups Make a restore


Last update: March 3, 2026
Created: March 3, 2026