Having discovered that systemd can even be used as a replacement for Cron, I'm migrating most of my maintenance scripts to systemd Timers.
Here's how to have your BTRFS volumes scrubbed using parameterized units:
Service Unit
#/etc/systemd/system/btrfs-scrub@.service
[Unit]
Description=Scrub BTRFS filesystem (%i)
[Service]
Type=simple
EnvironmentFile=/etc/conf.d/btrfs-scrub-%i
ExecStart=/usr/bin/btrfs scrub start -B $mountpoint
Timer Unit
#/etc/systemd/system/btrfs-scrub@.timer
[Unit]
Description=Trigger BTRFS scrub on filesystem (%i)
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=timers.target
Usage
In order to have a volume (e.g. your home partition) scrubbed you simply activate the timer...
$ systemctl enable btrfs-scrub@home.timer
... and specify the mount point in the corresponding configuration file,
in this case /etc/conf.d/btrfs-scrub-home
:
mountpoint=/home
The configuration file seems a bit superfluous here, but AFAIK there's
no way to supply filesystem paths via service@
-suffix.
Note that these units do not include any form of notification in case of a scrubbing fail! I personally don't need this as my logs are monitored using journalcheck.
Update 2015-07-12: Changed unit type to 'simple' to make it compatible with long-running machines.