Grandfather, Father, Son Rotation Script

Here’s a simple script I put together to rotate backup files in a given directory with decreasing resolution the further away we get from the current time.

#!/bin/bash set -euo pipefail DRYRUN=${DRYRUN:-1} DIR=${DIR:-'/backups/mysql'} HOURS=${HOURS:-48} DAYS=${DAYS:-35} MONTHS=${MONTHS:-24} usage() { echo "usage: DRYRUN=0 DIR=/backups HOURS=48 DAYS=30 MONTHS=24 $0" exit 1 } if [ $DRYRUN -eq 1 ]; then echo "DRYRUN: No changes will be made" fi if [ "$HOURS" -lt 0 ] || [ "$DAYS" -lt 1 ] || [ "$MONTHS" -lt 1 ]; then echo "ERROR: Cannot have negative rotation" usage fi ## Bail and cleanup if we exit early cleanup() { find $DIR -type f -execdir rename 's/.process$//g' '{}' \; } trap cleanup EXIT trap cleanup SIGINT ## Flag all the files for processing find $DIR -type f | grep -v '.process$' | xargs -I{} mv {}{,.process} while [ $MONTHS -gt 0 ]; do MONTHS=$(($MONTHS-1)) days=$(( ( $(date '+%s') - $(date -d "$MONTHS months ago" '+%s') ) / 86400 )) file=$(find $DIR -type f -mtime "+$days" | sort -n | tail -n1) if [ "$DRYRUN" -eq 0 ]; then rename 's/.process$//g' "$file" else echo "MONTH: $MONTHS $file" | sed 's/.process$//' fi done while [ $DAYS -gt 0 ]; do DAYS=$(($DAYS-1)) file=$(find $DIR -type f -mtime "+$DAYS" | sort -n | tail -n1) if [ "$DRYRUN" -eq 0 ]; then rename 's/.process$//g' "$file" else echo "DAY: $DAYS $file" | sed 's/.process$//' fi done while [ $HOURS -gt 0 ]; do HOURS=$(($HOURS-1)) minutes=$(($HOURS*60)) file=$(find $DIR -type f -mmin "+$minutes" | sort -n | tail -n1) if [ "$DRYRUN" -eq 0 ]; then rename 's/.process$//g' "$file" else echo "HOUR: $HOURS $file" | sed 's/.process$//' fi done ## Delete all remaining files [ "$DRYRUN" -eq 0 ] && rm "$DIR"/*.process 2> /dev/null
Code language: Bash (bash)

Grafana Overview Dashboard

There should be an “Overview” dashboard for your infrastructure that gives you a quick, high level view of how everything is working. The idea isn’t to necessarily use this for diagnosing problems, but for knowing where to look next. Here’s a quick one I put together for fun.

Radio Milwaukee AppleScript

I’ve been listening to Radio Milwaukee a lot lately. They play it at a lot of my favorite coffee shops in Milwaukee that I haven’t been able to visit for a while.

I like to listen to music in the Music app (previously iTunes) because I have AirPlay speakers in my office and around the house. This script opens the Radio Milwaukee stream and hides the Music app.

tell application "Music" open location "" play set visible of every window to false end tell
Code language: AppleScript (applescript)

The Day I Met Joe Biden

The Friday before the 2016 Presidential Election, I was at the same coffee shop that I had been going to almost every day for years. At one point I looked up from my laptop and noticed someone with an ear piece standing outside the window. After working for a while longer, I remembered that Vice President Biden was speaking in Madison that morning, campaigning for Hillary Clinton and Russ Feingold, who was running for his old Senate seat again.

A little while later, I noticed that Secret Service had actually stopped letting people in without Press credentials and there were many reporters inside and outside the cafe.

The next thing I remember is the motorcade coming around the corner and stopping right in front of Colectivo. I just found the moment in Slack where I was in the middle of a conversation when I said:

brb, joe biden is here
i think he’s literally walking into Colectivo
he is

First Russ Feingold came in. I had been sitting in the front of the cafe when all this started, so I was one of the first people to shake his hand when he walked in the door. (It probably didn’t hurt that I had a huge Russ Feindgold bumper sticker on the cover of my laptop 🙃)

Then Joe Biden came in and shook everyone’s hand. He noticed someone with a Green Bay Packers phone cover and told a story about how he got out of school early on Mondays if the Packers won. Then he walked into the middle of the restaurant and announced, “I’m Joe Biden and I work for Russ Feingold.”

I think about this day a lot when I encounter people that are less than enthusiastic about the idea of a President Biden. He wasn’t my first choice in the Democratic primary, but he is qualified to be President, he’s a good person, and he would make things better for most people instead of worse. In a lot of ways, he’s the opposite of our current President.

iOS 14 Smart Stack

For me, the best new iOS 14 feature is the Smart Stack widget. Widgets in general are neat, but I’m hoping the Smart Stack technology will be implemented in other parts of iOS as well.

If you’re not aware, Smart Stack is basically a way for apps to report when they have something interesting to report. In the example below, it had just started raining in Madison, so the weather widget was surfaced.

The obvious extension of this is for Watch complications. Having a temperature complication that switched to a weather conditions complication to warn you about pending inclement weather is a simple example that would make the Watch more useful and easier to use.

Switching to Calendar when you have a meeting coming up, Reminders when you have a task due, or Stocks when the stock market would be very convenient.

A Smart Stack on the lock screen would also be interesting. While you can already put widgets in the dashboard to the left of the lock screen, a single, customizable Smart Stack on the lock screen itself would be able to quickly surface similarly important information about weather, an important meeting, breaking news, and so on.

Fingers crossed for iOS 15. 🤞