From 39e3a0b18b3cc752d869a0bf79657e9dbd659ed5 Mon Sep 17 00:00:00 2001 From: Dmitriy Safronov <zimniy@cyberbrain.pw> Date: Sat, 9 Apr 2022 18:52:24 +0300 Subject: [PATCH] entrypoint --- entrypoint.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index bb7c20d..2d3d4c2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,13 +26,18 @@ backup () { test -z "${MYSQL_PASS}" || ( echo "Setting [MYSQL_PASS] environment variable is insecure, use passwordfile [/password] instead"; PASS="${MYSQL_PASS}" ) test -f /password && PASS="$(cat /password)" - unset MYSQL_HOST MYSQL_PORT MYSQL_USER MYSQL_PASS + test -n "${MYSQL_FILE}" && BACKUP_PREFIX="${MYSQL_FILE}" || BACKUP_PREFIX="${HOST}_${PORT}" + + unset MYSQL_HOST MYSQL_PORT MYSQL_USER MYSQL_PASS MYSQL_FILE # Create final Backup Directory - mkdir -p "${BACKUPDIR}" + test -d "${BACKUPDIR}" || ( echo "There might be an error: no final backup dir. Will create one..."; mkdir -p "${BACKUPDIR}" ) + test -w "${BACKUPDIR}" || ( echo "There might be an error: no write access to final backup dir. Will change rights..."; chmod -Rc u+w "${BACKUPDIR}" ) # Create temp Backup Directory TEMPDIR="${BACKUPDIR}/.${NOW}" + test -d "${TEMPDIR}" || mkdir -p "${TEMPDIR}" + test -w "${TEMPDIR}" || ( echo "There might be an error: no write access to temp backup dir. Will change rights..."; chmod -Rc u+w "${TEMPDIR}" ) # Create temp Backup Config CONFIG="$(mktemp)" @@ -61,11 +66,13 @@ backup () { # ZIP BACKUP # cd $TEMPDIR - tar -zcvf ${HOST}_${PORT}-${NOW}.tar.gz *.sql + tar -zcvf ${BACKUP_PREFIX}-${NOW}.tar.gz *.sql + echo "---" + du -h ${BACKUP_PREFIX}-${NOW}.tar.gz cd - > /dev/null # MOVE BACKUP TO BACKUP DIR # - mv -f ${TEMPDIR}/${HOST}_${PORT}-${NOW}.tar.gz "${BACKUPDIR}" + mv -f ${TEMPDIR}/${BACKUP_PREFIX}-${NOW}.tar.gz "${BACKUPDIR}" # CLEANUP # rm -rf ${TEMPDIR} -- GitLab