pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-admin@postgresql.org
Subject: Re: Can I backup/restore a database in a sql script?
Date: Fri, 22 Jun 2007 11:13:09 +0300
Message-ID: <200706221113.10105.achill@matrix.gatewaynet.com> (raw)
In-Reply-To: <A3D1526C98B7C1409A687E0943EAC41060600F@obelix.askesis.nl>
References: <A3D1526C98B7C1409A687E0943EAC41060600F@obelix.askesis.nl>

Στις Παρασκευή 22 Ιούνιος 2007 10:59, ο/η Joost Kraaijeveld έγραψε:
> 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)
>

With "\!" you can execute shell commands.
So you could probably
\c template1
\! pg_dump your_db > your_db.sql
\! some_processing your_db.sql > your_db_altered.sql
DROP DATABSE your_db
CREATE DATABSE your_db
\i your_db_altered.sql

I dont know if the \! escape works for windows, and in any case pg_dump, 
some_processing programs must be in the PATH for Unix/Windows

Debian/FreeBSD behaviour is exactly the same, it is on windows that you should 
try to make it work.

> TIA
>
> Joost
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq

-- 
Achilleas Mantzios



view thread (4+ messages)  latest in thread

Message-ID: <200706221113.10105.achill@matrix.gatewaynet.com>
Permalink:  ../200706221113.10105.achill@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/200706221113.10105.achill@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: achill@matrix.gatewaynet.com
  Subject: Re: Can I backup/restore a database in a sql script?
  In-Reply-To: <200706221113.10105.achill@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox