80 lines
3.1 KiB
HTML
80 lines
3.1 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<link rel="stylesheet" href="main.css" type="text/css" />
|
|
<link rel="stylesheet" href="blog.css" type="text/css" />
|
|
<link rel="alternate" type="application/rss+xml" title="Subscribe to this page..." href="feed.rss" />
|
|
<title>Defragging files in btrfs - Oneliner</title>
|
|
</head><body>
|
|
<div id="divbodyholder">
|
|
<div class="headerholder"><div class="header">
|
|
<div id="title">
|
|
<h1 class="nomargin"><a class="ablack" href="http://zigford.org/index.html">zigford.org</a></h1>
|
|
<div id="description"><a href="about.html">About</a><a href="links.html"> | Links</a><a href="scripts.html"> | Scripts</a><br>Sharing linux/windows scripts and tips</br></div>
|
|
</div></div></div>
|
|
<div id="divbody"><div class="content">
|
|
<!-- entry begin -->
|
|
<h3><a class="ablack" href="defragging-files-in-btrfs---oneliner.html">
|
|
Defragging files in btrfs - Oneliner
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #202004101301.14# -->
|
|
<div class="subtitle">April 10, 2020 —
|
|
Jesse Harris
|
|
</div>
|
|
<!-- text begin -->
|
|
<p>Sometimes, small databasey files get a bit fragmented over time on a COW
|
|
filesystem. This touch of shell is a goodone to clean them up every now and
|
|
then.</p>
|
|
<hr />
|
|
<pre><code> find -size +1024k -size 50000k -type f -exec filefrag {} \; |
|
|
awk '{a=NF-2; if ($a>50) {sub(/:.*/,"");print$0}}'|
|
|
xargs -I{} btrfs fi defrag "{}"
|
|
</code></pre>
|
|
<h1 id="pulling-it-apart">Pulling it apart</h1>
|
|
<h2 id="find">find</h2>
|
|
<pre><code> -size +1024k -size -50000k
|
|
# this tells find to only show files between 1mb and 50mb
|
|
|
|
-type f
|
|
# only find files
|
|
|
|
-exec filefrag {} ;\
|
|
# run filefrag on each file, which shows a count of fragments on each
|
|
# file
|
|
</code></pre>
|
|
<h2 id="awk">awk</h2>
|
|
<pre><code> a=NF-2
|
|
# files may have spaces in the name and filefrag lists the filename
|
|
# first, instead lets look the second from the last field number (NF =
|
|
Number of fields in a given line)
|
|
|
|
if ($a>50)
|
|
# only work on files with frags over 50
|
|
|
|
sub(/:.*/,"")
|
|
# from $0 (the whole line), substitue anything past : with nothing,
|
|
# making $0 reference the filename, spaces and all
|
|
</code></pre>
|
|
<h2 id="xargs">xargs</h2>
|
|
<pre><code> -I{}
|
|
# in the following command substitue {} with the incoming stdin (ie the
|
|
# filename
|
|
|
|
btrfs fi defrag "{}"
|
|
# defrag the file.
|
|
</code></pre>
|
|
<p>Tags: <a href='tag_btrfs.html'>btrfs</a>, <a href='tag_bash.html'>bash</a>, <a href='tag_bash-tips.html'>bash-tips</a>, <a href='tag_awk.html'>awk</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- text end -->
|
|
<!-- entry end -->
|
|
</div>
|
|
<div id="footer">© <a href="http://twitter.com/zigford_org">Jesse Harris</a> — <a href="mailto:jesse@zigford.org">jesse@zigford.org</a><br/>
|
|
Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>
|
|
</div></div>
|
|
</body></html>
|