> For the complete documentation index, see [llms.txt](https://docs.percona.com/percona-clustersync-for-mongodb/llms.txt).

# Percona ClusterSync for MongoDB commands

## Overview

Percona ClusterSync for MongoDB is a replication tool for MongoDB clusters. It provides commands to manage and monitor the replication process between source and target MongoDB clusters.

## Commands

### Common flags

The following flag is available on all subcommands:

| Name     | Description                                                                                                                                                            |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--port` | Port number of the running PCSM server to connect to (default: `2242`). Use this when the server is listening on a non-default port (e.g., `pcsm status --port 3000`). |

### version

Display the current version of Percona ClusterSync for MongoDB.

```bash
$ pcsm version
```

### status

Get the status of the replication process.

```bash
$ pcsm status
```

If the PCSM server is running on a non-default port, specify it with `--port` flag:

```bash
$ pcsm status --port 3000
```

### start

Starts cluster replication.

```bash
$ pcsm start
```

To start a filtered replication, pass the namespaces (databases and collections) that you want to include/exclude from replication.

```bash
$ pcsm start \
--include-namespaces="db1.collection1,db2.collection2" \
--exclude-namespaces="db3.collection3"
```

To include or exclude a specific database and all collections it includes, pass it in the format `mydb.*`.

Available flags:

| Name                               | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--include-namespaces`             | Replicate only the specified namespaces. Multiple namespaces are supported as a comma separated list. The number of namespaces to specify is unlimited                                                                                                                                                                                                                                                                                                         |
| `--exclude-namespaces`             | Replicate everything except the specified namespaces. Multiple namespaces are supported as a comma separated list. The number of namespaces to specify is unlimited. When both `--include-namespaces` and `--exclude-namespaces` flags are specified, the exclude filters take precedence. For example, if the `--include-namespaces` includes `db1.*` and `--exclude-namespaces` has `db1.users`, PCSM syncs all collections of `db1` **except** `db1.users`. |
| `--clone-num-parallel-collections` | Number of collections to copy in parallel during clone.                                                                                                                                                                                                                                                                                                                                                                                                        |
| `--clone-num-read-workers`         | Number of read workers that read collection segments from the source. Shared for all collections.                                                                                                                                                                                                                                                                                                                                                              |
| `--clone-num-insert-workers`       | Number of insert workers that write batches to the target. Shared for all collections.                                                                                                                                                                                                                                                                                                                                                                         |
| `--clone-segment-size`             | Defines the size of each clone segment processed during the initial clone phase.                                                                                                                                                                                                                                                                                                                                                                               |
| `--clone-skip-presplit`            | Skips pre-splitting collections on the sharded target. PCSM still shards each collection with the source shard key but keeps the initial chunk layout that MongoDB creates. Default: `false`. Available starting with version 1.1.0. See [Skip pre-splitting](https://docs.percona.com/percona-clustersync-for-mongodb/sharding.md#skip-pre-splitting).                                                                                                        |
| `--target-write-concern`           | Sets the write concern for data written to the target. Use `majority` or a number from `1` to `2147483647`. `0` and custom named write concerns aren’t allowed. Works only with `pcsm start`. Default: `majority`. Available starting with version 1.1.0. See [Configure target write concern](https://docs.percona.com/percona-clustersync-for-mongodb/install/usage.md#configure-target-write-concern) for usage and rollback risks.                         |
| `--repl-num-workers`               | Controls how many concurrent replication worker goroutines PCSM uses to apply DML (insert/update/replace/delete) events to the target cluster.                                                                                                                                                                                                                                                                                                                 |
| `--repl-change-stream-batch-size`  | Sets the maximum number of change stream events PCSM will request and read from MongoDB per batch while streaming changes from the source cluster.                                                                                                                                                                                                                                                                                                             |
| `--repl-event-queue-size`          | Controls the size of the internal event queue used by the replication subsystem.                                                                                                                                                                                                                                                                                                                                                                               |
| `--repl-worker-queue-size`         | Defines the maximum number of replication events that each replication worker thread can queue before processing                                                                                                                                                                                                                                                                                                                                               |
| `--repl-bulk-ops-size`             | Defines the maximum number of operations that can be grouped together into a single bulk apply batch during replication.                                                                                                                                                                                                                                                                                                                                       |

### reset

Resets the `PCSM` state and deletes the metadata collections from target deployment. After the command execution, you must restart the `PCSM` service and start the data replication from scratch. Read more about the flow in [Troubleshooting guide](https://docs.percona.com/percona-clustersync-for-mongodb/troubleshooting.md)

```bash
$ pcsm reset --target
```

### finalize

Finalize cluster replication.

```bash
$ pcsm finalize
```

### pause

Pause cluster replication.

```bash
$ pcsm pause
```

### resume

Resume cluster replication.

```bash
$ pcsm resume
```

Available flags:

| Name             | Description                                    |
| ---------------- | ---------------------------------------------- |
| `--from-failure` | Resume replication from the last failure point |
