Backup AWS RDS binary files to AWS S3
#!/bin/bash
FILES="$(mysql -u database.user -pdatabase.password -h database.host -Bse 'show binary logs' | cut -f 1)"
for file in $FILES
do
if [ ! -f files/$file ]; then
logger "Trying to download new file: $file"
echo "Trying to download new file: $file"
mysqlbinlog \
--no-defaults \
--read-from-remote-server \
--host=database.host \
--port=3306 \
--user database.user \
--password=database.password \
--result-file=files/$file \
$file
fi
done
# Move files that are older than 24 hours to Amazon
find files/* -mmin +1440 -exec aws s3 mv {} s3://bucketname/{} \;