<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>backup &amp;mdash; Plain text</title>
    <link>https://plain-text.cc/tag:backup</link>
    <description>A blog about computers and living things</description>
    <pubDate>Mon, 20 Apr 2026 15:19:51 +0200</pubDate>
    <item>
      <title>usb-copy.service: A plug and copy solution</title>
      <link>https://plain-text.cc/usb-copy-service-a-plug-and-copy-solution</link>
      <description>&lt;![CDATA[#linux #backup&#xA;&#xA;I often have to transfer files from other computers and work on them in my laptop. So I walk around with an USB stick in my key chain precisely for that. Having all my precious files at hand at all times is very useful, and the following systemd-service is what makes it possible.&#xA;&#xA;It does one very simple thing: detects when my USB stick is mounted, and runs rsync to copy all files to a folder in my /home directory. This tool has seen a few iterations, and at first it required an udev rule and a script. Now, this version the most simple and elegant I could come up with.&#xA;&#xA;To define which USB device should be copied, use the partition label. It can also be found using sudo systemctl list-units -t mount. In this case my usb is called run-media-USER-SANDISK.&#xA;&#xA;Create the systemd unit file at /etc/systemd/system/usb-copy.service&#xA;&#xA;[Unit]&#xA;Description=Backup USB contents&#xA;Requires=run-media-USER-SANDISK.mount&#xA;After=run-media-USER-SANDISK.mount&#xA;&#xA;[Service]&#xA;ExecStart=/usr/bin/rsync -a --delete /run/media/USER/SANDISK /home/USER/&#xA;&#xA;[Install]&#xA;WantedBy=run-media-USER-SANDISK.mount&#xA;&#xA;Reload the systemd-daemon with sudo systemctl daemon-reload&#xA;&#xA;This unit will silently run the command when the run-media-USER-SANDISK.mount unit appears.]]&gt;</description>
      <content:encoded><![CDATA[<p><a href="https://plain-text.cc/tag:linux" class="hashtag"><span>#</span><span class="p-category">linux</span></a> <a href="https://plain-text.cc/tag:backup" class="hashtag"><span>#</span><span class="p-category">backup</span></a></p>

<p>I often have to transfer files from other computers and work on them in my laptop. So I walk around with an USB stick in my key chain precisely for that. Having all my precious files at hand at all times is very useful, and the following systemd-service is what makes it possible.</p>

<p>It does one very simple thing: detects when my USB stick is mounted, and runs <code>rsync</code> to copy all files to a folder in my <code>/home</code> directory. This tool has seen a few iterations, and at first it required an <code>udev</code> rule and a script. Now, this version the most simple and elegant I could come up with.</p>

<p>To define which USB device should be copied, use the partition label. It can also be found using <code>sudo systemctl list-units -t mount</code>. In this case my usb is called <code>run-media-USER-SANDISK</code>.</p>

<p>Create the systemd unit file at <code>/etc/systemd/system/usb-copy.service</code></p>

<pre><code>[Unit]
Description=Backup USB contents
Requires=run-media-USER-SANDISK.mount
After=run-media-USER-SANDISK.mount

[Service]
ExecStart=/usr/bin/rsync -a --delete /run/media/USER/SANDISK /home/USER/

[Install]
WantedBy=run-media-USER-SANDISK.mount
</code></pre>

<p>Reload the systemd-daemon with <code>sudo systemctl daemon-reload</code></p>

<p>This unit will silently run the command when the <code>run-media-USER-SANDISK.mount</code> unit appears.</p>
]]></content:encoded>
      <guid>https://plain-text.cc/usb-copy-service-a-plug-and-copy-solution</guid>
      <pubDate>Sun, 16 Feb 2025 17:17:12 +0100</pubDate>
    </item>
  </channel>
</rss>