awslabs / rds-support-tools

Amazon RDS Support Tools contains utilities, sql, scripts and views which are useful in a RDS environment
https://aws.amazon.com/rds/
Apache License 2.0
217 stars 229 forks source link

Potential bug in rds-binlog-to-s3.sh as the last binary log might still be updated by the master #84

Open vinodpandey opened 1 year ago

vinodpandey commented 1 year ago

In https://github.com/awslabs/rds-support-tools/blob/main/mysql/rds-binlog-to-s3/rds-binlog-to-s3.sh, we are using "show master logs" to get the master log file names.

mysql_binlog_filename=$(mysql -u $dbuser -h $RDS -e "show master logs"|grep "mysql-bin"|awk '{print $1}')

The master might be updating the last binary log file based on the MySQL server configuration. In that case, when we download the last binary log file from the list, we will get incomplete data.

One possible solution can be to download all binary logs except the last one.

# converting to array by wrapping with ()
# we will remove the last element of the array later

mysql_binlog_filename=($(mysql -u $dbuser -h $RDS -e "show master logs"|grep "mysql-bin"|awk '{print $1}'))

# we are excluding the last element from mysql_binlog_filename as the master
# may still be updating the binary log
for file in ${mysql_binlog_filename[@]::${#mysql_binlog_filename[@]}-1}