← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11054: fixed restoredb some more to take into account foreign owners of database objects

 

------------------------------------------------------------
revno: 11054
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-05-28 15:40:32 +0100
message:
  fixed restoredb some more to take into account foreign owners of database objects
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 13:46:15 +0000
+++ tools/dhis2-tools-deb/pkg/usr/bin/dhis2-restoredb	2013-05-28 14:40:32 +0000
@@ -21,8 +21,9 @@
 BACKUP=$DHIS2_BASE/backups/snapshot_$(date +%Y%m%d%M%S).sql.bz2
 
 # stop tomcat and take a snapshot backup of the current database before doing anything
-dhis2-shutdown $INSTANCE
-sudo -u postgres pg_dump -T aggregated* -T analytics* -T completeness* -O $INSTANCE | bzip2 > $BACKUP
+dhis2-shutdown $INSTANCE || echo tomcat instance not running;
+
+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
@@ -30,6 +31,8 @@
 
 # restore the backup into the new database
 cat $2 | sudo -u postgres psql $DHIS2_DB
+# 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
 
 # restart tomcat
 dhis2-startup $INSTANCE