backup-docker/entrypoint.sh

33 lines
872 B
Bash
Raw Normal View History

2021-03-29 20:28:09 +00:00
#!/bin/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
2021-06-17 20:49:09 +00:00
if [ -z "${ENC_PASSWORD}" ]
then
RESTIC_PASSWORD="${ENC_PASSWORD}"
else if [ -z "${ENC_PASSWORD_FILE}" ]
RESTIC_PASSWORD=$(cat $ENC_PASSWORD_FILE)
else
echo "\$ENC_PASSWORD or \$ENC_PASSWORD_FILE is not set" && exit 1
fi
if [ -z "${MYSQL_PASSWORD}" ]
then
MYSQL_PASSWORD_ACTUAL="${MYSQL_PASSWORD}"
else if [ -z "${MYSQL_PASSWORD_FILE}" ]
MYSQL_PASSWORD_ACTUAL=$(cat $MYSQL_PASSWORD_FILE)
fi
2021-03-29 20:28:09 +00:00
2021-03-30 20:09:32 +00:00
mkdir -p /backup/sqlDump
for db in ${MYSQL_DUMP_DB//,/ }
do
2021-03-30 20:15:57 +00:00
echo "Dumping db: $db"
2021-06-17 20:49:09 +00:00
mysqldump --compact -P 3306 --host $MYSQL_HOST -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql"
2021-03-30 20:09:32 +00:00
done
2021-03-29 20:28:09 +00:00
restic -r "rclone:$RCLONE_REMOTE" --verbose backup "/backup"