[Helper] Use mariabackup for SQL

master
andryyy 2020-02-26 07:09:56 +01:00
parent a97c30273c
commit a1156c38fc
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
1 changed files with 18 additions and 3 deletions

View File

@ -97,8 +97,14 @@ function backup() {
--network $(docker network ls -qf name=${CMPS_PRJ}_) \ --network $(docker network ls -qf name=${CMPS_PRJ}_) \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/:ro \ -v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/:ro \
--entrypoint= \ --entrypoint= \
-v ${BACKUP_LOCATION}/mailcow-${DATE}:/backup \ -v ${BACKUP_LOCATION}/mailcow-${DATE}/mysql:/backup \
${SQLIMAGE} /bin/sh -c "mysqldump -hmysql -uroot -p${DBROOT} --all-databases | gzip > /backup/backup_mysql.gz" ${SQLIMAGE} /bin/sh -c "mariabackup --host mysql --user root --password ${DBROOT} --backup --rsync --target-dir=/backup"
docker run --rm \
--network $(docker network ls -qf name=${CMPS_PRJ}_) \
--entrypoint= \
-v ${BACKUP_LOCATION}/mailcow-${DATE}/mysql:/backup \
${SQLIMAGE} /bin/sh -c "mariabackup --prepare --target-dir=/backup"
;;& ;;&
--delete-days) --delete-days)
shift shift
@ -173,6 +179,14 @@ function restore() {
mysql) mysql)
SQLIMAGE=$(grep -iEo '(mysql|mariadb)\:.+' ${COMPOSE_FILE}) SQLIMAGE=$(grep -iEo '(mysql|mariadb)\:.+' ${COMPOSE_FILE})
docker stop $(docker ps -qf name=mysql-mailcow) docker stop $(docker ps -qf name=mysql-mailcow)
if [[ -d "${RESTORE_LOCATION}/mysql" ]]; then
docker run --rm \
--network $(docker network ls -qf name=${CMPS_PRJ}_) \
-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 \ docker run \
-it --rm \ -it --rm \
-v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/ \ -v $(docker volume ls -qf name=${CMPS_PRJ}_mysql-vol-1):/var/lib/mysql/ \
@ -184,6 +198,7 @@ function restore() {
echo Restoring... && \ echo Restoring... && \
gunzip < backup/backup_mysql.gz | mysql -uroot && \ gunzip < backup/backup_mysql.gz | mysql -uroot && \
mysql -uroot -e SHUTDOWN;" mysql -uroot -e SHUTDOWN;"
fi
docker start $(docker ps -aqf name=mysql-mailcow) docker start $(docker ps -aqf name=mysql-mailcow)
;; ;;
esac esac
@ -215,7 +230,7 @@ elif [[ ${1} == "restore" ]]; then
echo echo
declare -A FILE_SELECTION declare -A FILE_SELECTION
RESTORE_POINT="${FOLDER_SELECTION[${input_sel}]}" RESTORE_POINT="${FOLDER_SELECTION[${input_sel}]}"
if [[ -z $(find "${FOLDER_SELECTION[${input_sel}]}" -maxdepth 1 -type f -regex ".*\(redis\|rspamd\|mysql\|crypt\|vmail\|postfix\).*") ]]; then if [[ -z $(find "${FOLDER_SELECTION[${input_sel}]}" -maxdepth 1 -regex ".*\(redis\|rspamd\|mysql\|crypt\|vmail\|postfix\).*") ]]; then
echo "No datasets found" echo "No datasets found"
exit 1 exit 1
fi fi