Postgre Backup Script

Posted on 2009-04-15
Last Modified: 2012-05-06
I have a postgre database that I am trying to set up automatic backups for. I have written a batch file below that creates a backup for me. The script creates the file fine, but the file is always -kb and does not contain any data. Any help would be greatly appreciated. I am running the batch file under administrator permissions and in the same service account as Postgre. Any help would be greatly appreciated.
@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=timetrex_%datestr%.backup

   echo backup file name is %BACKUP_FILE%

   SET PGPASSWORD=85473f83b

   echo on

   bin\pg_dump -i -h localhost -p 5433 -U timetrex -F c -b -v -f %BACKUP_FILE% timetrex

Open in new window

Question by:jpadkins49
    LVL 22

    Accepted Solution

    Is the script finding the pg_dump executable ?
    Try fully qualifying the pg_dump

    Also the database service has to be running for pg_dump to be able to connect to the database.
    Can you use command line interface
    psql timetrex
    before you run the script ?

    You are running pg_dump with verbose messages, so if it is being executed you should be getting some idea where it is having a problem
    LVL 1

    Author Comment

    I changed the file location in the script and that seemed work fine along with using the postgres account rather than the timetrex user. Thanks for the help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: ( This requires some add-o…
    Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
    Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now