#!/usr/bin/env bash LOGFILE="/var/log/btrfs-snapshot.log" SNAP_DATE=$(date '+%Y-%m-%d_%H%M%S') send_matrix_webhook() { /usr/local/bin/send-matrix-webhook "btrfs-snapshot failed on $(hostname)" } trap send_matrix_webhook SIGINT SIGTERM EXIT create_snapshot() { if ! btrfs subvolume snapshot -r "$1" "${1}/.snapshots/$2-$SNAP_DATE" >/dev/null; then echo "[$(date '+%Y-%m-%d %H:%M:%S')] Error creating snapshot of $1" | tee -a "$LOGFILE" notify-send -i computer-fail "Error creating snapshot of $1" exit 1 else echo "[$(date '+%Y-%m-%d %H:%M:%S')] Create snapshot of $1: OK" | tee -a "$LOGFILE" fi } create_snapshot "/home" "home"