Skip to content

Instantly share code, notes, and snippets.

@quintindk
quintindk / azure-resource-naming-policy.json
Created June 19, 2021 11:08
Azure Policy to apply naming conventions
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"notequals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
@quintindk
quintindk / remove-transaction.sh
Created November 2, 2022 13:57
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
@quintindk
quintindk / connect.sh
Created November 8, 2022 19:35
Quick script to connect to a VM using bastion from your terminal. This uses tunnels rather than az network bastion ssh because I didn't know to install the ssh add-on in az cli.
#! /bin/bash
subscription=$1
if [[ -n $2 ]]; then
vm_name=$2
fi
if [[ -n $3 ]]; then
vm_username=$3
fi
if [[ -n $4 ]]; then
@quintindk
quintindk / export-binlogs.sh
Created November 14, 2022 10:40
So I improved the previous script using AWK which is relatively simple when you understand that it handles each line individually in a stream i.e. if you need previous lines keep them in a buffer until you're ready to dump them.
#! /bin/bash
database_name=$1
input_file=$2
output_file=$3
temp_file=$(mktemp)
sed '/SET @@SESSION.GTID_NEXT=/d' "$input_file" > "$temp_file"
awk '{