66 lines
1.3 KiB
Bash
66 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
#
|
|
# AIM : Manage Opennebula database update
|
|
#
|
|
#
|
|
|
|
. /usr/lib/eole/ihm.sh
|
|
|
|
function clean_backups()
|
|
{
|
|
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
|
|
}
|
|
|
|
function updateDB()
|
|
{
|
|
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() {
|
|
if [ $(CreoleGet one_database_type) = "mysql" ] && [ $(CreoleGet one_ha_role leader) = "leader" ]; then
|
|
Question_ouinon "Voulez-vous migrer de SQLite à Mysql ?" "True" "non" "warn"
|
|
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)
|
|
onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST
|
|
fi
|
|
fi
|
|
}
|
|
|
|
echo
|
|
EchoGras "Mise à jour de la base de données ONE"
|
|
echo
|
|
updateDB
|
|
echo
|
|
to_mysql
|
|
exit ${?}
|