First version (not tested)
This commit is contained in:
parent
ebe620b702
commit
864fb09762
3 changed files with 49 additions and 0 deletions
10
etc/systemd/system/btrfs-maintenance.service
Normal file
10
etc/systemd/system/btrfs-maintenance.service
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Run BTRFS maintenance (scrubs and rebalance)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/bin/btrfs-maintenance
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
9
etc/systemd/system/btrfs-maintenance.timer
Normal file
9
etc/systemd/system/btrfs-maintenance.timer
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Run BTRFS maintenance stuff (scrub and rebalance) monthly
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-01 02:00:00
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
30
usr/local/bin/btrfs-maintenance
Executable file
30
usr/local/bin/btrfs-maintenance
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Find all BTRFS formatted partitions
|
||||||
|
PARTITIONS=()
|
||||||
|
for i in $(lsblk -nrpo "name" -e 1,7,11); do
|
||||||
|
if [[ "$(lsblk -no FSTYPE "$i")" == "btrfs" ]]; then
|
||||||
|
PARTITIONS+=("$i")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Reallocate blocks that are less than 95% used
|
||||||
|
for i in ${PARTITIONS[*]}; do
|
||||||
|
echo "Balance: $i"
|
||||||
|
btrfs balance start -dusage=95 "$i" &
|
||||||
|
done
|
||||||
|
|
||||||
|
# Wait for balance operations to finish
|
||||||
|
wait
|
||||||
|
|
||||||
|
# Scrub all partitions
|
||||||
|
for i in ${PARTITIONS[*]}; do
|
||||||
|
echo "Scrub: $i"
|
||||||
|
btrfs scrub start -B "$i" &
|
||||||
|
done
|
||||||
|
|
||||||
|
# Wait for scrub operations to finish
|
||||||
|
wait
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in a new issue