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: http://www.postgresql.org/docs/9.0/static/libpq-pgpass.html
  3. 2. Create a bat file with the following contents
  4. @echo off
  5. SET PGPASSFILE=D:\PgBackup\pgpass.conf
  6.  
  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%
  14.  
  15. set BACKUP_FILE=%datestr%.backup
  16.  
  17.  
  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: http://wiki.postgresql.org/wiki/Automated_Backup_on_Windows#Using_.pgpass_and_pgdumpall.2C_same_file
  21. 3. Schedule the bat file to execute at required time using windows task scheduler
  22. Refer: http://windows.microsoft.com/en-US/windows7/schedule-a-task

URL: http://www.postgresql.org/docs/9.0/static/libpq-pgpass.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.