Permalink
Browse files

Automate database default push

  • Loading branch information...
NEMS Linux
NEMS Linux committed Nov 13, 2018
1 parent e34fc29 commit c0b8c0aeae5fd863758a0a0902cda95078e76780
Showing with 54 additions and 1 deletion.
  1. +53 −0 nems-push-db.sh
  2. +1 −1 nems-upgrade/1.4.1-1.5
@@ -9,13 +9,66 @@ mysql -u nconf -pnagiosadmin nconf -e "TRUNCATE History"
systemctl stop nagios
systemctl stop mysql
if [[ -d /tmp/mysql ]]; then
rm -rf /tmp/mysql
fi
mkdir /tmp/mysql
cd /tmp/mysql
# Master copy of my live database
# As I will be working on the running one
cp -R /var/lib/mysql .
# Edit the Sample database (nemsadmin user)
systemctl start mysql
# Replace my user info with defaults
echo "Before:"
mysql -t -u nconf -pnagiosadmin nconf -e "SELECT * FROM ConfigValues WHERE fk_id_attr=47;"
mysql -t -u nconf -pnagiosadmin nconf -e "UPDATE ConfigValues SET attr_value='nemsadmin' WHERE fk_id_attr=47;"
echo "After:"
mysql -t -u nconf -pnagiosadmin nconf -e "SELECT * FROM ConfigValues WHERE fk_id_attr=47;"
echo "Before:"
mysql -t -u nconf -pnagiosadmin nconf -e "SELECT * FROM ConfigValues WHERE fk_id_attr=55;"
mysql -t -u nconf -pnagiosadmin nconf -e "UPDATE ConfigValues SET attr_value='nagios@localhost' WHERE fk_id_attr=55;"
echo "After:"
mysql -t -u nconf -pnagiosadmin nconf -e "SELECT * FROM ConfigValues WHERE fk_id_attr=55;"
systemctl stop mysql
cd /root/nems/nems-migrator/data/1.5/mysql
if [[ -d NEMS-Sample ]]; then
rm -rf NEMS-Sample
fi
cp -R /var/lib/mysql .
mv mysql NEMS-Sample
# Create the clean database (used after initialization with custom user)
systemctl start mysql
mysql -u nconf -pnagiosadmin nconf -e "DELETE FROM ConfigValues WHERE fk_id_attr=47;"
mysql -u nconf -pnagiosadmin nconf -e "DELETE FROM ConfigValues WHERE fk_id_attr=55;"
systemctl stop mysql
cd /root/nems/nems-migrator/data/1.5/mysql
if [[ -d NEMS-Clean ]]; then
rm -rf NEMS-Clean
fi
cp -R /var/lib/mysql .
mv mysql NEMS-Clean
# Restore original MySQL database and resume operation as normal
rm -rf /var/lib/mysql
cp -R /tmp/mysql/mysql /var/lib
chown -R mysql:mysql /var/lib/mysql
systemctl start mysql
systemctl start nagios
@@ -4,7 +4,7 @@
# Ie., no need to re-build the entire port.
platform=$(/usr/local/share/nems/nems-scripts/info.sh platform)
ver=$(/usr/local/share/nems/nems-scripts/info.sh nemsver)
ver=$(/usr/local/share/nems/nems-scripts/info.sh nemsver)
if [[ "$ver" == "1.4.1" ]]; then

0 comments on commit c0b8c0a

Please sign in to comment.