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: $*"; "$@"; }
19 idle_time
=$
(xprintidle
2>/dev
/null
) ||
:
20 # 3 hours, assume a movie might run that long.
21 if [[ $idle_time ]] && (( idle_time
< 1000 * 60 * 60 * 3 )); then
28 if [[ $1 == check
]]; then
36 fnd
="findmnt --types btrfs --noheading"
37 for x
in $
($fnd --output "SOURCE" --nofsroot |
sort -u); do
38 mnt
=$
($fnd --output "TARGET" --first-only --source $x)
39 [[ $mnt ]] ||
continue
42 btrfs scrub cancel
$mnt &>/dev
/null ||
:
49 # for comparing before and after balance.
50 # the log is already fairly verbose, so commented.
51 # e btrfs filesystem df $mnt
53 if btrfs filesystem df
$mnt |
grep -q "Data+Metadata"; then
54 for usage
in $dusage; do
55 e btrfs balance start
-dusage=$usage -musage=$usage $mnt
58 e btrfs balance start
-dusage=0 $mnt
59 for usage
in $dusage; do
60 e btrfs balance start
-dusage=$usage $mnt
62 e btrfs balance start
-musage=0 $mnt
63 for usage
in $musage; do
64 e btrfs balance start
-musage=$usage $mnt
67 # e btrfs filesystem df $mnt
70 btrfs scrub status
$mnt | \
71 sed -rn 's/^\s*scrub started at (.*) and finished.*/\1/p'
74 date=$
(date --date="$date" +%s
)
75 # if date is sooner than 90 days ago
76 # the wiki recommends 30 days or so, but
77 # it makes the comp lag like shit for a day,
78 # so I'm going with 90 days.
79 if (( $date > `date +%s` - 60*60*24*30 )); then
80 echo "cron: skiping scrub of $mnt"
84 e btrfs scrub start
-Bd $mnt