During my Xed restoring of data I decided to make a script for this...
Code Block |
---|
language | bash |
---|
title | db-restore.sh |
---|
collapse | true |
---|
|
#!/bin/bash
pushd `dirname $0` > /dev/null
RESET_DIR="$(dirname $0pwd)"
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 -f "$RESET_DIR/sql/drop-create-grant.sql"
msg "PythonImport migrateDB"
python $MANAGE_PY syncdbsudo -u postgres psql -f "$SQL_DUMP" $DB_NAME
msg "Python migrate"
python $MANAGE_PY migrate apps.noclook
python $MANAGE_PY migrate actstream
msg "Create superuser"
python $MANAGE_PY migrate tastypiecreatesuperuser
msg "Reset DB sequences"
sudo -u postgres psql -f "$RESET_DIR/sql/reset-sequences-noclook.sql" norduni$DB_NAME
msg "Importing neo4j data from json"
cd $NOCLOOK_DIR
python noclook_consumer.py -C $RESET_DIR/neo4j-only.conf -I |
SQL
Code Block |
---|
language | sql |
---|
title | sql/drop-create-grant.sql |
---|
collapse | true |
---|
|
drop database norduni;
CREATE DATABASE norduni;
GRANT ALL PRIVILEGES ON DATABASE norduni to ni; |
Code Block |
---|
language | sql |
---|
title | sql/reset-sequences-noclook.sql |
---|
collapse | true |
---|
|
BEGIN;
SELECT setval(pg_get_serial_sequence('"noclook_nodetype"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "noclook_nodetype";
SELECT setval(pg_get_serial_sequence('"noclook_nodehandle"','handle_id'), coalesce(max("handle_id"), 1), max("handle_id") IS NOT null) FROM "noclook_nodehandle";
SELECT setval(pg_get_serial_sequence('"noclook_uniqueidgenerator"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "noclook_uniqueidgenerator";
SELECT setval(pg_get_serial_sequence('"noclook_nordunetuniqueid"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "noclook_nordunetuniqueid";
COMMIT; |
Nocklook Conf
Code Block |
---|
language | text |
---|
title | restore.conf |
---|
collapse | true |
---|
|
# All producers need to be listed here with a path data or empty
[data]
juniper_conf = /vagrant/nistore/producers/juniper_conf/json
nmap_services_py = /vagrant/nistore/producers/nmap_services_py/json
alcatel_isis =
noclook =
nagios_checkmk = /vagrant/nistore/producers/checkmk_livestatus/json
cfengine_report = /vagrant/nistore/producers/cfengine_report/json
[data_age]
juniper_conf = 30
# Set if the consumer should check for old data and delete it.
[delete_data]
juniper_conf = false |
Code Block |
---|
language | bash |
---|
title | neo4j-only.conf |
---|
collapse | true |
---|
|
# All producers need to be listed here with a path data or empty
[data]
juniper_conf =
nmap_services_py =
alcatel_isis =
noclook = /vagrant/nistore/producers/noclook/json
nagios_checkmk =
cfengine_report =
[data_age]
juniper_conf = 30
# Set if the consumer should check for old data and delete it.
[delete_data]
juniper_conf = false-I |