repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
nushell/modules/btrfs.nu
Raw# Btrfs Maintenance Script
# This script checks if your system is Btrfs and attempts to fix "Full" states
# by running a balance on chunks > 75% full.
export def maintenance [
mount_point: path = '/' # mount point to check, `/` by default
] {
print "๐ Checking filesystem type..."
let fs_type = df | where Mounted == $mount_point | get Filesystem.0
if $fs_type != "btrfs" {
print $"โ Error: Not a Btrfs filesystem ($fs_type). Aborting."
exit 1
}
print "โ
Filesystem is Btrfs."
print "\n๐ Current Btrfs Usage:"
^btrfs filesystem usage $mount_point
print "\n๐ Starting Btrfs Balance..."
try {
^sudo btrfs balance start -dusage=75 -musage=75 $mount_point
print "โ
Balance command sent successfully."
} catch { |err |
print $"โ Failed to start balance: $err"
print "Ensure you have sudo privileges."
exit 1
}
print "\nโณ Waiting for balance to complete or show status..."
^sudo btrfs status $mount_point
if ($in | str contains "Balance") {
print "\nโ Balance is still running. You can check progress with:"
print $" btrfs balance status $MOUNT_POINT"
}
print "\n๐ Checking storage after balance:"
^btrfs filesystem usage $mount_point
print "\nโ
Maintenance Complete."
}