This is a simple collection of systemd unit files for various tasks maintenance tasks for BTRFS file systems which are desirable to automate.
Caution: I have not been able to find good documentation about what may occur if two btrfs operations, such as balance and scrub, overlap with each other. Until I can find a clear answer on this or have sufficient experimental evidence to show that it is unsafe these unit files should be considered experimental and used with caution.
The provide units do the following,
btrfs-balance@.service- A template unit which will perform the btrfs balance operation on the btrfs volume at the path given as the systemd unit template parameter.
- Example:
systemctl start btrfs-balance@home.serviceassuming/homeis a btrfs volume. - Example:
systemctl start btrfs-balance@-.servicewhich will perform a balance on/.-is howsystemdencodes the/path in template units.
btrfs-scrub@.service- A template unit which will perform the btrfs scrub operation on the btrfs volume at the path given as the systemd unit template parameter.
- Example:
systemctl start btrfs-scrub@home.serviceassuming/homeis a btrfs volume.
btrfs-scrub@.timer- A template timer unit which will trigger the
btrfs-scrub@.serviceat a monthly interval. You can customized the timer values using the standardsystemdmethod of drop in units. - Example:
systemctl enable btrfs-scrub@home.timer, this will trigger a scrub of/homeonce a month.
- A template timer unit which will trigger the
btrfs-snapshot@.service- A template unit which will create a read-only snapshot of the btrfs subvolume specified by the
systemdunit template value. These snapshots will be saved in/var/lib/btrfs-snapshotsby default, but this value can be changed by overriding theBTRFS_SNAPSHOT_PATHenvironment variable for the unit. Each snapshot will be suffixed with ISO 8601 date time, with a resolution to the second. - Example:
systemctl start btrfs-snapshot@home.serviceassuming/homeis a btrfs subvolume.
- A template unit which will create a read-only snapshot of the btrfs subvolume specified by the
btrfs-snapshot@.timer- A template timer unit which runs the
btrfs-snapshot@.serviceunit against the btrfs subvolume at the path given by the template parameter. By default this will run daily, but this can be override with a standardsystemddrop in unit. - Example:
systemctl enable btrfs-snapshot@home.timerwill create a read-only snapshot of/homesaved to/var/lib/btrfs-snapshost, assuming it is a btrfs subvolume, every day.
- A template timer unit which runs the
You should probably use a package manager.
# ./configure
# make installThis will install the units into the standard systemd folder for package provided units, e.g. /usr/lib/systemd/system.