3 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
6 # https://github.com/kdave/btrfsmaintenance
9 # Man page says we could also use a range, i suppose it would be
10 # logical to use a pattern like 5..10 10..20,
11 # but I don't know if this would help us at all.
12 dusage
="1 5 10 20 30 40 50"
15 e
() { echo "cron: $*"; "$@"; }
17 fnd
="findmnt --types btrfs --noheading"
18 for x
in $
($fnd --output "SOURCE" --nofsroot |
sort -u); do
19 mnt
=$
($fnd --output "TARGET" --first-only --source $x)
20 [[ $mnt ]] ||
continue
21 # for comparing before and after balance.
22 # the log is already fairly verbose, so commented.
23 # e btrfs filesystem df $mnt
25 if btrfs filesystem df
$mnt |
grep -q "Data+Metadata"; then
26 for usage
in $dusage; do
27 e btrfs balance start
-dusage=$usage -musage=$usage $mnt
30 e btrfs balance start
-dusage=0 $mnt
31 for usage
in $dusage; do
32 e btrfs balance start
-dusage=$usage $mnt
34 e btrfs balance start
-musage=0 $mnt
35 for usage
in $musage; do
36 e btrfs balance start
-musage=$usage $mnt
39 # e btrfs filesystem df $mnt
42 btrfs scrub status
$mnt | \
43 sed -rn 's/^\s*scrub started at (.*) and finished.*/\1/p'
46 date=$
(date --date="$date" +%s
)
47 # if date is sooner than 90 days ago
48 # the wiki recommends 30 days or so, but
49 # it makes the comp lag like shit for a day,
50 # so I'm going with 90 days.
51 if (( $date > `date +%s` - 60*60*24*30 )); then
52 echo "cron: skiping scrub of $mnt"
56 e btrfs scrub start
-Bd $mnt