meta data for this page
  •  

This is an old revision of the document!


BTRFS Maintenance scripts

remove dangling QGroups

To solve After deleting a subvolume, you must manually delete the associated qgroup. mentioned here: https://btrfs.wiki.kernel.org/index.php/Quota_support#Known_issues

/usr/local/bin/btrfQGroupClean.sh
#!/bin/bash
 
[[ ! -d $1 ]] && { echo Please pass mountpoint as first argument >&2 ;
exit 1 ; }
 
while read x i x g x x l x p
do
    volName[i]=$p
done < <(btrfs subvolume list $1)
 
while read g r e
do
    group=${g##*/}
    [[ -z ${volName[group]} ]] && [[ $r -eq 0 ]] && [[ $e -eq 0 ]] && echo $g $r $e && btrfs qgroup destroy $g $1
#name=${volName[group]} || name='(unknown)'
    #echo $name $g `numfmt --to=iec $r` `numfmt --to=iec $e`
done < <(btrfs qgroup show --raw $1 | tail -n+3) | column -t
crontab
@daily /usr/local/bin/btrfQGroupClean.sh

periodic scrub

From arch linux btrfs-progs

/etc/systemd/system/btrfs-scrub@.service
[Unit]
Description=Btrfs scrub on %f

[Service]
Nice=19
IOSchedulingClass=idle
ExecStart=/bin/btrfs scrub start -B %f
/etc/systemd/system/btrfs-scrub@.timer
[Unit]
Description=Monthly Btrfs scrub on %f

[Timer]
OnCalendar=monthly
AccuracySec=1d
Persistent=true

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable btrfs-scrub@-.timer
systemctl start btrfs-scrub@-.timer # to enable for /
 
systemctl enable btrfs-scrub@home.timer # to enable for /home
systemctl start btrfs-scrub@home.timer # to enable for /home