updated norg backup

This commit is contained in:
Paul Wilde 2024-08-23 14:47:22 +01:00
parent 5f2d5544c2
commit 808b0849e7
4 changed files with 99 additions and 17 deletions

View file

@ -23,7 +23,7 @@
<id>https://paulwilde.uk/ponderings/norg/</id>
<summary type="html">&lt;h1 id=&quot;norg&quot;&gt;Norg&lt;&#x2F;h1&gt;
&lt;p&gt;A simple, portable, wrapper for the &lt;a href=&quot;https:&#x2F;&#x2F;www.borgbackup.org&quot;&gt;borg backup utility&lt;&#x2F;a&gt; written in Nim&lt;&#x2F;p&gt;
&lt;p&gt;A simple, portable, wrapper for the &lt;a href=&quot;https:&#x2F;&#x2F;www.borgbackup.org&quot;&gt;borg backup&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;restic.net&quot;&gt;restic&lt;&#x2F;a&gt; utilities written in Nim.&lt;&#x2F;p&gt;
</summary>
</entry>

View file

@ -106,7 +106,7 @@
<div class="post-content">
<h1 id="norg">Norg</h1>
<p>A simple, portable, wrapper for the <a href="https://www.borgbackup.org">borg backup utility</a> written in Nim</p>
<p>A simple, portable, wrapper for the <a href="https://www.borgbackup.org">borg backup</a> and <a href="https://restic.net">restic</a> utilities written in Nim.</p>
</div>
<div>

View file

@ -120,7 +120,7 @@
<div class="post-content">
<h1 id="norg">Norg</h1>
<p>A simple, portable, wrapper for the <a href="https://www.borgbackup.org">borg backup utility</a> written in Nim</p>
<p>A simple, portable, wrapper for the <a href="https://www.borgbackup.org">borg backup</a> and <a href="https://restic.net">restic</a> utilities written in Nim.</p>
<span id="continue-reading"></span>
<p>Inspired by <a href="https://torsion.org/borgmatic">Borgmatic</a></p>
<h2 id="usage">Usage</h2>
@ -130,7 +130,7 @@
</span><span> </span><span style="color:#89ddff;">&quot;</span><span style="color:#c3e88d;">/home/me/Pictures</span><span style="color:#89ddff;">&quot;
</span><span style="color:#89ddff;">]
</span><span style="color:#89ddff;">[[repositories]]
</span><span style="color:#f07178;">label </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">A Repository</span><span style="color:#89ddff;">&quot;
</span><span style="color:#f07178;">label </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">MyBorgRepo</span><span style="color:#89ddff;">&quot;
</span><span style="color:#f07178;">path </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">/my/backup/location</span><span style="color:#89ddff;">&quot;
</span><span>
</span><span style="color:#89ddff;">[[repositories]]
@ -150,7 +150,8 @@
</span><span style="color:#f07178;">base_url </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">https://uptime.kuma.url/api/push/1234abcd</span><span style="color:#89ddff;">&quot;
</span><span style="color:#f07178;">states </span><span style="color:#89ddff;">= [&quot;</span><span style="color:#c3e88d;">Success</span><span style="color:#89ddff;">&quot;,&quot;</span><span style="color:#c3e88d;">Failure</span><span style="color:#89ddff;">&quot;, &quot;</span><span style="color:#c3e88d;">Running</span><span style="color:#89ddff;">&quot;]
</span></code></pre>
<p>You can then run the equivalent <code>borg</code> command to init, create, list, mount and extract your backups.</p>
<p>You can then run the equivalent <code>borg</code> or <code>restic</code> command to init, create, list, mount and extract your backups.</p>
<p><strong>Using BorgBackup</strong></p>
<pre data-lang="sh" style="background-color:#212121;color:#eeffff;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="font-style:italic;color:#4a4a4a;"># Init your repository
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml init
</span><span>
@ -161,30 +162,111 @@
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml list
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Mount an Archive
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml mount pcname-2024-08-18T15:20:17773204 /home/me/mnt
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml mount</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> pcname-2024-08-18T15:20:17773204 /home/me/mnt
</span><span style="font-style:italic;color:#4a4a4a;"># Unmount an Archive
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml umount /home/me/mnt
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml umount</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo /home/me/mnt
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Extract an Archive
</span><span style="font-style:italic;color:#4a4a4a;"># You must be in an empty folder for this to work
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml extract pcname-2024-08-18T15:20:17773204
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Or You must set the destination to an empty folder
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml extract pcname-2024-08-18T15:20:17773204</span><span style="color:#89ddff;"> --</span><span style="color:#f78c6c;">destination</span><span style="color:#82aaff;"> /tmp/my_extracted_archive
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml extract</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> pcname-2024-08-18T15:20:17773204
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Or You must set the destination to an empty folder
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml extract</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> pcname-2024-08-18T15:20:17773204</span><span style="color:#89ddff;"> --</span><span style="color:#f78c6c;">destination</span><span style="color:#82aaff;"> /tmp/my_extracted_archive
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Prune all repos
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml prune
</span><span style="font-style:italic;color:#4a4a4a;"># Or specify a particula repo
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml prune</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Delete an Archive
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml delete</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> pcname-2024-08-18T15:20:17773204
</span></code></pre>
<p><strong>Using Restic</strong> <em>New in v0.1.6</em>
Add a repository with a <code>tool = "restic"</code> option.</p>
<pre data-lang="toml" style="background-color:#212121;color:#eeffff;" class="language-toml "><code class="language-toml" data-lang="toml"><span style="color:#89ddff;">[[repositories]]
</span><span style="color:#f07178;">label </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">MyResticRepo</span><span style="color:#89ddff;">&quot;
</span><span style="color:#f07178;">path </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">/my/restic/backup/location</span><span style="color:#89ddff;">&quot;
</span><span style="color:#f07178;">tool </span><span style="color:#89ddff;">= &quot;</span><span style="color:#c3e88d;">restic</span><span style="color:#89ddff;">&quot;
</span></code></pre>
<p>Then run the appropriate commands</p>
<pre data-lang="sh" style="background-color:#212121;color:#eeffff;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="font-style:italic;color:#4a4a4a;"># Init your repository
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml init
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Backup your data
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml backup
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># List Snapshots
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml snapshots
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Mount a Repo
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml mount</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyResticRepo /home/me/mnt
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Restore an Archive (restore destination must be empty)
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml restore</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> latest</span><span style="color:#89ddff;"> --</span><span style="color:#f78c6c;">destination</span><span style="color:#82aaff;"> /my/restore/location
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Prune a repo
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml prune
</span><span>
</span><span style="font-style:italic;color:#4a4a4a;"># Forget a Snapshot
</span><span style="color:#82aaff;">norg</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">c</span><span style="color:#82aaff;"> myconfig.toml forget</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">r</span><span style="color:#82aaff;"> MyBorgRepo</span><span style="color:#89ddff;"> -</span><span style="color:#f78c6c;">a</span><span style="color:#82aaff;"> a1b2c3d4
</span></code></pre>
<h3 id="command-line-parameters">Command line parameters</h3>
<ul>
<li><code>-c</code>, <code>--config</code>: The configuration file to use</li>
<li><code>-r</code>, <code>--repository</code>: The repository to work on</li>
<li><code>-a</code>, <code>--archive</code>: The Archive to operate on (snapshots for restic)</li>
<li><code>-d</code>, <code>--destination</code>: When extracting/restoring, the destination for the extracted files</li>
</ul>
<h2 id="build-from-source">Build from Source</h2>
<p>Download and build from source</p>
<pre data-lang="sh" style="background-color:#212121;color:#eeffff;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#82aaff;">git clone https://codeberg.org/pswilde/norgbackup
</span><span style="color:#82aaff;">cd norgbackup
</span><span style="color:#82aaff;">nimble install
</span></code></pre>
<p>or just install directly with <code>nimble</code></p>
<pre data-lang="sh" style="background-color:#212121;color:#eeffff;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#82aaff;">nimble install https://codeberg.org/pswilde/norgbackup
</span></code></pre>
<h2 id="system-support">System Support</h2>
<p>Norg should work on any system that can compile <code>nim</code> code with <code>nimble</code>.
Tested on:</p>
<ul>
<li>Arch Linux</li>
<li>Debian Linux</li>
<li>AlmaLinux</li>
<li>FreeBSD</li>
</ul>
<p>But in general all Linux distributions and BSDs should work if borg and/or restic is installed.
Windows support (Restic only until Borg support in Windows is available) is planned with the only real issue being finding the restic executable. Should be an easy fix.</p>
<h2 id="naming-why-norg">Naming. Why "Norg"?</h2>
<p>Well, I don't know. I'm a Star Trek fan so obviously I wanted to keep something
in line with the <a href="https://memory-alpha.fandom.com/wiki/Borg">Borg pseudo-species</a> as the borg backup utility does.<br />
Also, sometimes I feel my code has elements of inexperience but loads of potential... which reminded me of <a href="https://memory-alpha.fandom.com/wiki/Nog">Nog</a>.<br />
in line with the <a href="https://memory-alpha.fandom.com/wiki/Borg">Borg pseudo-species</a> as the borg backup utility does.
Also, sometimes I feel my code has elements of inexperience but loads of potential... which reminded me of <a href="https://memory-alpha.fandom.com/wiki/Nog">Nog</a>.
So, simply put, <code>Norg</code> is an portmanteau of "Borg" and "Nog".</p>
<h2 id="borg-and-restic-notes">Borg and Restic Notes</h2>
<p>I love both Borg and Restic tools, they are both great and both have their pros and cons. As <a href="https://borgbase.com">BorgBase</a> has repos for both, I felt it only sensible to
provide a tool that can use both.
Providing implementation for both means you could have duplicate backups using
different tools which should provide a certain amount of protection over failures in
a particular tool.
Caution should be taken when using additional flags when you have repositories of
both types in the same configuration file. I have tried to cater for some common flags
that will be converted to the correct type for a particular tool, but this may not always be the case. If in any doubt, it is advised to use the <code>--repository</code> flag for any borg/restic specific flags so as not to cause one the other tool to fail.</p>
<p>Some different yet similar commands should be converted to the correct type. A table below shows some of these:
| Borg Command | Restic Command | Result |
| create | backup | creates a backup |
| list | snapshots | lists archives/snapshots |
| extract | restore | restores/extracts a backup |
| delete | forget | removes a archive/snapshot |
| prune | forget (with --prune flag) | removes snapshots as per <code>--keep-*</code> config |</p>
<p>You may specify either command and it will work with both except the <code>forget</code> command. This will only forget a single snapshot in restic.</p>
<h2 id="why-create-this-when-borgmatic-exists">Why create this when Borgmatic exists?</h2>
<p><code>Borgmatic</code> is absolutely fantastic, and I love it dearly. I even implemented
the <code>Uptime Kuma</code> hook that is in it. However, I got a little impatient waiting
for the version that included the Uptime Kuma hook to arrive in various distributions
package repositories so ended up building borgmatic from source on all computers.<br />
This was a lengthy process, and borgmatic isn't very portable; it requires installation of numerous python packages (and the entire rust language in FreeBSD).<br />
package repositories so ended up building borgmatic from source on all computers.
This was a lengthy process, and borgmatic isn't very portable; it requires installation of numerous python packages (and the entire rust language in FreeBSD).
I wanted to make something that had to features I needed, in a single binary I
could move around to whatever computer I needed it on.<br />
could move around to whatever computer I needed it on.
Norg was the outcome of this.</p>
<h2 id="work-in-progress">Work in Progress</h2>
<p>Norg is still very much a work in progress, so there will be bugs. Please raise

File diff suppressed because one or more lines are too long