Borgbackup, Private SSH Keys, and MacOS

Thursday, February 23, 2023

I use a MacBook Pro for work. It’s not ideal, but better than Windows. I also use the phenomenal Borg and Borgmatic for my backups up to BorgBase . I wanted to get my work laptop backed up in case of an issue, but was having problems getting OSX Ventura to read the unlocked private SSH key I use to connect. I ended up concocting this script which searches for the correct environment variables and sets them so the cronjob can use the key.

#!/bin/bash

auth=`find /var/folders/db -user $LOGNAME -type s -name "*agent*" -print 2>/dev/null`
auth_pid=`echo $auth | cut -d '/' -f8 | cut -d '.' -f2`
SSH_AUTH_SOCK=$auth
SSH_AGENT_PID=$auth_pid

export SSH_AUTH_SOCK
export SSH_AGENT_PID

/opt/homebrew/bin/borgmatic create -c $HOME/.borgmatic.yaml --stats

Although Ventura doesn’t recommend using cron anymore in favor of launchd, it still works for the time being so I just threw it in a cronjob.

backupmacosborg

Using Atlantis with OpenTofu

gitlab, gitlab runners, k3s, and building all the things