Skip to content

Instantly share code, notes, and snippets.

@hiAndrewQuinn
Created September 8, 2025 15:33
Show Gist options
  • Select an option

  • Save hiAndrewQuinn/1a0c019a76fdabbf0e6edb2e68ba5a47 to your computer and use it in GitHub Desktop.

Select an option

Save hiAndrewQuinn/1a0c019a76fdabbf0e6edb2e68ba5a47 to your computer and use it in GitHub Desktop.
POSIX shell script for hourly backups of a KeePass database to tarsnap. Season to taste.
#!/bin/sh
set -e
KEYFILE="$HOME/.tarsnap.key"
CACHEDIR="$HOME/.tarsnap-cache"
SOURCE_FILE="$HOME/Documents/Passwords.kdbx" # or wherever it is
HOSTNAME=$(/usr/bin/hostname)
BASENAME=$(/usr/bin/basename "$SOURCE_FILE")
TIMESTAMP=$(/usr/bin/date +"%Y-%m-%d_%H-%M-%S")
ARCHIVE_NAME="${HOSTNAME}-${BASENAME}-${TIMESTAMP}"
/usr/bin/date --iso-8601=seconds
/usr/bin/tarsnap -c \
--keyfile "$KEYFILE" \
--cachedir "$CACHEDIR" \
-f "$ARCHIVE_NAME" \
--print-stats \
--humanize-numbers \
"$SOURCE_FILE"
/usr/bin/echo "---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment