Sleds/utils/storage-monster-migration.sh

175 lines
5.1 KiB
Bash

#!/bin/bash
# Usage: storage-monster-migration.sh
#
# This can be used for dev/localhost and multi-VM servers, HOWEVER:
# for multi VM the following manual steps MUST be undertaken before running this script:
# 1. Set disco for the server in question to "maintenance mode"
# 2. Deploy a release
# 3. Run this script
# 4. Take server out of maint mode in disco
# 5. (rev2) Mount LC b1 from {somewhere} to /sequencelogic/sm/LC/b1
# 6. (rev2) Mount L3 bucket(s) to /sequencelogic/sm/L3/{buckets}
# 7. (rev2) Mount VR bucket(s) to /sequencelogic/sm/VR/{buckets}
#
# What this does:
# A. Creates directories as necessary
# B. Generates default pool configs (basically L2 is setup and online, everything else is disabled)
# C. Moves old 1.2.0 /sequencelogic/sgws/mount/?????? dirs to /sequencelogic/sm/L2/b1/??????
# D. Modifies /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json:
# a. adds sm-home and pools-home to storageGuard if not already present
# b. modifies L2 config to indicate 'b1' (although this gets overridden by VAN quotas)
# E. Runs sequencelogic-reset-van-quotas.sh
# F. Runs sequencelogic-reset-van-policies.sh
# G. Modifies all old-style "http" location bucket ID values to use "b1" for L2_FS
source /sequencelogic/bin/sequencelogic-helpers.sh
echo "DEPRECATED BUT LEFT IN PLACE AS FUTURE SLI BUILDS MIGHT WANT TO DO A MIGRATION"
exit 1
SRC=/sequencelogic/sgws/mount
DEST=/sequencelogic/sm
if [ ! -d ${DEST} ]; then
mkdir ${DEST}
fi
# compatibility with old regime... TODO use a different tmp location
mkdir -p /sequencelogic/sgws/mount/tmp
POOLS=/sequencelogic/config/pools
TYPES="LC L2 L3 VR"
# must manually mount/link L3/VR!
BUCKET="b1"
NOW=`date +"%Y-%m-%dT%H:%M:%S"`
if [ ! -d ${POOLS} ]; then
mkdir -p ${POOLS}
fi
# real tmp
mkdir -p ${POOLS}/tmp
for t in ${TYPES}; do
# data directory
ddir="${DEST}/${t}/${BUCKET}"
if [ ! -d "${DEST}/${t}" ]; then
mkdir -p "${DEST}/${t}"
# create b1 in all pools if single VM
if [ $t != "L2" ]; then
case "$SEQUENCE_LOGIC_ENV" in
dev|demo|localhost) mkdir -p "${ddir}";;
*) echo "Manually mount and create buckets for LC/L3/VR multi-VM environments!!!";;
esac
fi
fi
# treat existing sgws/mount as LC_FS
if [ $t = "L2" ]; then
if [ ! -d ${ddir}/000000 ]; then
echo "Linking ${SRC} to ${ddir}"
ln -s ${SRC} ${ddir}
fi
# tim sanity
if [ ! -d ${ddir}/000000 ]; then
echo "No such directory: ${ddir}/000000"
exit 1
fi
desc="$t primary filestore"
enab=true
autoro=0.99
size=1.0
low=1.0
high=1.0
elif [ $t = "LC" ]; then
desc="MRU file cache"
enab=false
autoro=0.99
size=1048576
low=0.75
high=0.90
else
desc="$t secondary filestore"
enab=false
autoro=0.99
size=1.0
low=1.0
high=1.0
fi
# configs
echo "*** Creating pool configuration: ${POOLS}/${t}_FS-pool.conf.json ***"
cat > ${POOLS}/${t}_FS-pool.conf.json <<EOF
// DO NOT remove this comment line
// Pool configuration auto-generated on: ${NOW}
{
"description": "${desc}",
"name": "${t}_FS",
"enabled": ${enab},
"saved": "${NOW}",
"modifiedby": "${USER}",
"readpriority": 1.0,
"buckets": [
{
"id": "${BUCKET}",
"type": "local-storage",
"status": "online",
// low/high _water apply only to single bucket LC environments and are ignored elsewhere
"low_water": ${low},
"high_water": ${high},
// autoro is a decimal % at which point this bucket becomes readonly
"autoro": ${autoro},
// size is either a decimal value <= 1.0 indicating a percentage to use,
// or an absolute value > 1.0 indicating max # bytes to use
"size": ${size},
"writepriority": 1.0
}
]
}
EOF
done
# /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json updates
smHome=`getConfigurationValue storageGuard.sm-home`
echo "*** storageGuard.sm-home is set to: ${smHome} *** "
if [ "$smHome" = "" -o "$smHome" = "null" ]; then
echo "*** Editing ${SEQUENCE_LOGIC_ENV}.conf.json *** "
cat /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json | awk '
/"mount-home"/ {
printf "\t\t// mount-home deprecated as of 1.2.2\n"
printf "\t\t\"sm-home\": \"/sequencelogic/sm\",\n"
printf "\t\t\"pools-home\": \"/sequencelogic/config/pools\",\n"
}
/"type": "L2"/ {
sub(/"bucket_id": "[^"]+"/, "\"bucket_id\": \"b1\"")
}
{ print $0 }
' > /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json.1.2.2
mv /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json.1.2.0
mv /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json.1.2.2 /sequencelogic/config/${SEQUENCE_LOGIC_ENV}.conf.json
fi
# DB updates
echo "*** Update L2 bucket_id values *** "
bkt=${BUCKET}
#bkt=http://dev.ionu.com:8080
mongoExec "db.sgnode.update({'loc.type': 'L2'}, {\$set: {'loc.$.bucket_id': '${bkt}'}}, {multi:true})"
mongoExec "db.sgnode.dropIndexes()"
mongoExec "db.teampolicy.update({}, {\$set:{plan_id:'SMN_BASIC'}}, {multi:true})"
# Quotas
/sequencelogic/bin/sequencelogic-reset-van-quotas.sh
# Policies
/sequencelogic/bin/sequencelogic-reset-van-policies.sh
# Teams
/sequencelogic/bin/sequencelogic-reset-teams.sh
echo "*** Migration complete ***"
exit 0