Skip to content
Snippets Groups Projects
Commit 6e9c3ccb authored by nimrod's avatar nimrod
Browse files

Periodic scrubbing of btrfs volumes.

parent 714cf880
Branches
No related tags found
No related merge requests found
#!/bin/sh
set -eu
for mp in $(lsblk --list --noheadings --output fstype,mountpoint | \
awk '$1 == "btrfs" {print $2}' | \
sort -u)
do
status="$(btrfs scrub status "$mp" | awk '$1 == "Status:" {print $2}')"
if [ "$status" = 'running' ]
then
echo "Scrub already running on $mp, skipping." >&2
continue
fi
btrfs scrub start "$mp"
echo "Started scrub on $mp." >&2
done
[Unit]
Description=Scrub btrfs volumes
ConditionACPower=true
After=local-fs.target
[Service]
Type=oneshot
ExecStart=btrfs-scrub
[Unit]
Description=Scrub btrfs volumes
[Timer]
OnCalendar=weekly
[Install]
WantedBy=multi-user.target
...@@ -233,3 +233,24 @@ ...@@ -233,3 +233,24 @@
enabled: true enabled: true
name: update.timer name: update.timer
state: started state: started
- name: Copy the btrfs scrub script
ansible.builtin.copy:
dest: /usr/local/sbin/btrfs-scrub
mode: 0o0755
src: btrfs-scrub
- name: Copy btrfs scrub service and timer
loop:
- scrub.service
- scrub.timer
ansible.builtin.copy:
dest: /etc/systemd/system
mode: 0o0644
src: '{{ item }}'
- name: Enable the btrfs scrub timer
ansible.builtin.systemd:
enabled: true
name: scrub.timer
state: started
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment