#!/usr/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/roundcube-dump-database - dump Roundcube database to a file # # Copyright (c) 2012-2025 The Eisfair Team, team(at)eisfair(dot)org # # Creation : 2013-01-08 jed # Last Update: $Id$ # # Usage : roundcube-dump-database [-dest destination-directory] --update # # 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-dump-trace-$$.log #set -x roundcube_path=/var/roundcube roundcube_apache_user="wwwrun" roundcube_apache_group="nogroup" destpath=${roundcube_path}/data tmppath='/tmp' configfile=/etc/config.d/roundcube logfile=${roundcube_path}/roundcube-db-dump.log update=0 if [ $# -gt 0 ] then while [ 1 ] do case "$1" in -dest ) # destination directory if [ -d "$2" ] then destpath="$2" fi shift; shift ;; --update ) update=1 shift ;; * ) break ;; esac done fi if [ -s ${configfile} ] then # config file exists . ${configfile} if [ "${START_ROUNDCUBE}" = 'yes' ] then # 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 if [ -f ${docroot}/program/include/iniset.php ] then grep "RCMAIL_VERSION" ${docroot}/program/include/iniset.php | sed "s/^.*RCMAIL_VERSION' *, *'\(.*\)'.*$/\1/" > ${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 [ -d ${destpath} ] then # destination directory exists ### dump database ### if [ -f ${roundcube_path}/data/roundcubemail-1.db -a ! -f ${roundcube_path}/data/roundcubemail.db ] then # v0.90.1 -> v0.90.2 - raname database mv ${roundcube_path}/data/roundcubemail-1.db ${roundcube_path}/data/roundcubemail.db fi data_file=${roundcube_path}/data/roundcubemail.db if [ ${update} -eq 1 ] then dump_file=${destpath}/roundcubemail.db.DUMP rm -f ${dump_file} else dump_file=${destpath}/roundcubemail.db.DUMP.${EISDATE}-${EISTIME} fi if [ -f ${dump_file} ] then mecho --warn "The dump file '${dump_file}' already exists." mecho if /var/install/bin/ask "Do you want to overwrite it" "no" then rm -f ${dump_file} else mecho --arn "database dump aborted." exit 1 fi fi rm -f ${logfile} # roundcubemail.db: SQLite 2.x database file ${data_file} | grep -q "SQLite 3." if [ $? -eq 0 ] then # SQLite 3.x database if [ -f /usr/bin/sqlite3 ] then sqlite3 ${data_file} '.dump' > ${dump_file} 2>> ${logfile} else mecho --error "Program '/usr/bin/sqlite3' doesn't exist!" fi else # SQLite 2.x database file ${data_file} | grep -q "SQLite 2." if [ $? -eq 0 ] then # check if sqlite (2.x) binary exists if [ ! -f /usr/bin/sqlite -a ${roundcube_path}/.install/sqlite2-bin.tgz ] then tar xzf ${roundcube_path}/.install/sqlite2-bin.tgz -C / fi if [ -f /usr/bin/sqlite ] then sqlite ${data_file} '.dump' > ${dump_file} 2>> ${logfile} else mecho --error "Program '/usr/bin/sqlite' doesn't exist!" fi else mecho --error "Unknown database version given!" fi fi else mecho --error "Destination directory '${destpath}' 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 "Package disabled, START_ROUNDCUBE='no' has been set!" fi #else # mecho --error "Configuration file '${configfile}' doesn't exist!" fi exit 0