daily pastebin goal
38%
SHARE
TWEET

/usr/local/sbin/btrfs-scrub.sh

a guest Nov 24th, 2017 392 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3.  
  4. # By Marc MERLIN <marc_soft@merlins.org> 2014/03/20
  5. # License: Apache-2.0
  6.  
  7.  
  8. which btrfs >/dev/null || exit 0
  9.  
  10.  
  11. export PATH=/usr/local/bin:/sbin:$PATH
  12.  
  13.  
  14. # bash shortcut for `basename $0`
  15. PROG=${0##*/}
  16. lock=/var/run/$PROG
  17.  
  18. FILTER='(^Dumping|balancing, usage)'
  19. test -n "$DEVS" || DEVS=$(grep '\<btrfs\>' /proc/mounts | awk '{ print $1 }' | sort -u)
  20. for btrfs in $DEVS
  21. do
  22.     tail -n 0 -f /var/log/syslog | grep "BTRFS: " | grep -Ev '(disk space caching is enabled|unlinked .* orphans|turning on discard|device label .* devid .* transid|enabling SSD mode|BTRFS: has skinny extents|BTRFS: device label)' &
  23.     mountpoint="$(grep "$btrfs" /proc/mounts | awk '{ print $2 }' | sort | head -1)"
  24.     logger -s "Quick Metadata and Data Balance of $mountpoint ($btrfs)" >&2
  25.     # Even in 4.3 kernels, you can still get in places where balance
  26.     # won't work (no place left, until you run a -m0 one first)
  27.     btrfs balance start -musage=0 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
  28.     btrfs balance start -musage=20 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
  29.     # After metadata, let's do data:
  30.     btrfs balance start -dusage=0 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
  31.     btrfs balance start -dusage=20 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
  32.     # And now we do scrub. Note that scrub can fail with "no space left
  33.     # on device" if you're very out of balance.
  34.     logger -s "Starting scrub of $mountpoint" >&2
  35.     echo btrfs scrub start -Bd $mountpoint
  36.     ionice -c 3 nice -10 btrfs scrub start -Bd $mountpoint
  37.     pkill -f 'tail -n 0 -f /var/log/syslog'
  38.     logger "Ended scrub of $mountpoint" >&2
  39. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top