Jon Garrido Martin GIS Developer

GIS Developer Freelance

Automated Postgresql 9.4 Backup on Windows

By jongarrido | October 7, 2015 | 0 Comment

How to perform a dayly backup of a postgresql database on a windows server.

This post it’s an update of this one. On this case this steps are refered to a 9.4 version of postgresql on a Windows Server 2012.

In a new folder, for example d:/pg_backup, you need to have the pg_dump.exe command available to run de . For this purpose you need to create a bin folder with the next libraries (and also pg_dump) inside :

libeay32.dll

libiconv-2.dll

libintl-8.dll

libpq.dll

pg_dump.exe

ssleay32.dll

zlib1.dll

These files are available at your postgresql instalation folder C:\path\to\posgresql-9.4\bin

Then you need to create a batch file in your d:/pg_backup folder like this. You can name it as mydbbackup.bat.

@echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
set datestr=%month%_%day%_%year%
echo datestr is %datestr%

set BACKUP_FILE=<filename>_%datestr%.backup
echo backup file name is %BACKUP_FILE%
SET PGPASSWORD=<password>
echo on
d:\pg_backup\bin\pg_dump -i -h <host>-p 5432 -U <user>-F c -b -v -f %BACKUP_FILE% <dbname>

Here you must replece with your custom data: <filename>,<password>,<host><user><dbname>;.

Then you can add a new task in your windows sheduled tasks to run this script dayly.

 

That’s all

 

 

TAGS

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *