Ikteaja hsan
Ikteaja hsan

Reputation: 61

pg_restore [archiver] did not find magic string in file header

I take backup my azure postgresql flexible server to azure file share within blob storage using the command which is working fine and storing backup at azure file share. The command is running from azure vm and the azure fileshare is mounted on a vm

pg_dump -Fc -v --host=postgressqlflex-server.postgres.database.azure.com --dbname=elo-strangler-service-database --username=abc -f test$date.sql

But when i am trying to restore the backup form azure fileshare using the command bellow which running on same azure vm. its raising error

pg_restore -v --no-owner -h psqlflex-server.postgres.database.azure.com -U abc -Fc -j 4 -d testbackup1669029901.sql
Error

> pg_restore: [archiver] did not find magic string in file header

is it the reason of the two different name of the database for backup and restore?

Could you please help me to solve this issue.

Upvotes: 3

Views: 16152

Answers (3)

Swarna Anipindi
Swarna Anipindi

Reputation: 954

Typically, pg_restore does not know what format of dump to use, resulting in the following error:

Did not find magic string in file header.

In this scenario, -d represents a database, not a .sql file.

-f Selects the formatted output. format can be one of the outputs of a SQL script file.

Updated command to restore the database from .sql file:

pg_restore -v --no-owner -h psqlflex-server.postgres.database.azure.com -U abc -Fc -j 4 -f testbackup1669029901.sql

Upvotes: 4

Sarvar Nishonboyev
Sarvar Nishonboyev

Reputation: 13110

Instead use psql command:

psql -h localhost -p 5432 -U postgres -d <db_name> -f file_path

Upvotes: 5

Guillermo Espert
Guillermo Espert

Reputation: 1310

In my case the problem was related with the operator > under Windows PowerShell to output to a file. When you use -f filename option on pg_dump the file is saved correctly and pg_restore works fine. I used in both -F c option.

Upvotes: 1

Related Questions