[Helper] backup fixes

master
andryyy 2020-03-29 15:50:29 +02:00
parent a71d991c12
commit 212c18fd08
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
1 changed files with 47 additions and 32 deletions

View File

@ -202,14 +202,24 @@ function restore() {
;; ;;
mysql) mysql)
SQLIMAGE=$(grep -iEo '(mysql|mariadb)\:.+' ${COMPOSE_FILE}) SQLIMAGE=$(grep -iEo '(mysql|mariadb)\:.+' ${COMPOSE_FILE})
read -p "mailcow will be stopped and the corresponding mailcow.conf file of the backup will be restored, do you want to proceed? [y|N] " MYSQL_STOP_MAILCOW if [[ -z "${SQLIMAGE}" ]]; then
if [[ ${MYSQL_STOP_MAILCOW,,} =~ ^(yes|y)$ ]]; then echo "Could not determine SQL image version, skipping restore..."
echo "Stopping mailcow..." shift
docker-compose down continue
elif [ ! -f "${RESTORE_LOCATION}/mailcow.conf" ]; then
echo "Could not find the corresponding mailcow.conf in ${RESTORE_LOCATION}, skipping restore."
echo "If you lost that file, copy the last working mailcow.conf file to ${RESTORE_LOCATION} and restart the restore process."
shift
continue
else else
read -p "mailcow will be stopped and the currently active mailcow.conf will be modified to use the DB parameters found in ${RESTORE_LOCATION}/mailcow.conf - do you want to proceed? [Y|n] " MYSQL_STOP_MAILCOW
if [[ ${MYSQL_STOP_MAILCOW,,} =~ ^(no|n|N)$ ]]; then
echo "OK, skipped." echo "OK, skipped."
shift shift
continue continue
else
echo "Stopping mailcow..."
docker-compose down
fi fi
#docker stop $(docker ps -qf name=mysql-mailcow) #docker stop $(docker ps -qf name=mysql-mailcow)
if [[ -d "${RESTORE_LOCATION}/mysql" ]]; then if [[ -d "${RESTORE_LOCATION}/mysql" ]]; then
@ -231,12 +241,17 @@ function restore() {
gunzip < backup/backup_mysql.gz | mysql -uroot && \ gunzip < backup/backup_mysql.gz | mysql -uroot && \
mysql -uroot -e SHUTDOWN;" mysql -uroot -e SHUTDOWN;"
fi fi
echo "Copying mailcow.conf..." echo "Modifying mailcow.conf..."
mv mailcow.conf mailcow.conf_backup_$(date +"%Y-%m-%d-%H-%M-%S") source ${RESTORE_LOCATION}/mailcow.conf
cp ${RESTORE_LOCATION}/mailcow.conf mailcow.conf sed -i "/DBNAME/c\DBNAME=${DBNAME}" ${SCRIPT_DIR}/../mailcow.conf
sed -i "/DBUSER/c\DBUSER=${DBUSER}" ${SCRIPT_DIR}/../mailcow.conf
sed -i "/DBPASS/c\DBPASS=${DBPASS}" ${SCRIPT_DIR}/../mailcow.conf
sed -i "/DBROOT/c\DBROOT=${DBROOT}" ${SCRIPT_DIR}/../mailcow.conf
source ${SCRIPT_DIR}/../mailcow.conf
echo "Starting mailcow..." echo "Starting mailcow..."
docker-compose up -d docker-compose up -d
#docker start $(docker ps -aqf name=mysql-mailcow) #docker start $(docker ps -aqf name=mysql-mailcow)
fi
;; ;;
esac esac
shift shift