Skip to content

Instantly share code, notes, and snippets.

@ricco386
Last active July 5, 2022 07:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@ricco386
Copy link
Author

Reload sytemd process systemctl daemon-reload so we have new service and timer.
Enable timer systemctl enable btrfs-scrub@pictures.timer and systemctl enable btrfs-scrub@pictures.timer.
List all timers systemctl list-timers --all.

@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