Assorted shell and Python scripts
1#!/usr/bin/env bash
2
3LOGFILE="/var/log/btrfs-snapshot.log"
4SNAP_DATE=$(date '+%Y-%m-%d_%H%M%S')
5
6send_matrix_webhook() {
7 /usr/local/bin/send-matrix-webhook "btrfs-snapshot failed on $(hostname)"
8}
9
10trap send_matrix_webhook SIGINT SIGTERM EXIT
11
12create_snapshot() {
13 if ! btrfs subvolume snapshot -r "$1" "${1}/.snapshots/$2-$SNAP_DATE" >/dev/null; then
14 echo "[$(date '+%Y-%m-%d %H:%M:%S')] Error creating snapshot of $1" | tee -a "$LOGFILE"
15 notify-send -i computer-fail "Error creating snapshot of $1"
16 exit 1
17 else
18 echo "[$(date '+%Y-%m-%d %H:%M:%S')] Create snapshot of $1: OK" | tee -a "$LOGFILE"
19 fi
20}
21
22create_snapshot "/home" "home"