Skip to content

Instantly share code, notes, and snippets.

@quintindk
Created November 2, 2022 13:57
Show Gist options
  • Save quintindk/905ecf1705bd09bf4a24cbf6437370bb to your computer and use it in GitHub Desktop.
Save quintindk/905ecf1705bd09bf4a24cbf6437370bb to your computer and use it in GitHub Desktop.
This script removes the mysql heartbeat transactions from a mysql binlog export.
#! /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"
@quintindk
Copy link
Author

I've improved this one here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment