Backup database

How can we backup or export/import our database, say for instance i want to back up user databse from one server and move it to another, I dont see any way of doing this yet?

can anyone please help?

1 Like

I don’t know if there is a way to do import/export for the database now.
What I was able to do was to use a cloud function that would return all users info from the database:

Moralis.Cloud.define("getUsers", async function (request) {
  const query = new Parse.Query("User");
  query.limit(1000);
  const result = await query.find({ useMasterKey: true });
  return result;
});

this is a suitable work around thank you.

would like to see something officially implemented by the Moralis team eventually.

1 Like

Hi @phyx1u5

Currently backup function for users is not supported.

You can use the solution from @cryptokid

When you say ‘backup function not supported’, does that mean that the Moralis db is not backed up at all at the moment?
How would I handle that when I’m going live? For sure I need a regular automated backup solution. Would be nice to know the plans around that :slight_smile:

Hey @matiyin

I mean, you can’t make it from the dashboard now.
Moralis does backups and all data is safe.

2 Likes

Hi @Yomoo

Moralis does backups and all data is safe.

You said that you have backups, but please let me confirm the following points.

  1. How often are you backing up?
  2. Is it a Point-in-Time Backup?
  3. When I want to restore, what action should I take to restore?

You should make your own backups. We make hourly backups for the database. You can connect directly to mongo db and dump the entire database so that you can restore it yourself.

can you please get your youtube team to do a video for this procedure? I’m sure many people want to know, including myself

there is more info here on how to connect directly to mongo db:
https://docs.moralis.io/moralis-dapp/database/direct_access#connect-directly-to-the-mongo-db-instance-that-runs-on-your-moralis-server

so we can use this with a interface tool lile mongodb compass?

yes, you can use it with mongodb compass

I have confirmed that I can back up using mongodump myself, but I cannot do point-in-time backups because I get an error if I specify the --oplog option.

How can I do point-in-time backup by myself?

what you mean with point in time backups?

The correct term is point-in-time snapshot.

Point-in-time snapshots are needed for the following reasons
Without the -oplog option when taking an online backup, if a collection is added or changed while mongodump is running, it will be inconsistent with other collections.
Point in time snapshot allows you to back up the collection data consistent with the timing of mongodump execution.

What is the error that you get?

I get the following error

Failed: error getting oplog start: error getting recent oplog entry: mongo: no documents in result

I checked and oplog only works with replicaset, does that mean Moralis doesn’t have replicaset?
https://www.mongodb.com/community/forums/t/schedule-mongodb-backup-to-s3-using-kubernetes-cronjob/101886

Looks like you can check that: Troubleshoot Replica Sets — MongoDB Manual

I connected to the MongoDb IP of Moralis.Server with mongosh and ran rs.status(), and here is what I got
test> rs.status()
MongoServerError: not running with --replSet

Looks like you can check that: Troubleshoot Replica Sets — MongoDB Manual

I am aware that --oplog cannot be used in mongodump because there is no replicaset in Moralis’ MongoDb. What should I check with Trubleshoot above?

can you add a request in roadmap.moralis.io about this?