Skip to main content
edited body; edited title
Source Link
frlan
  • 7.3k
  • 3
  • 36
  • 72

Automate Database backup in postgreSqlPostgreSQL

I am looking for a solution - a script to automate the process of taking backup of a database in postgreSqlPostgreSQL. As of now iI 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 iI did change the extension to .backup. As a result, if iI 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.

Automate Database backup in postgreSql

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.

Automate Database backup in PostgreSQL

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.

Source Link
Shruthi
  • 335
  • 1
  • 7
  • 29

Automate Database backup in postgreSql

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.