Skip to content

Instantly share code, notes, and snippets.

@ricco386
Last active June 3, 2024 02:07
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
@userx14
Copy link

userx14 commented Nov 1, 2020

Hi,
when trying to launch the btrfs-scrub service manually it does not background properly and blocks the shell used to start the service. I had to removed the -B flag and set Type=forking for that to work, not sure if it has any other negative consequences though.
Greetings Benjamin

@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