MYSQL Backup to S3 script

Script

#!/bin/bash

# Set the enviroment variable so read function knows to seperate on ",".
export IFS=","

NOW=$(date +"%Y_%m_%d_%H_%M")

DATABASES_CONFIG_FILE="/home/bfnadmin/databases.csv"

S3_ENDPOINT="https://my-s3-storage.com"
S3_BUCKET="s3://sql-backups"

TEMP_BACKUP_DIR="backups"

while read HOST USERNAME PASSWORD DB_SRV DB_NAME;
do
echo "[$DB_SRV - $DB_NAME]"

mysqldump --single-transaction --quick --lock-tables=false \
-h $HOST \
-u $USERNAME \
-p$PASSWORD \
$DB_NAME | gzip > $TEMP_BACKUP_DIR/$DB_SRV-$DB_NAME-$NOW.sql.gz

echo "Uploading backup to S3 storage - $DB_SRV-$DB_NAME-$NOW.sql.gz"

aws --endpoint-url=$S3_ENDPOINT s3 cp $TEMP_BACKUP_DIR/$DB_SRV-$DB_NAME-$NOW.sql.gz $S3_BUCKET

rm $TEMP_BACKUP_DIR/$DB_SRV-$DB_NAME-$NOW.sql.gz

echo -e "\n\n"

done < $DATABASES_CONFIG_FILE

~/ .aws/credentials

[default]
aws_access_key_id=xxx
aws_secret_access_key=yyy

databases.csv

ip_Address,sql_user,sql_password,Host_Display_name,DB_Name