Skip to content

Instantly share code, notes, and snippets.

@jnwelzel
Created January 8, 2015 18:22
Show Gist options
  • Save jnwelzel/9849b077c5f88fea25ff to your computer and use it in GitHub Desktop.
Save jnwelzel/9849b077c5f88fea25ff to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Description:
# this script restores couchbase & neo4j from the UX reference server, e.g qa1b.
# the process for restoring this is as follows:
# - start Couchbase and stop neo4j (with neo4j_server_stop.sh)
# - download the latest backup from http://10.165.4.67/fluigidentity.database.backup.tar.gz
# - run this script as "sudo ux_restore.sh <DB_ARCHIVE_ZIP> [<CLOUDPASS_HOME_DIR>]"
# - start neo4 (with neo4j_server_start.sh)
# - hit localhost:7474/browser and confirm that DB size is apprx 32gb by clicking the circles in the top-left corner
#
if [ $# -lt 1 ]
then
echo "Usage: $0 <DB_ARCHIVE_ZIP> [<CLOUDPASS_HOME>]"
exit 1
fi
BACKUP_FILE=$1
echo bkup: ${BACKUP_FILE}
SRC_DIR=../../..
if [ $# -eq 3 ]
then
SRC_DIR=$2
fi
SRC_DIR=$(cd $SRC_DIR; pwd)
echo src: $SRC_DIR
if [ ! -d $SRC_DIR/backend/build/dist ]
then
echo Error: $SRC_DIR/backend/build/dist does not exist.
exit 1
fi
BU_DIR=/data/backup
if [ ! -d $BU_DIR ]
then
echo Error: Data dir does not exist $BU_DIR
exit 1
fi
if [ ! -f $BACKUP_FILE ]
then
echo Error: Backup file does not exist $BACKUP_FILE
exit 1
fi
which cbrestore &> /dev/null
if [ $? != 0 ]
then
echo "You must add cbrestore to your path."
exit 1
fi
ps -ef | grep Couchbase > /dev/null
if [ $? != 0 ]
then
echo "Error: Couchbase is not running."
exit 1
fi
ps -ef | grep neo4j | grep server.properties > /dev/null
if [ $? == 0 ]
then
echo "Error: Neo4j is running. Kill it and try again"
exit 1
fi
cd $BU_DIR
echo "Extracting backup file."
tar -zxvf $BACKUP_FILE
mv ./data/backup/* .
couchdb=$(ls -1t $BU_DIR/couchbase*.tar.gz | head -n 1)
if [ ! -f $couchdb ]
then
echo Error: Archive does not contain couchbase backup file.
exit 1
fi
echo "Extracting couchbase zip file $couchdb"
tar -zxvf $couchdb &> /dev/null
cdb=$(ls -1td $BU_DIR/data/backup/couchbase.* | grep -v tar| head -n 1)
cd $cdb
echo "Starting CB restore $cdb "
/opt/couchbase/bin/cbrestore . -u Administrator -p password -x rehash=1 couchbase://localhost:8091 -b cloudpass -B cloudpass
if [ $? != 0 ]
then
echo "Error: Couchbase restore error"
exit 1
fi
scimdb=$(ls -1t $BU_DIR/totvslabs*.tar.gz | head -n 1)
if [ ! -f $scimdb ]
then
echo Error: Archive does not contain scim backup file.
exit 1
fi
echo "Extracting scim tar file $scimdb"
tar -zxf $scimdb
rm $scimdb
rm -R /data/totvslabs 2>/dev/null
mv totvslabs /data
ksdb=$(ls -1t $BU_DIR/CloudpassKeystore.* | head -n 1)
echo "Copying keystore file"
cp $ksdb $SRC_DIR/backend/build/bin/CloudpassKeystore
rm $ksdb
rm -R $cdb
rm -R $BU_DIR/data 2>/dev/null
rm -R $couchdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment