Wednesday, May 13, 2015
0 comments

PostgreSQL DB Backup using .bat file and task Scheduler and Resore using CMD

3:10 PM
PostgreSQL DB Backup using .bat file and task Scheduler and Resore using CMD

1. Create .bat file using following code:
@ECHO OFF
@setlocal enableextensions
@cd /d "%~dp0"

SET PGPATH=C:\"Program Files"\PostgreSQL\9.1\bin\
SET SVPATH=f:\
SET PRJDB=demo
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 DBDUMP=%PRJDB%_%d%_%t%.sql
@ECHO OFF
%PGPATH%pg_dump -h localhost -p 5432 -U postgres %PRJDB% > %SVPATH%%DBDUMP%

echo Backup Taken Complete %SVPATH%%DBDUMP%
pause
2. Crate task task scheduler and assign the .bat file to run.
DB back .sql format DONE.

DB Backup using CMD:

If Acces dispaled the give full permission to specidied path OR Run as Administrator the CMD
DB Backup will be saved on bin path.

DB Restore
Open PG console from tools menu of PostgreSQL then follow:
http://www.thegeekstuff.com/2009/01/how-to-backup-and-restore-postgres-database-using-pg_dump-and-psql/

0 comments:

 
Toggle Footer