meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:fs:btrfs:maintenance [2020/06/02 19:34]
niziak created
linux:fs:btrfs:maintenance [2021/05/13 19:43] (current)
niziak
Line 1: Line 1:
 ====== BTRFS Maintenance scripts ====== ====== BTRFS Maintenance scripts ======
  
 +===== Defragment =====
 +From [[https://​helmundwalter.de/​blog/​btrfs-finding-and-fixing-highly-fragmented-files/​|BTRFS fragmentation can hurt the performance of your System]]
  
 +Find the most fragmented files on your System:
 +
 +<code bash>
 +find / -xdev -type f| xargs filefrag 2>/​dev/​null | sed '​s/​^\(.*\):​ \([0-9]\+\) extent.*/\2 \1/' | awk -F ' ' '$1 > 500' | sort -n -r | head -30
 +</​code>​
 +
 +You should review this list. If there is something with 10000+ extends, it is a candidate to be flagged as nodatacow. In my case, I have discovered that the fail2ban sqlite database was using 170k extends which is a lot!
 +
 +<code bash>
 +find / -xdev -type f| xargs filefrag 2>/​dev/​null | sed '​s/​^\(.*\):​ \([0-9]\+\) extent.*/\2 \1/' | awk -F ' ' '$1 > 500' | cut -f ' ' -f2 2>/​dev/​null | xargs -r btrfs -v fi defrag -f -czstd
 +</​code>​
 +
 +
 +===== Headline =====
 +
 +<file bash /​usr/​local/​bin/​btrfsQuota.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
 +    [[ -z $name ]] && echo -e "​subvol\tqgroup\ttotal\tunshared"​
 +    group=${g##​*/​}
 +    [[ ! -z ${volName[group]} ]] && 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
 +</​file>​
  
  
Line 8: Line 43:
 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]] 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]]
  
-<file bash /​usr/​local/​bin/​btrfQGroupClean.sh>+<file bash /​usr/​local/​bin/​btrfsQGroupClean.sh>
 #!/bin/bash #!/bin/bash
  
Line 29: Line 64:
  
 <file cron crontab> <file cron crontab>
-@daily /​usr/​local/​bin/​btrfQGroupClean.sh+@daily /​usr/​local/​bin/​btrfsQGroupClean.sh
 </​file>​ </​file>​