Skip to content

Instantly share code, notes, and snippets.

@ricco386
Last active July 5, 2022 07:20
Show Gist options
  • Save ricco386/4dd6cae0ad4e0397a5ba7a1e4b5b1f6d to your computer and use it in GitHub Desktop.
Save ricco386/4dd6cae0ad4e0397a5ba7a1e4b5b1f6d to your computer and use it in GitHub Desktop.
Systemd timer for BTRFS Scrub. Usage: systemctl enable btrfs-scrub@pictures.timer
# /etc/conf.d/btrfs-scrub-pictures
mountpoint=/data/pictures
# /etc/systemd/system/btrfs-scrub@.service
[Unit]
Description=Scrub BTRFS filesystem (%i), check volume for errors
Documentation=man:btrfs-scrub
# After=fstrim.service
[Service]
Type=oneshot
EnvironmentFile=/etc/conf.d/btrfs-scrub-%i
ExecStart=/usr/sbin/btrfs scrub start -B $mountpoint
IOSchedulingClass=idle
CPUSchedulingPolicy=idle
# /etc/systemd/system/btrfs-scrub@.timer
[Unit]
Description=Trigger BTRFS scrub on filesystem (%i)
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=timers.target
@Silvenga
Copy link

Silvenga commented Jan 23, 2021

@Benjaminrenz the reason for this behavior is that the service uses Type=oneshot (the service will be in the activation state unil the command exits, the start command will wait for activation to complete).

Removing that directive will use the default simple type (which IMO is more correct). Removing the -B will allow the service to be started multiple times without the scrub compleng (which will cause the service to fail).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment