diff --git a/README.md b/README.md index 8d95098..0d1ee64 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,14 @@ Environment variables: `RCLONE_CONFIG` file path for the rclone config file e.g. `/config/rclone.conf` -`RESTIC_PASSWORD` password for the repo +`ENC_PASSWORD` or `ENC_PASSWORD_FILE` password for the repo + +For the database: + +`MYSQL_DUMP_DB` all databases comma sperated: `db1,db2` + +`MYSQL_HOST` + +`MYSQL_USERNAME` + +`MYSQL_PASSWORD` or `MYSQL_PASSWORD_FILE` diff --git a/docker-compose.yml b/docker-compose.yml index c6ed8d7..f9721ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: environment: - RCLONE_REMOTE=gdrive:/backupTest - RCLONE_CONFIG=/config/rclone.conf - - RESTIC_PASSWORD=repopw + - ENC_PASSWORD=repopw - MYSQL_USERNAME=dbuser - MYSQL_PASSWORD=dbPassword - MYSQL_DUMP_DB=dbName1,dbName2 diff --git a/entrypoint.sh b/entrypoint.sh index aa9b5d5..a112d1d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,14 +4,29 @@ set -e [ -z "${RCLONE_REMOTE}" ] && echo "\$RCLONE_REMOTE is not set" && exit 1 [ -z "${RCLONE_CONFIG}" ] && echo "\$RCLONE_CONFIG is not set" && exit 1 -[ -z "${RESTIC_PASSWORD}" ] && echo "\$RESTIC_PASSWORD is not set" && exit 1 + +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 mkdir -p /backup/sqlDump for db in ${MYSQL_DUMP_DB//,/ } do echo "Dumping db: $db" - mysqldump --compact -P 3306 --host $MYSQL_HOST -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD" "$db" > "/backup/sqlDump/$db.sql" + mysqldump --compact -P 3306 --host $MYSQL_HOST -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql" done restic -r "rclone:$RCLONE_REMOTE" --verbose backup "/backup" diff --git a/init.sh b/init.sh index 0b0f2c8..189f5de 100755 --- a/init.sh +++ b/init.sh @@ -4,7 +4,15 @@ set -e [ -z "${RCLONE_REMOTE}" ] && echo "\$RCLONE_REMOTE is not set" && exit 1 [ -z "${RCLONE_CONFIG}" ] && echo "\$RCLONE_CONFIG is not set" && exit 1 -[ -z "${RESTIC_PASSWORD}" ] && echo "\$RESTIC_PASSWORD is not set" && exit 1 + +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 echo "Init new repo"