Make a selective logical backup¶
Before you start¶
Before taking a backup, verify PBM is installed and running.
- Install and set up Percona Backup for MongoDB
- Check that
pbm agentis running with thepbm statuscommand -
Check that all
pbm-agentsand 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:
pbm statusto check the version of pbm-agentspbm versionto check the version of PBM CLI.
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
pbm backup --ns=customers.payments
pbm backup command as follows:
pbm backup --ns=invoices.*
<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 inmydb). -
--with-users-and-roles→ includes all users and custom roles defined inmydbin 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
dbfield matchesmydb. - Global administrative roles or users defined in other databases are excluded.
Next steps¶
Useful links¶
Created: March 3, 2026