Backup script for PostgreSQL with zip support (Windows)

Simplest solution for backing up PostgreSQL databases. With this bat file you can dump one database to a file and compress it using 7-zip.

PS. If you want a date in your filename simply add %date% var to it’s string.
PS2. Of course check your paths before complaining it does not work 😛

@echo off
:: Global config
SET PG_BIN="C:\Program Files\PostgreSQL\9.6\bin\pg_dump.exe"
SET PG_HOST=localhost
SET PG_PORT=5432
SET PG_PATH="C:\inetpub\temporary_backups"
SET ZIP_BIN="C:\Program Files\7-Zip\7z.exe"

:: Database config for 
SET PG_DATABASE=your_database_name
SET PG_USER=your_database_user
SET PGPASSWORD=youe_database_password

SET PG_FILENAME=%PG_PATH%\%PG_DATABASE%_postgres.sql
%PG_BIN% -h %PG_HOST% -p %PG_PORT% -U %PG_USER% %PG_DATABASE% > "%PG_FILENAME%"
%ZIP_BIN% a "%PG_FILENAME:~0,-4%.zip" "%PG_FILENAME%" &DEL "%PG_FILENAME%"

@echo Backup Taken Complete %PG_PATH%%PG_FILENAME%

PHP reading problem with files larger than 2 GB

If you’ll ever have problem with opening (fopen) and reading (fread) files larger than 2 GB in your PHP script. Check your version of scripting engine. In my case switching to 64 bit solved the problem. Please mind that this error is very hard to debug because PHP does not log anything (same as MS IIS) in such case. It simply resets client connection…