graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Hasura Graphql Database Backup

Open kirannuclear opened this issue 4 years ago • 6 comments

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

kirannuclear avatar Dec 12 '20 17:12 kirannuclear

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

You really has such schema and need to backup it?

ayuryshev avatar Dec 12 '20 21:12 ayuryshev

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

kirannuclear avatar Dec 13 '20 05:12 kirannuclear

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"] ?

ayuryshev avatar Dec 13 '20 06:12 ayuryshev

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

kirannuclear avatar Dec 13 '20 06:12 kirannuclear

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

tirumaraiselvan avatar Dec 18 '20 09:12 tirumaraiselvan

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

dohomi avatar Aug 05 '22 07:08 dohomi

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

FDiskas avatar Oct 18 '22 20:10 FDiskas