Restore Postgre . BAT

Asked

Viewed 251 times

0

I’m making a .Bat for Backup and one for Restore of a bank in Postegresql, the .Bat Backup works perfectly, however, Restore gives problem by database owning data.

Would have some way to start the .Bat of Restore excluding all tables and only leaving the BD not to make a mistake?

chdir C:\Program Files\PostgreSQL\9.4\bin

ECHO "C:\Program Files\PostgreSQL\9.4\bin"
ECHO.
SET caminho=C:\
SET database=DATABASE
SET PGPASSWORD=1234

FOR /F "TOKENS=1-4 delims=/ " %%I IN ('DATE /t') DO SET data=%%I-%%J-%%K
FOR /F "TOKENS=1-2* delims=: " %%A IN ('TIME /t') DO SET hora=%%Ah%%Bm

ECHO ***********************************************
ECHO Aguarde, realizando o Restore do Banco de Dados
ECHO ***********************************************
ECHO.

pg_restore -U postgres -d %database% -1 %caminho%%database%_%data%.backup

PAUSE
  • Use the --clean option in pg_dump which will generate the appropriate commands to clear your base before restoring it.

1 answer

0

Not would be the case to apply a drop before?


  • Update: getting date in layout faster.

Check the information of that reply link

@echo off & setlocal enabledelayedexpansion & cd /d "%~dp0" & set "_cmd=Get Day^,Month^,Year^,Hour^,Minute^"
cls & mode con cols=70 lines=8 & color 9F & title <nul & title Restore do  Banco PostegreSQL

rem :|  Cria variavel para data adicionando 0 para dia/mes/hora/minuto menores que 10... 
for /f "tokens=1-5 delims= " %%a in ('wmic Path Win32_LocalTime !_cmd! ^| findstr /r "[0-9]"') do (
     set "_y=%%e" & set "_m=0%%d" &  set "_d=0%%a" & set "_tt=0%%b" & set "_tm=0%%c" 
     set "_dt=!_y: =!_!_m:~-2!_!_d:~-2!" & set "_hora=!_tt:~-2!h!_tm:~-2!m"
    ) && set "_database=database" & set "_usuario=usuario" & set "_pgpassword=1234"

chdir /d "C:\Program Files\PostgreSQL\9.4\bin" && echo/"%cd%"

echo/ ***********************************************
echo/ aguarde, realizando o restore do banco de dados
echo/ ***********************************************

.\psql -U !_usuario! -c "drop database protodb"
.\psql -c psql pg_restore -u postgres -d !_database! -1 !_caminho!!database!_!_data!_!hora!.backup

timeout /t -1 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.