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.
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
Related
I am doing pg_dump using -
pg_dump -U <username> -h <host> <database> > backup.sql
pg_dump is working fine.
I am trying to do pg_restore doing -
pg_restore -U <username> -h <host> -d <databse> backup.sql
Then it is showing pg_restore: error: input file does not appear to be a valid archive
I have checked many StackOverflow answers about this, but I could not figure out anything. Please help me. Thanks in advance.
Update : As per comments we can not use pg_restore for .sql files. Actually I have an restriction that I must have to restore the database using pg_restore command. Can you please give the pg_dump command using which I can restore that using pg_restore?
You created a plain format dump, which is an SQL file. You have to restore plain-format dumps with psql:
psql -U <username> -h <host> -d <databse> -f backup.sql
pg_restore is used to restore dumps in all other formats. You get dumps in other formats by using the appropriate -F option with pg_dump: for example, -F c produces a custom format dump.
If you want to restore a plain format dump with a client other than psql, you have to create it with the option --inserts.
I connect to my remote database in Azure ok using psql , then i run the below command but i cant find the file? I want to send the backup file to my windows hard disk
pg_dump -E utf8 --clean --if-exists --no-owner --verbose --no-password -f > c:\backup_file.tar
I created a serverless Aurora-Postgresql RDS cluster on AWS in a VPC, and a Linux EC2 instance to access it from, also in the VPC. I have a binary file dump.bin I dumped from a prior database with pg_dump -Fc that I want to use to restore the new database to the state of the old one. Inside the EC2 instance, I can run pg_dump against the new database with no issues, which creates a dump of the unconfigured database. I can even run pg_restore --version, and it prints pg_restore (PostgreSQL) 10.17. But when I run pg_restore with arguments to connect to the database and actually try to commit the restore, the program simply hangs indefinitely with no output.
This is the command I am running:
pg_restore --host=<rds-instance-dns-host>.us-east-2.rds.amazonaws.com --port=5432 --username=postgres --file=dump.bin --verbose
I think you mistook --file option for FILE argument in pg_restore:
$ pg_restore --help
pg_restore restores a PostgreSQL database from an archive created by pg_dump.
Usage:
pg_restore [OPTION]... [FILE]
…
-f, --file=FILENAME output file name (- for stdout)
…
Similarily from man pg_restore:
-f filename
--file=filename
Specify output file for generated script,
or for the listing when used with -l.
Use - for stdout.
The --file tells where to write output, an SQL script that would restore the database if run on it. It is not about from which file to restore. So your pg_restore does not know from which file to read, so it tries to read from its standard input.
So your command should rather look like this:
pg_restore --host=<rds-instance-dns-host>.us-east-2.rds.amazonaws.com \
--port=5432 --username=postgres --verbose dump.bin
Or, as I'd recommend, use parallel restore and output to a file, so you can examine it later in case of any errors:
pg_restore --host=<rds-instance-dns-host>.us-east-2.rds.amazonaws.com \
--jobs=8 --port=5432 --username=postgres --verbose dump.bin \
> /tmp/pg_restore.log 2>&1
I'm using the following command to backup my database (PostgreSQL 11.8):
pg_basebackup -D "C:\\temp" -F tar -X f -z -P -U myUser
And the following to restore:
I manually unpack the base.tar.gz => base.tar
pg_restore -h localhost -W -U myUser -c -C -d myDatabase -F tar -v "C:\\temp\\base.tar"
This results in the following error:
pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive
What am I doing wrong?
Also, I tried different versions of the restore (only data, etc.) but of course the missing header file issue persists.
Thanks for your help!
You cannot use pg_basebackup and pg_restore together:
pg_basebackup is a physical backup tool
pg_restore can only be used with a logical backup created by pg_dump.
There is no single PostgreSQL command to restore a backup created with pg_basebackup.
To restore a physical backup see https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-PITR-RECOVERY
I'm working with Heroku's new PGBackups functionality and I have used the public-url command to download a backup. The file isn't in a format that I'm used to. I was expecting a pg_dump file that I could open with Vim or another text editor. Does anyone know what the files that result from public-url are?
The pg_dump -Fc "custom" format
c
custom
Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default.
It sends you a file that you can use with the pg_restore command.
For example, I can download the file with:
curl -o /tmp/latest.dump <database_url>
And then restore with:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <destination_database_name> /tmp/latest.dump