Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Can I backup/restore a database in a sql script?

From: Erik Jones <erik(at)myemma(dot)com>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>, pgsql-admin(at)postgresql(dot)org
Subject: Re: [GENERAL] Can I backup/restore a database in a sql script?
Date: 2007-06-22 17:24:50
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-adminpgsql-general
On Jun 22, 2007, at 4:09 AM, Richard Huxton wrote:

> Joost Kraaijeveld wrote:
>> Hi,
>> I want to write a sql script in which I backup a database and restore
>> a new (altered) version of that database. Is that possible? If so ,
>> can anyone give me an example of how to do that?
>> I can run it from any command prompt (psql -U postgres template1 <
>> my_db.backup)    but I would like it to run from psql (which should
>> give me 1 script for all platforms I must do this: Windows, FreeBSD
>> and Debian)
> You can restore using just psql (because pg_dump can produce an sql  
> file to be processed). I don't know of any way to backup a database  
> that doesn't use pg_dump.

You could script a PITR backup and recovery procedure but I doubt any  
given single solution would be portable between Windows, Debian, and  
FreeBSD given the differences in filesystems and filesystem tools  
although I suppose with a lot of careful work it may be possible.   
See the chapter on Backup and Restore in the manual for the details  
of how PITR works ( 

Erik Jones

Software Developer | Emma®
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at

In response to

pgsql-admin by date

Next:From: Chris HooverDate: 2007-06-22 18:14:43
Subject: How to move a tablespace?
Previous:From: Tom LaneDate: 2007-06-22 17:24:47
Subject: Re: REINDEX question

pgsql-general by date

Next:From: Tom LaneDate: 2007-06-22 17:28:16
Subject: Re: Embedded C++ with ecpg?
Previous:From: Jasbinder Singh BaliDate: 2007-06-22 17:20:55
Subject: SPI using perl

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group