summaryrefslogtreecommitdiff
path: root/slogthedog.sh
blob: 7e00a4bb1ce91cc18731114612dc323451b96a98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# slogthedog.sh - Detect ZFS pools missing SLOGs and offer to add one.
# Because sometimes the sync log needs a good boy.

clear
cat << "EOF"
      __
  __ /o \_
<___/---'
🐢 SLOG THE DOG v1.0
-------------------------------
 Fetching sync logs since 2025
EOF

echo ""
echo "πŸ” Scanning ZFS pools for missing SLOGs..."

for pool in $(zpool list -H -o name); do
  if ! zpool status "$pool" | grep -q 'logs'; then
    echo "πŸ›‘ Pool '$pool' has no SLOG."
    echo -n "Do you want to add a SLOG device to this pool? [y/N]: "
    read answer
    if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
      echo ""
      echo "🐾 Available GPT-capable drives:"
      gpart show | grep "GPT" | awk '{print $1}' | sort -u
      echo -n "πŸ‘‰ Enter device name to use (e.g. nvd0 or nvme0n1): "
      read dev
      echo ""
      echo "🧼 Prepping /dev/$dev..."
      gpart destroy -F /dev/$dev >/dev/null 2>&1
      gpart create -s GPT /dev/$dev
      gpart add -t freebsd-zfs -l slog_${pool} -s 16G /dev/$dev
      echo "βž• Adding /dev/gpt/slog_${pool} as log device to $pool..."
      zpool add "$pool" log /dev/gpt/slog_${pool}
      echo "βœ… SLOG added to pool '$pool' using /dev/gpt/slog_${pool}"
      echo ""
    else
      echo "❌ Skipping pool '$pool'"
    fi
  else
    echo "βœ… Pool '$pool' already has a SLOG."
  fi
done

echo ""
echo "🏁 Done. Slog the Dog is waggin’ his tail. All pools checked."