Scheduling automatic backup of postgres database in windows

/ Published in: DOS Batch
Save to your folder(s)

Copy this code and paste it in your HTML
  1. 1. Create a file to store the connection password (Find the attached sample pgpass.conf)
  2. Refer:
  3. 2. Create a bat file with the following contents
  4. @echo off
  5. SET PGPASSFILE=D:\PgBackup\pgpass.conf
  7. for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
  8. set dow=%%i
  9. set month=%%j
  10. set day=%%k
  11. set year=%%l
  12. )
  13. set datestr=%month%_%day%_%year%
  15. set BACKUP_FILE=%datestr%.backup
  18. "D:\Program Files\PostgreSQL\9.0\bin\pg_dumpall.exe" --host=localhost --username=postgres --no-password --database=postgres --oids --file=D:\PgBackup\%BACKUP_FILE%
  19. Make necessary changes in the parameters and paths
  20. Refer:
  21. 3. Schedule the bat file to execute at required time using windows task scheduler
  22. Refer:


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.