[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,41 +202,56 @@ 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..."
docker-compose down
else
echo "OK, skipped."
shift shift
continue 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
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."
shift
continue
else
echo "Stopping mailcow..."
docker-compose down
fi
#docker stop $(docker ps -qf name=mysql-mailcow)
if [[ -d "${RESTORE_LOCATION}/mysql" ]]; then
docker run --rm \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/:rw \
--entrypoint= \
-v ${RESTORE_LOCATION}/mysql:/backup \
${SQLIMAGE} /bin/bash -c "shopt -s dotglob ; /bin/rm -rf /var/lib/mysql/* ; rsync -avh --usermap=root:mysql --groupmap=root:mysql /backup/ /var/lib/mysql/"
elif [[ -f "${RESTORE_LOCATION}/backup_mysql.gz" ]]; then
docker run \
-it --rm \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/ \
--entrypoint= \
-u mysql \
-v ${RESTORE_LOCATION}:/backup \
${SQLIMAGE} /bin/sh -c "mysqld --skip-grant-tables & \
until mysqladmin ping; do sleep 3; done && \
echo Restoring... && \
gunzip < backup/backup_mysql.gz | mysql -uroot && \
mysql -uroot -e SHUTDOWN;"
fi
echo "Modifying mailcow.conf..."
source ${RESTORE_LOCATION}/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..."
docker-compose up -d
#docker start $(docker ps -aqf name=mysql-mailcow)
fi fi
#docker stop $(docker ps -qf name=mysql-mailcow)
if [[ -d "${RESTORE_LOCATION}/mysql" ]]; then
docker run --rm \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/:rw \
--entrypoint= \
-v ${RESTORE_LOCATION}/mysql:/backup \
${SQLIMAGE} /bin/bash -c "shopt -s dotglob ; /bin/rm -rf /var/lib/mysql/* ; rsync -avh --usermap=root:mysql --groupmap=root:mysql /backup/ /var/lib/mysql/"
elif [[ -f "${RESTORE_LOCATION}/backup_mysql.gz" ]]; then
docker run \
-it --rm \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/ \
--entrypoint= \
-u mysql \
-v ${RESTORE_LOCATION}:/backup \
${SQLIMAGE} /bin/sh -c "mysqld --skip-grant-tables & \
until mysqladmin ping; do sleep 3; done && \
echo Restoring... && \
gunzip < backup/backup_mysql.gz | mysql -uroot && \
mysql -uroot -e SHUTDOWN;"
fi
echo "Copying mailcow.conf..."
mv mailcow.conf mailcow.conf_backup_$(date +"%Y-%m-%d-%H-%M-%S")
cp ${RESTORE_LOCATION}/mailcow.conf mailcow.conf
echo "Starting mailcow..."
docker-compose up -d
#docker start $(docker ps -aqf name=mysql-mailcow)
;; ;;
esac esac
shift shift