====== Linux ZFS ======
https://lepkov.ru/zfs-cheatsheet/ backup https://habr.com/ru/companies/macloud/articles/547056/ \\
- manual old one\\
# zfs pools and mount points
tree /dev/zvol/
/dev/zvol/
├── rpool
├── data
│ ├── vm-100-disk-1 -> ../../../zd0
│ └── vm-100-disk-1-part1 -> ../../../zd0p1
└── swap -> ../../zd16
zfs get all rpool/data/subvol-111-disk-1 | grep com
zfs set compression=off rpool/data/subvol-111-disk-1
zfs get compressratio
NAME PROPERTY VALUE SOURCE
rpool compressratio 1.07x -
rpool/ROOT compressratio 1.78x -
rpool/ROOT/pve-1 compressratio 1.78x -
rpool/data compressratio 1.06x -
rpool/data/subvol-110-disk-0 compressratio 1.77x -
# start trim operation
zpool trim rpool
# show status
zpool status -t rpool
===== ZFS move - recompress =====
++++ Recompress zfs|
#You basically have to rewrite every block of every file.
#A reasonably safe and simple way to do it is like this, however this
#assumes you have sufficient space.
#First set the new value for compression.
zfs set compression=on tank/fs
#Send a snapshot to a temporary name
zfs snapshot tank/***@1
zfs send -R tank/***@1 | zfs recv -vFd tank/fs-recompressed
#Mark the original as readonly and send anything newly written
#since the 'zfs send' above started.
zfs set readonly=on tank/fs
zfs snapshot tank/***@2
zfs send -i tank/***@1 tank/***@2 | zfs recv -v tank/fs-recompressed
#Now delete the original and rename the newone into its place.
zfs delete tank/fs
zfs rename tank/fs-recompressed tank/fs
#Note that the new tank/fs will have all the the snapshots of
#the original as well since -R was used with the zfs send.
++++
===== ZFS - notification =====
++++ telegram notification zfs|
# https://github.com/leovp/telegram_notifications
nano /etc/zfs/zed.d/zed-telegram.sh
#!/bin/bash
TELEGRAM_BOT_TOKEN="righttoken" # put your token here
TELEGRAM_CHAT_ID="chatid" # your chat_id for sending notification
subject="$1"
details="$2"
MESSAGE="🚨 ZFS Alert on $(hostname) 🚨
Event: $subject
Details:
$details"
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=$MESSAGE"
chmod +x /etc/zfs/zed.d/zed-telegram.sh
# zed-functions.sh Modified zed_notify function
zed_notify()
{
zed_notify_email "${subject}" "${pathname}"; rv=$?
[ "${rv}" -eq 0 ] && num_success=$((num_success + 1))
[ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1))
# Execute external Telegram script if it exists
if [ -x "/etc/zfs/zed.d/zed-telegram.sh" ]; then
/etc/zfs/zed.d/zed-telegram.sh "${subject}" "$(cat "${pathname}")"; rv=$?
[ "${rv}" -eq 0 ] && num_success=$((num_success + 1))
[ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1))
fi
}
++++
===== ZFS backup =====
# create file 20 gb
dd if=/dev/zero of=/mnt/sdb3/zpool_test bs=1G count=20
# create pool on file
zpool create test /mnt/sdb3/zpool_test
# send data replication to local system
zfs send -vR rpool@snap1 | zfs receive test -F
# send data of zpool to file
zfs send -vR rpool@snap1 > /mnt/pve/backup/zfs-pve-rpool-20240624.backup
# recieve
zfs receive rpool < /mnt/pve/backup/zfs-pve-rpool-20240624.backup
zpool attach rpool nvme-512GB_SSD_NJM358R015419P70GX-part3 ata-SPCC_Solid_State_Disk_AA230918S351201018-part3
zpool remove rpool /mnt/sdb3/zpool_mirror1_1
===== ZFS monitoring =====
https://blog.roberthallam.org/2022/09/monitoring-zfs-with-influxdb-grafana-publishing-and-reflection-part-5/ \\
https://github.com/richardelling/zpool_influxdb \\