-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrfs_maintenance.sh
77 lines (63 loc) · 2.32 KB
/
btrfs_maintenance.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
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# vim:set syntax=sh:
# kate: syntax bash;
# SPDX-License-Identifier: CC-BY-SA-4.0
# Copyright 2021 Jakob Meng, <[email protected]>
exit # do not run any commands when file is executed
#
# Btrfs Maintenance
#
# NOTE: Also have a look at periodic btrfs filesystem monitoring in btrfs_stats.sh
# Enable periodic btrfs balance and btrfs scrub
# NOTE: Only available on Debian 10 (Buster) and later
# Ref.: /usr/share/doc/btrfsmaintenance/README.Debian
apt install btrfsmaintenance
cat << 'EOF' | patch -p0 -d /
--- /etc/default/btrfsmaintenance.orig 2019-08-27 08:04:32.838921055 +0200
+++ /etc/default/btrfsmaintenance 2019-08-27 08:04:53.502863986 +0200
@@ -40,7 +40,7 @@
# (Colon separated paths)
# The special word/mountpoint "auto" will evaluate all mounted btrfs
# filesystems
-BTRFS_BALANCE_MOUNTPOINTS="/"
+BTRFS_BALANCE_MOUNTPOINTS="auto"
## Path: System/File systems/btrfs
## Type: string(none,daily,weekly,monthly)
@@ -81,7 +81,7 @@
# (Colon separated paths)
# The special word/mountpoint "auto" will evaluate all mounted btrfs
# filesystems
-BTRFS_SCRUB_MOUNTPOINTS="/"
+BTRFS_SCRUB_MOUNTPOINTS="auto"
## Path: System/File systems/btrfs
## Type: string(none,weekly,monthly)
EOF
# or
vi /etc/default/btrfsmaintenance # Change BTRFS_BALANCE_MOUNTPOINTS and BTRFS_SCRUB_MOUNTPOINTS
# or
sed -i -e 's/^BTRFS_BALANCE_MOUNTPOINTS=\"\/\"/BTRFS_BALANCE_MOUNTPOINTS=\"auto\"/g' /etc/default/btrfsmaintenance
sed -i -e 's/^BTRFS_SCRUB_MOUNTPOINTS=\"\/\"/BTRFS_SCRUB_MOUNTPOINTS=\"auto\"/g' /etc/default/btrfsmaintenance
mkdir /etc/systemd/system/btrfs-balance.service.d
cat << 'EOF' >> /etc/systemd/system/btrfs-balance.service.d/override.conf
# 2019 Jakob Meng, <[email protected]>
# Wait until btrfs balance job has finished
#
# Ref.: man systemd.service
[Service]
TimeoutStopSec=infinity
EOF
mkdir /etc/systemd/system/btrfs-scrub.service.d
cat << 'EOF' >> /etc/systemd/system/btrfs-scrub.service.d/override.conf
# 2019 Jakob Meng, <[email protected]>
# Wait until btrfs scrub job has finished
#
# Ref.: man systemd.service
[Service]
TimeoutStopSec=infinity
EOF
systemctl daemon-reload
systemctl enable btrfs-balance.timer
systemctl enable btrfs-scrub.timer
# Only Debian 10 (Buster) and earlier
systemctl restart btrfsmaintenance-refresh.service
systemctl enable btrfsmaintenance-refresh.service