=== 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