diff --git a/entrypoint.sh b/entrypoint.sh index bb7c20db9ebe3cc67dd7b78c17cd967a9b18d482..2d3d4c2bb35f0a9f80ab4007e78d6966c27b3b1f 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}