Skip to content

Instantly share code, notes, and snippets.

@rluisr
Last active May 21, 2021 17:33
Show Gist options
  • Save rluisr/a120063e2dcbdf10157901e75abae6c5 to your computer and use it in GitHub Desktop.
Save rluisr/a120063e2dcbdf10157901e75abae6c5 to your computer and use it in GitHub Desktop.
Download binary logs from Amazon RDS.
#!/bin/bash
set -eux
MYSQL_HOST=''
MYSQL_USER=''
MYSQL_PASS=''
EXEC_MYSQL="docker run -e MYSQL_PWD=${MYSQL_PASS} -it --rm mysql:5.6 mysql"
EXEC_MYSQLBINLOG="docker run -e MYSQL_PWD=${MYSQL_PASS} -v ${PWD}:/dump -it --rm mysql:5.6 mysqlbinlog"
binlog_files=$( eval "${EXEC_MYSQL} -h ${MYSQL_HOST} -u ${MYSQL_USER} -e 'show master logs' | grep 'mysql-bin' | awk '{print \$2}'" )
for binlog_file in $binlog_files
do
eval "${EXEC_MYSQLBINLOG} -h ${MYSQL_HOST} -u ${MYSQL_USER} --read-from-remote-server ${binlog_file} --raw --result-file=/dump/"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment