X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=btrfsmaint;h=d2263257d412b4da2d9e37e5c1678641e301e8f6;hb=3ca4714d6b02ff279a0c724415f3e0a3a6f49059;hp=33cae4a36280351c170155f11fc83ba8ca3b2102;hpb=ea108a03dfa2d7f73447c0b14210d766e5ee5d9b;p=distro-setup diff --git a/btrfsmaint b/btrfsmaint index 33cae4a..d226325 100755 --- a/btrfsmaint +++ b/btrfsmaint @@ -46,7 +46,8 @@ usage() { Usage: ${0##*/} [ARGS] Do btrfs maintence or stop if xprintidle shows a user -force Run regardless of user idle status on all disks. +force Run regardless of user idle status on all disks and do scrub + regardless of when it was last run. check Only check if an existing maintence should be cancelled due to nonidle user. Also, runs in a loop every 20 seconds for 10 minutes. @@ -102,7 +103,6 @@ main() { fi - tmp=$(mktemp) fnd="findmnt --types btrfs --noheading" for x in $($fnd --output "SOURCE" --nofsroot | sort -u); do mnt=$($fnd --output "TARGET" --first-only --source $x) @@ -113,10 +113,22 @@ main() { # Only run for $check, since it runs in parallel to non-check, avoid # race condition. if $check; then - if ! btrfs dev stats -c $mnt >$tmp; then - if diff -q $mnt/btrfs-dev-stats $tmp; then - diff -u $mnt/btrfs-dev-stats $tmp | mail -s "$HOSTNAME: error: btrfs dev stats -c $mnt" root@localhost - cat $tmp >$mnt/btrfs-dev-stats + tmp=$(mktemp) + # if mnt is /, avoid making a buggy looking path + stats_path=${mnt%/}/btrfs-dev-stats + if [[ ! -e $stats_path ]]; then + btrfs dev stats -c $mnt >$stats_path ||: # populate initial reading + elif ! btrfs dev stats -c $mnt >$tmp; then + if ! diff -q $stats_path $tmp; then + exim -t <$stats_path fi fi rm -f $tmp @@ -164,7 +176,7 @@ main() { sed -rn 's/^\s*scrub started at (.*) and finished.*/\1/p' ) fi - if [[ $date ]]; then + if ! $force && [[ $date ]]; then if $dryrun; then echo "$0: last scrub finish for $mnt: $date" fi @@ -179,8 +191,8 @@ main() { continue fi fi - # -c 2 -n 4 is from btrfsmaintenance, does ionice - e btrfs scrub start -Bd -c 2 -n 4 $mnt + # btrfsmaintenance does -c 2 -n 4, but I want lowest pri. + e btrfs scrub start -Bd -c 3 $mnt # We normally only do one disk since this is meant to be run while I sleep # and if we try to do all disks, we invariably end up doing a scrub still