-
Notifications
You must be signed in to change notification settings - Fork 1
/
btrfs-scrub.sh
executable file
·64 lines (48 loc) · 1.31 KB
/
btrfs-scrub.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
lockdir="/run/lock/btrfs-scrub"
lock() {
mkdir -p "$lockdir"
lockfile-create --use-pid "$lockdir" || exit 0
}
unlock() {
lockfile-remove "$lockdir"
}
get_btrfs_mounts() {
declare -a a
declare -A b
while read d m fs r; do
[[ "$fs" == "btrfs" ]] && a+=("$m")
done < /proc/mounts
# deduplicate entries in the array
for i in "${a[@]}"; do
b["$i"]=1;
done
echo "${!b[@]}"
}
main() {
trap unlock EXIT
local mounts="$(get_btrfs_mounts)"
lock
for m in $mounts; do
echo "Starting quick meta-data balance for $m"
echo "btrfs balance start -musage=0 $m"
btrfs balance start -musage=0 "$m"
echo "Starting meta-data balance for $m"
echo "btrfs balance start -musage=20 $m"
btrfs balance start -musage=20 "$m"
done
for m in $mounts; do
echo "Starting quick data balance for $m"
echo "btrfs balance start -dusage=0 $m"
btrfs balance start -dusage=0 "$m"
echo "Starting data balance for $m"
echo "btrfs balance start -dusage=20 $m"
btrfs balance start -dusage=20 "$m"
done
for m in $mounts; do
echo "Starting scrub for $m"
echo "btrfs scrub start -Bd $m"
btrfs scrub start -Bd "$m"
done
}
main "$@"