Skip to content
Snippets Groups Projects
Commit 8c68e347 authored by nimrod's avatar nimrod
Browse files

Per btrfs device scrub job.

Instead of a single Systemd service and timer and a script to scrub all
of the btrfs devices. Easier to find faults that way.
parent 7da2cea9
No related branches found
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
# In case there are no btrfs volumes, the for loop will execute once with an
# empty string for mp. Validate that indeed we're passed a mountpoint.
[ -d "$mp" ] || continue
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" >&2
done
...@@ -235,23 +235,34 @@ ...@@ -235,23 +235,34 @@
name: update.timer name: update.timer
state: started state: started
- name: Copy the btrfs scrub script - name: Create btrfs scrub services
ansible.builtin.copy: # yamllint disable rule:line-length
dest: /usr/local/sbin/btrfs-scrub loop: &btrfs_devices |-
mode: 0o0755 {{ ansible_mounts|selectattr("fstype", "equalto", "btrfs")|map(attribute="device")|unique }}
src: btrfs-scrub # yamllint enable rule:line-length
ansible.builtin.template:
dest: /etc/systemd/system/scrub{{ name }}.service
mode: 0o0644
src: scrub.service.j2
vars: &btrfs_vars
device: '{{ item }}'
name: '{{ item|replace("/", "_") }}'
tags: [scrub]
- name: Copy btrfs scrub service and timer - name: Create btrfs scrub timers
loop: loop: *btrfs_devices
- scrub.service ansible.builtin.template:
- scrub.timer dest: /etc/systemd/system/scrub{{ name }}.timer
ansible.builtin.copy:
dest: /etc/systemd/system
mode: 0o0644 mode: 0o0644
src: '{{ item }}' src: scrub.timer.j2
vars: *btrfs_vars
tags: [scrub]
- name: Enable the btrfs scrub timer - name: Enable the btrfs scrub timers
loop: *btrfs_devices
ansible.builtin.systemd: ansible.builtin.systemd:
enabled: true enabled: true
name: scrub.timer name: scrub{{ name }}.timer
state: started state: started
vars: *btrfs_vars
tags: [scrub]
# vim: filetype=systemd
[Unit] [Unit]
Description=Scrub btrfs volumes Description=Scrub btrfs device {{ device }}
ConditionACPower=true ConditionACPower=true
After=local-fs.target After=local-fs.target
[Service] [Service]
Type=oneshot Type=exec
ExecStart=btrfs-scrub ExecStart=btrfs scrub start -B {{ device }}
# vim: filetype=systemd
[Unit] [Unit]
Description=Scrub btrfs volumes Description=Scrub btrfs device {{ device }}
[Timer] [Timer]
OnCalendar=weekly OnCalendar=weekly
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment