Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to backup all streams of a NATS Streaming Server? #213

Closed
hossainemruz opened this issue Aug 13, 2021 · 11 comments
Closed

How to backup all streams of a NATS Streaming Server? #213

hossainemruz opened this issue Aug 13, 2021 · 11 comments

Comments

@hossainemruz
Copy link

Problem:

I have to backup all the streams of my NATS streaming server. I don't know what streams are there. I want to backup all the streams into a single snapshot. Currently, we can backup only a single stream using the following command.

$ nats stream backup <stream-name> /backup/dir/<stream-name>.tgz

What I have tried so far:

I have tried providing a wildcard instead of <stream-name>. It does not work.

$ nats stream backup * /backup/dir/backup.tgz
nats: error: "*" is not a valid stream name, try --help

Possible Workaround:

At first, I can list all the streams using nats str ls command. Then, I can loop through all the streams and backup them individualy.

However, this does not satisfy my requirement as I want to backup all the streams into a single snapshot. My snapshot should represent a complete state of the NATS streaming server just not a single stream.

@ripienaar
Copy link
Collaborator

We do not have a way to do that, each stream goes into back up state independently, message ingest does not pause during snapshots so you'd never get a exact point in time snapshot.

You can shut one of the replicas assuming all is R3 or greater and back up its disk - I know not ideal.

@hossainemruz
Copy link
Author

Thank you @ripienaar for your response. Do you have any plan to support the workaround? For example, if the stream name is a wildcard, then the backup command will automatically find the respective streams and backup them. Probably, in a single *.tgz file but one file for each stream is also fine.

@ripienaar
Copy link
Collaborator

for stream in $(nats s ls -j|jq -r '.[]')
do
  nats stream backup ....
done

@hossainemruz
Copy link
Author

Yes. That's what I am planning for now. However, it would have been great if nats has built-in support for this use-case. We can contribute the feature if you are willing to accept.

@ripienaar
Copy link
Collaborator

yes, should be a easy thing to add to the stream backup command, I'd then take the supplied directory and do dir/<stream name>/backup files... so you get a series of stream backups in one dir. Today each backup has to be in a dir of its own

@hossainemruz
Copy link
Author

Let us know if you have bandwidth to do it or need any help from us. It's not an emergency.

Btw, thank you for the amazing works.

@ripienaar
Copy link
Collaborator

We'd love a contribution if you want to give it a go

@hossainemruz
Copy link
Author

Sure. Will do ASAP.

@joelhoisko
Copy link

Maybe an offtopic comment, but just so that I'm not going insane: this issue is about backing up streams in JetStream and not NATS Streaming Server (the precursor to JetStream) right? I'm asking, because I've been searching for information about backups/restores for NATS Streaming Server specifically and to my understanding the NATS Streaming Server doesn't have a concept of streams nor does it really work with the nats CLI tool either. Or am I missing something here?

@ripienaar
Copy link
Collaborator

ripienaar commented Sep 30, 2021

This issue relates to JetStream, not Streaming Server indeed. Given that Streaming Server is retiring, yes we did not add extensive support for it in the nats cli

@ripienaar
Copy link
Collaborator

We now have nats account backup that does this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants