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

Restoring the Apostrophe database from backup #4092

Closed
programarivm opened this issue Mar 15, 2023 · 10 comments
Closed

Restoring the Apostrophe database from backup #4092

programarivm opened this issue Mar 15, 2023 · 10 comments
Labels

Comments

@programarivm
Copy link

programarivm commented Mar 15, 2023

Hi there,

I've created my first Apostrophe site. As a newbie, I'd expect the docs to describe how to dump and load a MongoDB 4.4 database in a one-liner command.

Example:

Thank you,

@BoDonkey
Copy link
Contributor

BoDonkey commented Mar 15, 2023

Hey @programarivm,
Congrats!
You can take a look at the large amount of documentation for MongoDB.
https://www.mongodb.com/basics/backup-and-restore
We will try and put together a small tutorial soon.
Cheers,
Bob

@programarivm
Copy link
Author

Thanks for the swift response @BoDonkey. I think it should be a one-liner command for MongoDB 4.4. One reason to stay away from MongoDB 5 is it requires CPU support for AVX instructions. See turnkeylinux/tracker#1724

@BoDonkey
Copy link
Contributor

I guess it all depends on your hosting model. Many of our clients use Atlas, so their host server for the Apostrophe instance(s) doesn't matter as much.
With regards to the "one-liner" -> Don't mongorestore and mongodump fulfill that?

@programarivm
Copy link
Author

This is what I'd do to dump the database after Setting up Apostrophe.

mongodump -h localhost:27017 -d "apos-app" -u "my-user" -p password
2023-03-15T11:18:03.696+0100	Failed: can't create session: could not connect to server: connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

Not too sure if it is correct.

@programarivm
Copy link
Author

This one did the trick.

mongodump --db "apos-app"
2023-03-15T11:29:27.027+0100	writing apos-app.aposDocs to dump/apos-app/aposDocs.bson
2023-03-15T11:29:27.029+0100	writing apos-app.aposMigrations to dump/apos-app/aposMigrations.bson
2023-03-15T11:29:27.029+0100	writing apos-app.sessions to dump/apos-app/sessions.bson
2023-03-15T11:29:27.035+0100	done dumping apos-app.aposMigrations (21 documents)
2023-03-15T11:29:27.035+0100	done dumping apos-app.aposDocs (7 documents)
2023-03-15T11:29:27.036+0100	done dumping apos-app.sessions (0 documents)
2023-03-15T11:29:27.036+0100	writing apos-app.aposAttachments to dump/apos-app/aposAttachments.bson
2023-03-15T11:29:27.036+0100	writing apos-app.aposBearerTokens to dump/apos-app/aposBearerTokens.bson
2023-03-15T11:29:27.036+0100	writing apos-app.aposCache to dump/apos-app/aposCache.bson
2023-03-15T11:29:27.037+0100	done dumping apos-app.aposAttachments (0 documents)
2023-03-15T11:29:27.037+0100	writing apos-app.aposLocks to dump/apos-app/aposLocks.bson
2023-03-15T11:29:27.038+0100	done dumping apos-app.aposCache (0 documents)
2023-03-15T11:29:27.038+0100	done dumping apos-app.aposLocks (0 documents)
2023-03-15T11:29:27.038+0100	done dumping apos-app.aposBearerTokens (0 documents)
2023-03-15T11:29:27.039+0100	writing apos-app.aposNotifications to dump/apos-app/aposNotifications.bson
2023-03-15T11:29:27.039+0100	done dumping apos-app.aposNotifications (0 documents)
2023-03-15T11:29:27.043+0100	writing apos-app.aposUsersSafe to dump/apos-app/aposUsersSafe.bson
2023-03-15T11:29:27.044+0100	done dumping apos-app.aposUsersSafe (1 document)

For further information:

@programarivm
Copy link
Author

programarivm commented Mar 15, 2023

Now I'm having trouble to restore my database. It seems as if something may be wrong with using hyphens in a MongoDB database name:

Dev teams may be tempted to use hyphens in their database names like "apos-app" or "a3-boilerplate" causing unexpected issues.

@programarivm
Copy link
Author

Finally this is how I am restoring the database.

mongorestore --db myapp dump/myapp 

Remember, it is more convenient to not use hyphens in the database name.

I hope this helps.

@boutell
Copy link
Member

boutell commented Mar 15, 2023

We use database names without hyphens on a regular basis btw, with all supported MongoDB versions.

I recommend the --archive option of mongodump and mongorestore, and passing a URI to those tools rather than individual parameters, but it works the other way too.

@programarivm
Copy link
Author

programarivm commented Mar 15, 2023

BTW @BoDonkey, I was wondering if these two commands could be run in the root folder of the Apostrophe site:

Dump:

mongodump --db myapp

Restore:

mongorestore --db myapp dump/myapp

If so, does it make sense to mkdir a dump folder? What about adding the following lines to the .gitignore file?

...
# Restore the database from backup
/dump/*
!/dump/.gitkeep

@boutell
Copy link
Member

boutell commented Mar 15, 2023 via email

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

No branches or pull requests

3 participants