2016-05-09 15:27:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# AIM : Manage Opennebula database update
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
. /usr/lib/eole/ihm.sh
|
2019-02-19 09:18:57 +01:00
|
|
|
script="$1"
|
2016-05-09 15:27:16 +02:00
|
|
|
|
2016-09-08 15:49:07 +02:00
|
|
|
function clean_backups()
|
|
|
|
{
|
2019-02-18 17:39:41 +01:00
|
|
|
file=${1}
|
|
|
|
bcks=($(ls ${file}_*))
|
|
|
|
nbbck=$(expr ${#bcks[@]} - 2)
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ${nbbck} -gt 1 ]]
|
|
|
|
then
|
|
|
|
EchoGras "Cleaning up old backups !"
|
|
|
|
for idx in `seq 0 ${nbbck}`
|
|
|
|
do
|
|
|
|
rm -f ${bcks[${idx}]}
|
|
|
|
done
|
|
|
|
fi
|
2016-09-08 15:49:07 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 15:27:16 +02:00
|
|
|
function updateDB()
|
|
|
|
{
|
2019-02-18 17:39:41 +01:00
|
|
|
local dbfile='/var/lib/one/one.db'
|
|
|
|
local cmd="onedb"
|
|
|
|
local res=0
|
|
|
|
|
|
|
|
if [[ -f ${dbfile} ]]
|
|
|
|
then
|
|
|
|
$cmd upgrade -f -s ${dbfile}
|
|
|
|
res=${?}
|
|
|
|
clean_backups ${dbfile}
|
|
|
|
return ${res}
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function to_mysql() {
|
2019-02-19 09:18:57 +01:00
|
|
|
if [ "$script" = 'instance' ] && [ $(CreoleGet one_database_type) = "mysql" ] && [ $(CreoleGet one_ha_role leader) = "leader" ]; then
|
2019-02-19 11:53:12 +01:00
|
|
|
Question_ouinon "Voulez-vous migrer de SQLite à Mysql ?" "True" "oui" "warn"
|
2019-02-18 17:39:41 +01:00
|
|
|
rep=$(echo "$?")
|
|
|
|
if [ "$rep" == "0" ]; then
|
|
|
|
# do not recover db on follower
|
|
|
|
HOST=$(CreoleGet one_database_host)
|
|
|
|
DB=$(CreoleGet one_database_name)
|
|
|
|
USER=$(CreoleGet one_database_user)
|
|
|
|
PASS=$(CreoleGet one_database_pass)
|
2019-02-19 11:53:12 +01:00
|
|
|
cp -a /etc/one/oned.conf /etc/one/oned.conf.ori
|
|
|
|
# HA ne doit pas être activer pour la migration
|
|
|
|
CreoleCat -s /usr/share/eole/creole/distrib/oned-ha-mysql.conf -o /etc/one/oned.conf
|
|
|
|
oned -i
|
2019-02-18 17:39:41 +01:00
|
|
|
onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST
|
2019-02-19 11:53:12 +01:00
|
|
|
cp -a /etc/one/oned.conf.ori /etc/one/oned.conf
|
2019-02-18 17:39:41 +01:00
|
|
|
fi
|
|
|
|
fi
|
2016-05-09 15:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
EchoGras "Mise à jour de la base de données ONE"
|
|
|
|
echo
|
|
|
|
updateDB
|
|
|
|
echo
|
2019-02-18 17:39:41 +01:00
|
|
|
to_mysql
|
2016-05-09 15:27:16 +02:00
|
|
|
exit ${?}
|