Created
November 2, 2022 13:57
-
-
Save quintindk/905ecf1705bd09bf4a24cbf6437370bb to your computer and use it in GitHub Desktop.
This script removes the mysql heartbeat transactions from a mysql binlog export.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
total=0 | |
while :; do | |
start_line=$(cat $1 | grep -m 1 -n -B 4 'Table_map: `mysql`.`heartbeat` mapped to number 150' | grep 'BEGIN' | awk -F'-' '{print $1}') | |
end_line=$(cat $1 | grep -m 1 -n -A 12 'Table_map: `mysql`.`heartbeat` mapped to number 150' | grep 'COMMIT\/\*!\*\/;' | awk -F'-' '{print $1}') | |
if [[ ! -z "$start_line" ]]; then | |
((lines=end_line-start_line)) | |
((total+=lines)) | |
echo "from $start_line to $end_line, $lines removed, total $total" | |
sed -i "${start_line},${end_line}d" $1 | |
else | |
echo "breaking $start_line" | |
break 1 | |
fi | |
done | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've improved this one here.