Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 96D2E9FB5A5 for ; Fri, 22 Jun 2007 05:13:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 55160-06 for ; Fri, 22 Jun 2007 05:13:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 394B39FB548 for ; Fri, 22 Jun 2007 05:13:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by svr4.postgresql.org (Postfix) with ESMTP id 26B3B5AF88E for ; Fri, 22 Jun 2007 08:13:15 +0000 (GMT) Received: from smadev.internal.net (localhost [127.0.0.1]) by smadev.internal.net (8.13.6/8.13.6) with ESMTP id l5M8DAi6029173 for ; Fri, 22 Jun 2007 11:13:10 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Received: by smadev.internal.net (8.13.6/8.13.6/Submit) id l5M8DAkt029172 for pgsql-admin@postgresql.org; Fri, 22 Jun 2007 11:13:10 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt 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 User-Agent: KMail/1.9.3 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706221113.10105.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.033 tagged_above=0 required=5 tests=AWL=-0.103, BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200706/240 X-Sequence-Number: 25908 =CE=A3=CF=84=CE=B9=CF=82 =CE=A0=CE=B1=CF=81=CE=B1=CF=83=CE=BA=CE=B5=CF=85= =CE=AE 22 =CE=99=CE=BF=CF=8D=CE=BD=CE=B9=CE=BF=CF=82 2007 10:59, =CE=BF/=CE= =B7 Joost Kraaijeveld =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > Hi, > > I want to write a sql script in which I backup a database and restore a n= ew > (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,=20 some_processing programs must be in the PATH for Unix/Windows Debian/FreeBSD behaviour is exactly the same, it is on windows that you sho= uld=20 try to make it work. > TIA > > Joost > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq =2D-=20 Achilleas Mantzios