.bat file to generate backup and restore in PostgreSQL

1

I am creating .bat files to perform the backup and restore of a database in PostgreSQL I use windows 10 and pg 9.4

I execute the following command to perform the backup

set PGUSER=postgres
set PGPASSWORD=postgres123

"C:/Program Files/PostgreSQL/9.4/bin\"pg_dump.exe --host localhost --port 5432 --format custom --blobs --verbose --file "D:\bkp.sql" "dbsibcom"

It works perfectly.

And to perform the restore I have the following command

set PGUSER=postgres

set PGPASSWORD=postgres123
"C:/Program Files/PostgreSQL/9.4/bin\pg_restore.exe -i -h localhost -p 5432 -c -d "testrestore" -v " D:\bkp.sql"

I create the bat file and try to restore it, it just opens and closes the screen quickly and does not work.

Is there something wrong or another method to restore?

Do I have to give some permission for pg to have access to my backup file or something?

Issue

I also tried these commands to try to perform the restore and it does not work

set PGUSER=postgres
set PGPASSWORD=postgres123 

C:/Program Files/PostgreSQL/9.4/bin\pg_restore.exe --host localhost --port 5432 --username "postgres" --dbname "testrestore"   --verbose "D:\bkp.sql"
    
asked by anonymous 27.10.2017 / 00:26

1 answer

4

Considering:

  • The name of the database as: minha_database
  • The backup file as: C:\bkp\backup_database.dump
  • PostgreSQL 9.1 installation in% with%
  

To backup:

C:\Progra~2\PostgreSQL.1\bin\pg_dump -h servidor -p 5432 -U postgres --inserts -c -f C:\bkp\backup_database.dump minha_database
  

To restore:

C:\Progra~2\PostgreSQL.1\bin\psql -U postgres -d minha_database -f C:\bkp\backup_database.dump
  • You can hold the C:\Program Files (x86)\PostgreSQL command to not prompt for the password and automate the execution.

  • You can put a command set PGPASSWORD=postgres123 at the end of pause to see what error occurs.

  • In your environment, the bin \ path will be: .bat . Use this path to place the commands.

  • The dump file will be generated in sql, plain text, without any protection / encryption.

27.10.2017 / 03:15