I am looking for a solution - a script to automate the process of taking backup of a database in PostgreSQL. As of now I do it manually, that is by right clicking on the db and clicking the backup option. I did some research and ended up with a script which solves the issue pretty much, ie:
@ECHO OFF
@setlocal enableextensions
@cd /d "%~dp0"
SET PGPATH=C:\PostgreSQL\9.4\bin\
SET SVPATH=d:\
SET PRJDB=Test
SET DBUSR=postgres
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%i IN ('DATE /T') DO SET d=%%i-%%j-%%k
FOR /F "TOKENS=1,2,3 DELIMS=: " %%i IN ('TIME /T') DO SET t=%%i%%j%%k
SET pg_dump=%PRJDB%_%d%_%t%.backup
@ECHO OFF
%PGPATH%pg_dump -h localhost -p 5432 -U postgres %PRJDB% > %SVPATH%%pg_dump%
echo Backup Taken Complete %SVPATH%%pg_dump%
pause
It did take the backup, but the file generated was a sql file, though I did change the extension to .backup
. As a result, if I need to restore the DB, and try to restore from the file generated it is not possible. Can someone please provide me with a solution to this problem.
Thanks in advance.
Schedule Task
, here is an example thewindowsclub.com/…