-
-
Save ThomDietrich/b95c433ea13f2cd1c921 to your computer and use it in GitHub Desktop.
ZFS scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "ZFS listing:" | |
/sbin/zfs list | |
echo | |
echo "ZFS compression ratio:" | |
/sbin/zfs get compressratio | /usr/bin/grep -v @ | |
echo | |
echo "ZFS ARC (Adaptive Replacement Cache):" | |
/sbin/sysctl -n kstat.zfs.misc.arcstats.c | awk '{print "ZFS ARC mem: " ($1/1024/1024/1024) " GB"}' | |
/sbin/sysctl -n kstat.zfs.misc.arcstats.hits kstat.zfs.misc.arcstats.misses | sed 'N;s/\n/ /g' | awk '{ print "ZFS ARC hitratio: " $1/($1+$2)*100 "%" }' | |
echo | |
echo "ZPool Status:" | |
/sbin/zpool status | |
echo | |
echo "ZPool iostat:" | |
/sbin/zpool iostat -v | |
echo | |
echo "Drive ID:" | |
for i in `/sbin/zpool status | /usr/bin/sed -n "s/[^a-z]\{1,\}\([a-z]\{2,3\}[0-9]\{1,\}\).\{1,\}/\1/g p"`; | |
do | |
echo -n " $i: " | |
/usr/local/sbin/smartctl -i /dev/$i | /usr/bin/sed -n -e '5,7p' | /usr/bin/sed -e 's/^.\{1,\}:[^0-9A-Za-z]\{1,\}//g' | /usr/bin/sed -n -e 'N;s/\n/ (/;N;s/\n/) - S:/;p' | |
done | |
echo | |
echo "Drive health:" | |
for i in `/sbin/zpool status | /usr/bin/sed -n "s/[^a-z]\{1,\}\([a-z]\{2,3\}[0-9]\{1,\}\).\{1,\}/\1/g p"`; | |
do | |
echo -n " $i: " | |
/usr/local/sbin/smartctl -H /dev/$i | /usr/bin/grep -Eo "result: .+" | |
done | |
echo | |
echo "Drive temperature:" | |
for i in `/sbin/zpool status | /usr/bin/sed -n "s/[^a-z]\{1,\}\([a-z]\{2,3\}[0-9]\{1,\}\).\{1,\}/\1/g p"`; | |
do | |
echo -n " $i: " | |
/usr/local/sbin/smartctl -l scttempsts /dev/$i | /usr/bin/sed -n -e "9p" | /usr/bin/grep -Eo "[0-9?]+ Celsius" | |
done | |
echo | |
echo "ZFS snapshots:" | |
/sbin/zfs list -t snapshot | /usr/bin/awk 'BEGIN { LAST = "a"} { match($0,"^.+@"); NEXT = substr($0,0,RLENGTH); if (LAST != NEXT) {print ""; LAST = NEXT;}; print $0; }' | |
echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
WEEKDAY=$(date -j +%u); | |
for TARGET in $(zfs list -t filesystem | sed -n 3,/eof/p | awk '{ print $1 }' ) | |
do | |
if [ $WEEKDAY = "1" ]; then | |
# echo "destroying: $TARGET@2weeksago"; | |
zfs destroy -f $TARGET@2weeksago | |
# echo "backup: $TARGET" | |
zfs rename -r $TARGET@1weekago @2weeksago | |
else | |
zfs destroy -f $TARGET@1weekago | |
fi | |
zfs rename -r $TARGET@6daysago @1weekago | |
zfs rename -r $TARGET@5daysago @6daysago | |
zfs rename -r $TARGET@4daysago @5daysago | |
zfs rename -r $TARGET@3daysago @4daysago | |
zfs rename -r $TARGET@2daysago @3daysago | |
zfs rename -r $TARGET@yesterday @2daysago | |
zfs snapshot -r $TARGET@yesterday | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment