[Helper] backup fixes
parent
a71d991c12
commit
212c18fd08
|
@ -202,41 +202,56 @@ function restore() {
|
|||
;;
|
||||
mysql)
|
||||
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 [[ ${MYSQL_STOP_MAILCOW,,} =~ ^(yes|y)$ ]]; then
|
||||
echo "Stopping mailcow..."
|
||||
docker-compose down
|
||||
else
|
||||
echo "OK, skipped."
|
||||
if [[ -z "${SQLIMAGE}" ]]; then
|
||||
echo "Could not determine SQL image version, skipping restore..."
|
||||
shift
|
||||
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
|
||||
#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
|
||||
shift
|
||||
|
|
Loading…
Reference in New Issue