#!/bin/bash -e onedb=0 dryRun=0 loadAll=0 args=`getopt nad: $*` if [ $? != 0 ] ; then echo -e "USAGE: doUpdateDb.sh [-d ] [-n] [-a]" echo -e "\t-d: process only ; if not specified, all dbs listed in the file 'databases' are processed" echo -e "\t-n: dry run" echo -e "\t-a: load all tables, not just new ones" exit 1 fi set -- $args for i do case "$i" in -d) DIRS=$2 onedb=1 shift shift;; -n) dryRun=1 shift;; -a) loadAll=1 shift;; --) shift break;; esac done if [[ $onedb != 1 ]] ; then DIRS="`grep -v '^#' /usr/data/mirror-download/databases` hgFixed uniProt proteinDB/proteins040115 proteinDB/proteins040515 proteinDB/proteins051015 proteinDB/proteins040315 proteinDB/proteins050415 proteinDB/proteins060115" fi # update tables for dir in $DIRS ; do db=`basename $dir` echo "Updating database $db..." if [[ $loadAll != 1 && -e /usr/data/mirror-download/.lastupdate.$db ]] ; then findarg="-newer /usr/data/mirror-download/.lastupdate.$db" else findarg="" fi for file in `find /usr/data/mirror-download/$dir/database $findarg -name "*.txt.gz"` ; do table=`basename $file .txt.gz` sql=/usr/data/mirror-download/$dir/database/$table.sql echo "Updating table $table in database $db..." if [ $dryRun != 1 ] ; then /usr/local/bin/hgsql $db -e "drop table if exists $table" /usr/local/bin/hgsql $db < $sql zcat $file | /usr/local/bin/hgsql $db -e "load data local infile \"/dev/stdin\" into table $table" fi done if [ $dryRun != 1 ] ; then touch -r /usr/data/mirror-download/$dir/database/`ls -rt /usr/data/mirror-download/$dir/database/ | tail -1` /usr/data/mirror-download/.lastupdate.$db # use time of newest file as a marker so that files updated between download and update are not lost fi done #FIXME: need better solution here -- this will wipe out local info #if [ $dryRun != 1 ] ; then # hgsql hgcentral -e "drop table if exists sessionDb;" # hgsql hgcentral -e "drop table if exists userDb;" # hgsql hgcentral -e "drop table if exists defaultDb;" # hgsql hgcentral -e "drop table if exists blatServers;" # hgsql hgcentral -e "drop table if exists dbDb;" # hgsql hgcentral -e "drop table if exists gdbPdb;" # hgsql hgcentral -e "drop table if exists liftOverChain;" # hgsql hgcentral -e "drop table if exists clade;" # hgsql hgcentral -e "drop table if exists genomeClade;" # hgsql hgcentral < hgcentral.sql #fi echo "Done."