backup-docker/entrypoint.sh
Niklas 82a5e5b2ab
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone Build encountered an error
fixed empty var check
2021-07-02 20:02:42 +02:00

33 lines
936 B
Bash
Executable File

#!/usr/bin/env sh
set -e
[ -z "${RCLONE_REMOTE}" ] && echo "\$RCLONE_REMOTE is not set" && exit 1
[ -z "${RCLONE_CONFIG}" ] && echo "\$RCLONE_CONFIG is not set" && exit 1
if [ -n "${ENC_PASSWORD}" ]; then
RESTIC_PASSWORD="${ENC_PASSWORD}"
elif [ -n "${ENC_PASSWORD_FILE}" ]; then
RESTIC_PASSWORD=$(cat "$ENC_PASSWORD_FILE")
else
echo "\$ENC_PASSWORD or \$ENC_PASSWORD_FILE is not set" && exit 1
fi
if [ -n "${MYSQL_PASSWORD}" ]; then
MYSQL_PASSWORD_ACTUAL="${MYSQL_PASSWORD}"
elif [ -n "${MYSQL_PASSWORD_FILE}" ]; then
MYSQL_PASSWORD_ACTUAL=$(cat "$MYSQL_PASSWORD_FILE")
fi
mkdir -p /backup/sqlDump
for db in $(echo "$MYSQL_DUMP_DB" | sed 's/,/\n/g')
do
echo "Dumping db: $db"
mysqldump --compact -P 3306 --host "$MYSQL_HOST" -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql"
done
export RESTIC_PASSWORD
restic -r "rclone:$RCLONE_REMOTE" --verbose backup "/backup"