← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11061: Enhanced restoredb to handle either plain sql, gzipped or bzipped files

 

------------------------------------------------------------
revno: 11061
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-05-28 18:30:32 +0100
message:
  Enhanced restoredb to handle either plain sql, gzipped or bzipped files
modified:
  tools/dhis2-tools-deb/pkg/usr/bin/dhis2-restoredb


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'tools/dhis2-tools-deb/pkg/usr/bin/dhis2-restoredb'
--- tools/dhis2-tools-deb/pkg/usr/bin/dhis2-restoredb	2013-05-28 14:40:32 +0000
+++ tools/dhis2-tools-deb/pkg/usr/bin/dhis2-restoredb	2013-05-28 17:30:32 +0000
@@ -26,11 +26,21 @@
 sudo -u $DHIS2_USER sh -c "pg_dump -T aggregated* -T analytics* -T completeness* -O $INSTANCE | bzip2 > $BACKUP"
 
 # drop and recreate a new blank database
-sudo -u postgres dropdb $DHIS2_DB
-sudo -u postgres createdb -O $DHIS2_USER $DHIS2_DB
+dropdb $DHIS2_DB
+createdb -O $DHIS2_USER $DHIS2_DB
 
 # restore the backup into the new database
-cat $2 | sudo -u postgres psql $DHIS2_DB
+# try bzipped, gzipped and plain
+COMPRESSION="PLAIN"
+bunzip2 -t $2 && COMPRESSION="BZIP2" 
+gunzip -t $2 && COMPRESSION="GZIP"
+
+case $COMPRESSION in
+  BZIP2) bunzip2 -c $2 | psql "$DHIS2_DB";;
+  GZIP) gunzip -c $2 | psql "$DHIS2_DB";;
+  *) cat $2 | psql "$DHIS2_DB";;
+esac
+
 # make sure db owner owns everything
 pg_dump -s $DHIS2_DB | grep -i 'owner to' | sed -e "s/OWNER TO .*;/OWNER TO $DHIS2_USER;/i"|psql $DHIS2_DB