From 8376610dec3a7066fedaa4c779cb062b69c23ae2 Mon Sep 17 00:00:00 2001 From: Keith Whyte Date: Sun, 21 Feb 2021 22:52:11 +0100 Subject: [PATCH] Add DB migration script --- modules/rhizo_base/files/bin/migrate-hlr.sh | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 modules/rhizo_base/files/bin/migrate-hlr.sh diff --git a/modules/rhizo_base/files/bin/migrate-hlr.sh b/modules/rhizo_base/files/bin/migrate-hlr.sh new file mode 100755 index 0000000..d460f4d --- /dev/null +++ b/modules/rhizo_base/files/bin/migrate-hlr.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +echo "This will (re)-start daemons and disrupt service. Continue (y/n)?" + +read answer + +if [ "$answer" != "y" ]; then + exit +fi + +if [ "$PWD" != "/var/lib/osmocom" ]; then + OLDPWD=$PWD + cd /var/lib/osmocom +fi + +sv stop osmo-nitb +echo "PRAGMA wal_checkpoint(FULL)" | sqlite3 ./hlr.sqlite3 + +if [ -f hlr.db ]; then + echo "OSMO HLR hlr.db Exists, Making backup..." + systemctl stop osmo-hlr + echo "PRAGMA wal_checkpoint(FULL)" | sqlite3 ./hlr.db + if [ -s hlr.db-wal ]; then + echo "WAL file not empty. Exiting." + systemctl start osmo-hlr + exit + fi + mv hlr.db hlr.db.$(date +%F-%T) + rm hlr.db-wal hlr.db-shm 2> /dev/null +fi + +echo "Importing NITB db form hlr.sqlite3 to hlr.db..." +osmo-hlr-db-tool import-nitb-db hlr.sqlite3 -l hlr.db +systemctl restart osmo-hlr +echo "done" + +/var/rhizomatica/rccn/OsmoSmsQ.py -p ./hlr.sqlite3 -q + +if [ -f sms.db ]; then + systemctl stop osmo-msc + echo "OSMO (S)MSC sms.db Exists, Making backup..." + echo "PRAGMA wal_checkpoint(FULL)" | sqlite3 ./sms.db + if [ -s sms.db-wal ]; then + echo "WAL file not empty. Exiting." + systemctl start osmo-msc + exit + fi + mv sms.db sms.db.$(date +%F-%T) + rm sms.db-wal sms.db-shm 2>/dev/null +fi + +echo ".clone sms.db" | sqlite3 hlr.sqlite3 +/var/rhizomatica/rccn/OsmoSmsQ.py -p ./sms.db -q +systemctl restart osmo-msc + +cd $OLDPWD