hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.77k forks source link

Hasura Graphql Database Backup #6334

Open kirannuclear opened 3 years ago

kirannuclear commented 3 years ago

Hi. Please explain me How can I take the backup of database ?. I have tried by refering the documentation and other sources

curl --location --request POST "http://localhost:8080/v1/graphql/pg_dump" --header "x-hasura-admin-secret: myadminsecretkey" --header "Content-Type: application/json" --data-raw "{  "opts": ["-O", "-x", "--schema", "public", "--schema", "auth"],  "clean_output": true}" -o backup.sql

when i run this command I get backup.sql which contains "{"path":"$","error":"resource does not exist","code":"not-found"}".
But i want to export all table data in an sql file. Thanks in Advance

ayuryshev commented 3 years ago

Is this intentional: "--schema", "auth" ?

You really has such schema and need to backup it?

kirannuclear commented 3 years ago

how can I know my schema name in hasura ? please explain me.

ayuryshev commented 3 years ago

That's a postgresql related not hasura itself.

Every database has schema public which I see in parameters: "--schema", "public"

When you connect hasura to a database 2 new schemas are created: hdb_catalog and hdb_views.

But schema auth - is not something standard/ what you see frequently. Not a single database that I manage now has such schema.

So my question is:

I see: -data-raw "{ "opts": ["-O", "-x", "--schema", "public", "--schema", "auth"]

I suppose that you're trying to dump schema auth. Do your database has this schema?

Maybe resource not exists is about non-existent schema?

What would be if you change to -data-raw "{ "opts": ["-O", "-x", "--schema", "public"] ?

kirannuclear commented 3 years ago

when I ran with -data-raw "{ "opts": ["-O", "-x", "--schema", "public"] , i got the same issue.

tirumaraiselvan commented 3 years ago

The API endpoint should be http://localhost:8080/v1alpha1/pg_dump

See: https://hasura.io/docs/1.0/graphql/core/api-reference/pgdump.html#disabling-pg-dump-api

dohomi commented 2 years ago

this does not seem to work for Hasura Cloud based databases. Is there an alternative?

FDiskas commented 2 years ago

What is source?

Request

POST http://localhost:8080/v1alpha1/pg_dump HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
  "opts": ["-O", "-x", "--schema", "public"],
  "clean_output": true,
  "source": "postgres"
}

Response:

HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Date: Tue, 18 Oct 2022 20:02:33 GMT
Server: Warp/3.3.19
Content-Type: application/json; charset=utf-8

{
  "code": "not-found",
  "error": "source \"postgres\" not found",
  "path": "$"
}

Db structure

image