MySQL

MySQL replication status monitoring

Background

I am running my own authoritative DNS servers for the last few years. In earlier stages I just used registrar-provided DNS, later moved to “Cloud provider” provided DNS and ultimately settled for running my own auth DNS.

Two major requirements pushed me to self-host auth DNS:

  1. Requirement of REST API for DNS needed by the web servers to resolve Letsencrypt certbot DNS-based challenge. This allows me to have internally hosted tools with Letsencrypt issues TLS certificates instead of self-signed ones. The API access is mostly missing in the registrars hosted DNS.
  2. Occasional DDoS on my blog. There have been occasional DDoS on my blog (probably from random people who enjoy doing volumetric attacks). This always worried me about DNS bills during DDoS, especially for low TTL records. The last hosted DNS option I had over a year ago was Google Cloud DNS and they charge $0.40 per million queries per month. This can add a significant amount to the bill if under massive DDoS resulting in many millions of DNS queries. Plus per zone 20 cents charge gets expensive at a scale with a half a dozen domains.

After exploring a few options I settled for running PowerDNS with MySQL backend. This is kind of a comfort zone since I ran similar systems for my employers in past and it worked well. PowerDNS is a great option for authoritative DNS as it has nice documented REST API, CLI utility pdnsutil for easy high-level scripting, supports a bunch of backends to store DNS records from BIND like text files to MySQL. It is also good (automated) support to handle DNSSEC for signing the zone.

Quick simple script for automated database dumps

I tried looking for script for database dumps but most of them are way too complex then a simple solution one can implement. 

Thus, I wrote a quick simple 1 page (infact few lines) bash script for database dumps.

Here’s the code:  

#!/bin/bash

#Script for MySQL automated dumps

dbhost=DB-HOSTNAME-HERE  
dbusername=DB-USERNAME-HERE  
dbpassword=DB-PASSWORD-HERE

# Enter database names here  
dbname=( database1 database2 database3 )

for i in "${dbname[@]}"

do  
timestamp=backup_`date +%F.%T`  
output=$i+$timestamp  
mysqldump -h $dbhost -u $dbusername -p$dbpassword -C $i | bzip2 -c > /backups/MySQL-automated/$output  
done

To use this script, simply add names of database inside brackets in front of “dbname” like
dbname=( database1 database2 database3 ) and that’s all. You will get output in form of compressed .sql file.