126 lines
5.1 KiB
HTML
126 lines
5.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>Transfer BTFS snapshots with netcat</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="transfer-btfs-snapshots-with-netcat.html">
|
|
Transfer BTFS snapshots with netcat
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #202007192257.11# -->
|
|
<div class="subtitle">July 19, 2020 —
|
|
Jesse Harris
|
|
</div>
|
|
<!-- text begin -->
|
|
|
|
<p>Netcat, the swiss army knife of TCP/IP can be used for many tasks.
|
|
Today, I'll breifly demonstrate sending btrfs snapshots between computers
|
|
with it's assistance.</p>
|
|
|
|
<hr />
|
|
|
|
<h5>The setup</h5>
|
|
|
|
<p>I use a raspberry pi computer as a small NAS. It doesn't have a high
|
|
performance requirment and just has an 8Tb spinning rust drive connected
|
|
over usb 3. Ocasionally, I want to back it up to another set of drives
|
|
across my local LAN.</p>
|
|
|
|
<p>Both the raspberry pi, and my receiving desktop computer run Gentoo and thus
|
|
installing netcat can be achieved by the following command:</p>
|
|
|
|
<pre><code> emerge net-analyzer/netcat
|
|
</code></pre>
|
|
|
|
<p>Gentoo also offers the OpenBSD variant:</p>
|
|
|
|
<pre><code> emerge net-analyzer/openbsd-netcat
|
|
</code></pre>
|
|
|
|
<p>These two versions will happily work together, but have slightly different
|
|
syntax and behaviors</p>
|
|
|
|
<h5>Version differences</h5>
|
|
|
|
<p>The main difference I have noticed between the two versions is that the
|
|
openbsd variant will automatically quit when it receives and EOF signal,
|
|
while the original version requires the -q parameter.</p>
|
|
|
|
<h5>On the receiving end</h5>
|
|
|
|
<p>I tend to setup my recieving end of the netcat tunnel first. I beleive the
|
|
sending end could be setup first but this seems more natural to my mind.
|
|
In this case I want my btrfs snapshot stored in another btrfs filesystem.
|
|
This allows easy restoration of single file.</p>
|
|
|
|
<pre><code> cd /mnt/btrfs/backups
|
|
nc -l 10004 | btrfs receive .
|
|
</code></pre>
|
|
|
|
<p>The <code>-l 10004</code> parameter specifies that netcat should listen on port 10004.
|
|
You could as easily pick any other port not in use.</p>
|
|
|
|
<p>Next, a pipe to <code>btrfs receive</code> and <code>.</code> says to store the snapshot here.</p>
|
|
|
|
<p>After you press enter on this command, netcat will be listening, but as no data
|
|
has passed through the pipe yet, the btrfs command will not have recieved
|
|
anything and will just be waiting indefinitly for data.</p>
|
|
|
|
<h5>On the sending end</h5>
|
|
|
|
<p>From the source machine, if this is the first snapshot ever send:</p>
|
|
|
|
<pre><code> cd /mnt/btrfs/snapshots/
|
|
btrfs send root-2020-07-19-01:00:01 | nc -q 1 192.168.11.203 10004
|
|
</code></pre>
|
|
|
|
<p>If it is not the first:</p>
|
|
|
|
<pre><code> cd /mnt/btrfs/snapshots/
|
|
btrfs send -p root-2020-07-19-01:00:01 \
|
|
root-2020-07-20-01:00:01 | nc -q 1 192.168.11.203 10004
|
|
</code></pre>
|
|
|
|
<p>The <code>-p</code> can tell btrfs that the following subvolume is a parent of the
|
|
snapshot we are sending and therefore only send the difference.
|
|
The <code>-q 1</code> tells that non-openbsd varient of netcat to quit 1 second after
|
|
receiving and EOF message from the upstream program.</p>
|
|
|
|
<p>After pressing enter on this command, btrfs send will begin passing data
|
|
through the pipe to netcat which will connect to the destination computer on the
|
|
port specified. You should begin to see informational output from btrfs at this
|
|
stage.</p>
|
|
|
|
<p>If you hadn't thought to specify <code>-q</code> parameter, not to worry. You can monitor
|
|
that data is coming through the pipe using a tool like <code>nettop</code> or <code>iotop</code>.
|
|
After data transfer has ceased, simply hit Ctrl+C to close the pipe on both ends
|
|
at once.</p>
|
|
|
|
<h3>Summing up</h3>
|
|
|
|
<p>And that is about all there is to sending btrfs snapshots with netcat.
|
|
You can transfer your snapshots as fast as your disks and LAN will allow.
|
|
Depending on your CPU you may also get better performance if you pipe through
|
|
gzip and gunzip.</p>
|
|
|
|
<p>Tags: <a href='tag_btrfs.html'>btrfs</a>, <a href='tag_netcat.html'>netcat</a>, <a href='tag_linux.html'>linux</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>
|