Updated scripts to better handle errors.
diff --git a/demo/dashboard/scripts/backup.sh b/demo/dashboard/scripts/backup.sh
index d68d530..888f74d 100755
--- a/demo/dashboard/scripts/backup.sh
+++ b/demo/dashboard/scripts/backup.sh
@@ -1,5 +1,5 @@
#
-# Copyright 2016 The Charles Stark Draper Laboratory
+# Copyright 2014 The Charles Stark Draper Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,18 +16,24 @@
#!/bin/bash
-INDEXNAME="xdata_v3"
+INDEXNAME='"xdata_v3,.kibana"'
BACKUPDIR="/mnt/es-backups/"
+echo " * Backing up $INDEXNAME in $BACKUPDIR"
+
sudo mkdir -p $BACKUPDIR || exit $?
-# Create the repository
-curl -XPUT 'http://localhost:9200/_snapshot/xdata_backup' -d `{
- "type" : "fs",
- "settings" : { "location" : "$BACKUPDIR",
- "max_snapshot_bytes_per_sec" : "50mb",
- "max_restore_bytes_per_sec" : "50mb" }
- }`
+# Create the repository
+curl -s -XPUT 'http://localhost:9200/_snapshot/xdata_backup' -d "{ \"type\" : \"fs\",
+ \"settings\" : {
+ \"location\" : \"$BACKUPDIR\",
+ \"max_snapshot_bytes_per_sec\" : \"50mb\",
+ \"max_restore_bytes_per_sec\" : \"50mb\"
+ }
+ }" > /dev/null
+
# Backup only relevant indices. We speciy this as to prevent backing up the .kibana index and any other test indexes that were created
-curl -XPUT 'http://localhost:9200/_snapshot/xdata_backup/snapshot' -d `{ "indices" : "$INDEXNAME" }`
+# This has the potential to fail, if a snapshot with the same name already exists.
+curl -s -XPUT 'http://localhost:9200/_snapshot/xdata_backup/snapshot' -d "{ \"indices\" : $INDEXNAME }" > /dev/null
+echo " ...done."
diff --git a/demo/dashboard/scripts/install.sh b/demo/dashboard/scripts/install.sh
index 61f3b2d..b37a2c3 100644
--- a/demo/dashboard/scripts/install.sh
+++ b/demo/dashboard/scripts/install.sh
@@ -1,5 +1,5 @@
#
-# Copyright 2016 The Charles Stark Draper Laboratory
+# Copyright 2014 The Charles Stark Draper Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
# Update box & install openjdk and mongodb
sudo -E apt-get update || exit $?
sudo -E apt-get -y install openjdk-7-jdk || exit $?
-sudo -E apt-get -y install mongodb || exit $?
# Install Miniconda
wget -q $MINICONDA_SCRIPT || exit $?
@@ -47,7 +46,7 @@
sudo -E apt-get -y install logstash || exit $?
# Install Kibana
-echo "deb http://packages.elastic.co/kibana/4.4/debian stable main" | sudo tee -a /etc/apt/sources.list.d/kibana-4.4.x.list
+echo "deb http://packages.elastic.co/kibana/4.5/debian stable main" | sudo tee -a /etc/apt/sources.list.d/kibana-4.5.x.list
sudo -E apt-get update || exit $?
sudo -E apt-get -y install kibana || exit $?
@@ -56,6 +55,15 @@
sudo cp /vagrant/files/config/xdata.conf /etc/logstash/conf.d/ || exit $?
sudo cp /vagrant/files/twisted_app.py $HOME/ || exit $?
sudo cp /vagrant/files/config/kibana.yml /opt/kibana/config/ || exit $?
+sudo cp /vagrant/scripts/backup.sh $HOME/ || exit $?
+sudo cp /vagrant/scripts/restore.sh $HOME/ || exit $?
+
+# Make the backup directory and change its permissions
+BACKUPDIR="/mnt/es-backups/"
+sudo mkdir -p $BACKUPDIR || exit $?
+sudo cp -r /vagrant/files/indices/* $BACKUPDIR
+sudo chown -R elasticsearch:elasticsearch $BACKUPDIR
+
# Create log directory to store send_logs to
sudo mkdir /var/log/xdata || exit $?
diff --git a/demo/dashboard/scripts/restart.sh b/demo/dashboard/scripts/restart.sh
index a44a94c..3a84577 100644
--- a/demo/dashboard/scripts/restart.sh
+++ b/demo/dashboard/scripts/restart.sh
@@ -1,5 +1,5 @@
#
-# Copyright 2016 The Charles Stark Draper Laboratory
+# Copyright 2014 The Charles Stark Draper Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
diff --git a/demo/dashboard/scripts/restore.sh b/demo/dashboard/scripts/restore.sh
index 5bdf523..78c76cd 100644
--- a/demo/dashboard/scripts/restore.sh
+++ b/demo/dashboard/scripts/restore.sh
@@ -1,5 +1,5 @@
#
-# Copyright 2016 The Charles Stark Draper Laboratory
+# Copyright 2014 The Charles Stark Draper Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,5 +16,38 @@
#!/bin/bash
+LHOST='http://localhost:9200'
+INDICES='xdata_v3,.kibana'
+MAX_TRIES=10
+tries=0
+
+echo " * Restoring $INDICES"
+
+# Make sure the indices exist, and that they are open
+# This is because, if we just restarted, the instance may not be ready.
+while true;
+do
+ response=$(curl -s -XHEAD --write-out %{http_code} --silent --output /dev/null "$LHOST/$INDICES")
+ if [ "$response" = "200" ]; then
+ response=$(curl -s -XGET --silent "$LHOST/_cat/indices/$INDICES?h=status")
+ if [[ $response == "open"* ]]; then
+ break
+ fi
+ fi
+ tries=$((tries+1))
+ if [ "$tries" -gt "$MAX_TRIES" ]; then
+ echo " Error: Indices either don't exist, or are not open"
+ exit 1
+ fi
+ sleep 1;
+done
+
+# Close indices before we try to restore them
+curl -s -XPOST "$LHOST/$INDICES/_close" > /dev/null
+
# Restore snapshot
-curl -XPUT 'http://localhost:9200/_snapshot/xdata_backup/snapshot_restore'
+curl -s -XPOST "$LHOST/_snapshot/xdata_backup/snapshot/_restore" > /dev/null
+
+# Open the newly restore indices
+curl -s -XPOST "$LHOST/$INDICES/_open" > /dev/null
+echo " ...done."