A common community question is how to make a temporary copy of all messages in a JetStream stream, especially before deleting and recreating the original stream or its consumers.
There is not a single universal answer because “copy” can mean different things:
Each approach has different behavior around stream names, consumer state, retention policy, sequence numbers, and operational risk.
If your goal is to preserve a stream before replacing it, JetStream backup and restore is usually the first option to consider.
For example, the NATS CLI can back up a stream while excluding its consumer definitions. A real invocation also names the stream and a destination path for the backup:
nats stream backup <stream> <destination-path> --no-consumersBy default a backup includes consumer definitions and state. The --no-consumers flag excludes them, which is useful when you want to preserve stream messages but intentionally avoid restoring consumers, for example when you suspect a consumer configuration or state issue.
A typical high-level workflow is:
The validation step matters. A backup is only operationally useful if you have already proven that restore works in an environment that is close enough to the one you care about.
One important detail: restore recreates the stream from the backup, so the target stream must not already exist when you restore. You cannot restore on top of a live stream with the same name, which is why the workflow deletes the original first. If you have already recreated the original stream and then want to load older messages back into it, backup and restore is not the right tool for that step. Use a source or a manual replay instead.
Do not assume that backup and restore can be used as a same-cluster “copy and rename” operation.
In practice, the NATS CLI restore path may reject changing the stream name during restore with an error like:
1stream names may not be changed during restoreThat means backup and restore is best treated as a way to restore the backed-up stream, not as a general mechanism to create mystream_backup from mystream in the same account.
If you need a temporary stream with a different name in the same environment, consider a mirror, a source, or a controlled republish workflow instead.
If the original stream uses interest-based retention, think carefully before restoring it without consumers.
With interest retention, messages are retained based on consumer interest. If you restore only the stream data and omit consumers, there may be no active interest to keep those messages. Depending on the exact stream configuration and server behavior, that can defeat the purpose of restoring messages into an interest-retained stream with no consumers.
Practical guidance:
--no-consumers, verify what happens to restored messages before deleting the original.The safest answer is not to rely on assumptions here. Test the lifecycle end to end: backup, restore, consumer recreation, message availability, and cleanup.
JetStream can keep one stream populated from another. There are two related primitives, and the difference matters for this use case:
For a read-only copy with a different name that stays close to a faithful duplicate, a mirror is the better fit because it preserves sequence numbers. For example, conceptually:
1mystream -> original stream2mystream_backup -> mirror of mystreamA mirror catches up from existing messages and then continues tracking new messages from the original stream. This makes it useful for temporary backup-like workflows where a point-in-time CLI restore is not the right shape.
A typical approach is:
mystream_backup, that mirrors the original stream.Step 5 needs the most care. Because a mirror stream cannot also accept direct writes, you generally cannot simply convert the backup mirror into the new production stream. Mirror configuration is fixed when the stream is created and generally cannot be added or removed by updating an existing stream, though this can depend on your NATS version. Two cleaner patterns are:
source pointing at the backup copy. Once it has caught up, remove the source so the stream keeps only its direct subjects. Unlike a mirror, sources can be added and removed by updating a stream.Test whichever pattern you choose, because the exact behavior depends on your stream configuration and NATS version.
Another fallback is to read all messages from the source stream and publish them into a new stream yourself.
This can work, but it is not the same thing as a native stream copy. When you republish messages, the destination stream receives new messages with its own stream sequence and storage metadata. You should also consider:
Manual republishing is often reasonable for controlled migrations, small recovery tasks, or custom transformations. It is riskier if you need an exact operational copy of the stream’s state.
Use this decision table as a starting point:
| Goal | Consider | Main caution |
|---|---|---|
| Restore the same stream after deletion | Backup and restore | Validate restore before deleting production data |
| Exclude consumer definitions | nats stream backup --no-consumers | Interest retention may not retain messages without consumers |
| Create a separate copy with a different name | Mirror or source | A mirror preserves sequences but takes no direct writes; a source re-sequences messages but can also take writes |
| Copy into a custom stream layout | Manual read and republish | Destination messages are newly published messages |
| Debug suspected consumer issues | Backup without consumers, then recreate consumers | Make sure stream retention will preserve messages |
For production or important data, use a conservative process:
The key point is that JetStream gives you multiple building blocks, but they are not interchangeable. Backup and restore is best for restoring the same stream under its original name. Mirrors and sources are better for maintaining a separate stream that continuously tracks another one. Manual republishing gives maximum control but creates new stream history.
Want help from the NATS experts? Meet with our architects to get help tailored to your use case and environment.



News and content from across the community