Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
titledb-restore.sh
#!/bin/bash

pushd `dirname $0` > /dev/null
RESET_DIR="$(pwd)"
popd > /dev/null
MANAGE_PY="/home/vagrant/norduni/src/niweb/manage.py"
NOCLOOK_DIR="/home/vagrant/norduni/src/scripts"
NEO4J_DIR="/home/vagrant/neo4j-community-2.1.6"
DB_NAME="norduni"
SQL_DUMP="/vagrant/nistore/producers/noclook/sql/postgres.sql"
DJANGO_DB_USER="ni"

function now (){
  date +"%Y-%m-%d %H:%M:%S"
}


function msg(){
  echo "> $1 - $(now)"
}


msg "Stopping neo4j"
$NEO4J_DIR/bin/neo4j stop


msg "Removing neo4j data"
rm -rf $NEO4J_DIR/data/*


msg "Starting neo4j again"
$NEO4J_DIR/bin/neo4j start


msg "Adding indexes to neo4j"
curl -D - -H "Content-Type: application/json" --data '{"name" : "node_auto_index","config" : {"type" : "fulltext","provider" : "lucene"}}' -X POST http://localhost:7474/db/data/index/node/
curl -D - -H "Content-Type: application/json" --data '{"name" : "relationship_auto_index","config" : {"type" : "fulltext","provider" : "lucene"}}' -X POST http://localhost:7474/db/data/index/relationship/


msg "Drop, Create, Grant on DB"
sudo -u postgres psql -fc "$RESET_DIR/sql/drop-create-grant.sql"drop database $DB_NAME"


msg "Import DB"
awk '/CREATE DATABASE norduni2/{flag=1}/\\connect postgres/{flag=0}flag' $SQL_DUMP | sed -e "s/norduni2/$DB_NAME/" -e "s/postgres;/$DJANGO_DB_USER;/" | sudo -u postgres psql


msg "Python migrate"
python $MANAGE_PY syncdb
python $MANAGE_PY migrate apps.noclook


msg "Create superuser"
python $MANAGE_PY migrate actstream
python $MANAGE_PY migrate tastypie


 createsuperuser


msg "Upgrade db entries to 2.x"
cd $NOCLOOK_DIR/updates_and_fixes/
python upgrade_1.9_to_2.X.py -C $RESET_DIR/upgrade.conf -I

msg "Reset DB sequences"
sudo -u postgres psql -f "$RESET_DIR/sql/reset-sequences-noclook.sql" norduni


msg "Importing data from json"
cd $NOCLOOK_DIR
python noclook_consumer.py -C $RESET_DIR/restore.conf -I

...