#!/usr/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/roundcube-restore-database - restore Roundcube database # # Copyright (c) 2012-2025 The Eisfair Team, team(at)eisfair(dot)org # # Creation : 2013-01-08 jed # Last Update: $Id$ # # Usage : roundcube-restore-database [-src source-file] # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ # read eislib . /var/install/include/eislib #exec 2>/tmp/roundcube-db-import-trace-$$.log #set -x roundcube_path=/var/roundcube roundcube_apache_user="wwwrun" roundcube_apache_group="nogroup" srcfile=${roundcube_path}/data/roundcubemail.db.DUMP tmppath='/tmp' configfile=/etc/config.d/roundcube logfile=${roundcube_path}/roundcube-db-restore.log update=0 if [ $# -gt 0 ] then while [ 1 ] do case "$1" in -src) # source file if [ -f "$2" ] then srcfile="$2" fi shift; shift ;; --update) update=1 shift ;; *) break ;; esac done fi if [ -s ${configfile} ] then . ${configfile} # save current Roundcube version idx=1 while [ ${idx} -le ${ROUNDCUBE_N} ] do eval active='$ROUNDCUBE_'${idx}'_ACTIVE' if [ "${active}" = 'yes' ] then eval docroot='$ROUNDCUBE_'${idx}'_DOCUMENT_ROOT' break fi idx=`expr ${idx} + 1` done prev_version='' if [ -f ${roundcube_path}/roundcube_version ] then prev_version=`cat ${roundcube_path}/roundcube_version` fi # set default database type rc_db_type="${ROUNDCUBE_DB_TYPE}" if [ -z "${rc_db_type}" ] then rc_db_type='sqlite' fi if [ "${rc_db_type}" = "sqlite" ] then # SQLite database if [ -f ${srcfile} ] then # source file exists data_file=${roundcube_path}/data/roundcubemail.db prev_data_file=${data_file}.${EISDATE}-${EISTIME} if [ ${update} -eq 1 -a -f ${data_file} ] then # backup database without prior question mv ${data_file} ${prev_data_file} fi if [ -f ${data_file} ] then mecho --warn "The database file '${data_file}' already exists." mecho if /var/install/bin/ask "Do you want to backup it" "yes" then mv ${data_file} ${prev_data_file} else mecho --warn "database import aborted." exit 1 fi fi rm -f ${logfile} ### import database ### # SQLite 3.x database if [ -f /usr/bin/sqlite3 ] then sqlite3 ${data_file} < ${srcfile} 2>> ${logfile} else mecho --error "Program '/usr/bin/sqlite3' doesn't exist!" fi else mecho --error "Source file '${srcfile}' doesn't exist!" fi fi if [ -s ${logfile} ] then # log file exists and has a size greater than zero if /var/install/bin/ask "A log file has been created, do you want to show it now" "n" then # check if show-doc.cui supports colors color='' frame='' if $(grep -qE "^MENU=['\"]/var/install/bin/show-menu['\"]" /etc/config.d/setup) then color='--nocolor' frame='--noframe' fi sleep 3 /var/install/bin/show-doc.cui ${color} ${frame} --follow --title ${logfile} ${logfile} fi else # delete file of size zero rm -f ${logfile} fi #else # mecho --error "Configuration file '${configfile}' doesn't exist!" fi exit 0