From: Sandro Santilli Date: Wed, 14 Dec 2011 07:59:43 +0000 (+0000) Subject: Add -v switch to postgis_restore.pl, tweak usage and debug output X-Git-Tag: 2.0.0alpha1~472 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f1bab3976764aa0341fb6a34618009100c3570b;p=postgis Add -v switch to postgis_restore.pl, tweak usage and debug output git-svn-id: http://svn.osgeo.org/postgis/trunk@8401 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/utils/postgis_restore.pl b/utils/postgis_restore.pl index a0a0cbc73..a0bb8ec86 100755 --- a/utils/postgis_restore.pl +++ b/utils/postgis_restore.pl @@ -31,16 +31,29 @@ use strict; my $me = $0; my $usage = qq{ -Usage: $me - Restore a custom dump (pg_dump -Fc) of a PostGIS-enabled database. - First dump the old database: pg_dump -Fc > - Then create a new database: createdb - Then install PostGIS in the new database: psql -f /postgis.sql - Finally, run this script on the old dump: $me | psql +Usage: $me [-v] + Restore a custom dump (pg_dump -Fc) of a PostGIS-enabled database. + First dump the old database: pg_dump -Fc MYDB > MYDB.dmp + Then create a new database: createdb NEWDB + Then install PostGIS in the new database: + psql -f postgis/postgis.sql NEWDB + Also install PostGIS topology and raster, if you were using them: + psql -f topology/topology.sql NEWDB + psql -f raster/rtpostgis.sql NEWDB + Finally, pass the dump to this script and feed output to psql: + $me MYDB.dmp | psql NEWDB + The -v switch writes detailed report on stderr. }; -die $usage if (@ARGV != 1); +my $DEBUG = 0; + +if ( @ARGV && $ARGV[0] eq '-v' ) { + $DEBUG = 1; + shift(@ARGV); +} + +die $usage if (@ARGV < 1); my $dumpfile = $ARGV[0]; my $manifest = $dumpfile . ".lst"; @@ -50,8 +63,6 @@ die "$me:\tUnable to find 'pg_dump' on the path.\n" if ! `pg_dump --version`; die "$me:\tUnable to find 'pg_restore' on the path.\n" if ! `pg_restore --version`; die "$me:\tUnable to open dump file '$dumpfile'.\n" if ! -f $dumpfile; -my $DEBUG = 0; - print STDERR "Converting $dumpfile to ASCII on stdout...\n"; ###################################################################### @@ -62,9 +73,8 @@ print STDERR " Reading list of functions to ignore...\n"; my %skip = (); while(my $l = ) { - print STDERR " $l" if $DEBUG; $l =~ s/\s//g; - print STDERR "DATA:$l\n" if $DEBUG; + print STDERR "DATA $l\n" if $DEBUG; $skip{$l} = 1; } @@ -83,10 +93,10 @@ while( my $l = ) { my $sig = linesignature($l); $hasTopology = 1 if $sig eq 'SCHEMAtopology'; if ( $skip{$sig} ) { - print STDERR "SKIPPING $sig\n" if $DEBUG; + print STDERR "SKIP $sig\n" if $DEBUG; next } - print STDERR "KEEPING $sig\n" if $DEBUG; + print STDERR "KEEP $sig\n" if $DEBUG; print MANIFEST $l; } @@ -153,11 +163,11 @@ while( my $l = ) { if ( $skip{$sig} ) { - print STDERR "SKIPPING $sig\n" if $DEBUG; + print STDERR "SKIP $sig\n" if $DEBUG; next; } - print STDERR "KEEPING $sig\n" if $DEBUG; + print STDERR "KEEP $sig\n" if $DEBUG; print STDOUT @sublines; next; }