Skip to content

Build your personal knowledge base with Trilium Notes

update docs

Adorian Dorand9c0ca233243
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Database.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Database.html
index 8dab5f243b..6aa6931d9b 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Database.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Database.html
@@ -13,7 +13,27 @@
work directly on the database file.</p>
<p>See&nbsp;<a href="#root/_help_oyIAJ9PvvwHX">Manually altering the database</a>&nbsp;for
more information.</p>
-<h2>How to Reset the Database</h2>
+<h2 style="margin-left:0px;">How to Reset the Database</h2>
+<p style="margin-left:0px;">If you want to start again and:</p>
+<ul style="list-style-type:disc;margin-left:0px;">
+ <li style="margin-left:0px;">Create and switch to a new blank knowledge base</li>
+ <li style="margin-left:0px;">Use a different knowledge base synced from a server or desktop application</li>
+ <li
+ style="margin-left:0px;">Restore a backup</li>
+</ul>
+<p style="margin-left:0px;">You can navigate to <strong>Settings → Database</strong> and click the <strong>Start over</strong> button.
+ You'll be prompted to restart the application, with the option to back
+ up your current database before proceeding.</p>
+<aside class="admonition important">
+ <p style="margin-left:0px;">For the web client, Trilium cannot restart automatically. You'll need
+ to manually restart the server/container and then reload the web application.</p>
+</aside>
+<p style="margin-left:0px;">After restarting, the setup screen will appear. You can choose to back
+ up your existing database, then proceed with the setup menu as if it's
+ a new installation. The existing database will only be overwritten after
+ selecting to create a new database, sync with a server, or restore from
+ a backup.</p>
+<h3>The Legacy Method</h3>
<p>If you are experimenting with Trilium and want to return it to its original
state, you can do that by deleting the current database. When you restart
the application, it will generate a new database containing the original
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
index d00005ace5..2e66b873e0 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Read-Only Notes.html
@@ -17,7 +17,7 @@
<h2>Changing a note's read-only behavior</h2>
<p>A note's read-only behavior can be changed via:</p>
<ul>
- <li>On the New layout,&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;→ <em>Editable</em> on
+ <li>On the New layout,&nbsp;<a class="reference-link" href="#root/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;→ <em>Editable</em> on
the new layout</li>
<li>For the old layout via the&nbsp;<a class="reference-link" href="#root/_help_BlN9DFI679QC">Ribbon</a>,
by going to the <em>Basic Properties</em> tab and looking for the <em>Editable</em> selection.</li>
@@ -50,7 +50,7 @@
by:</p>
<ul>
<li>Pressing the <em>Read-only</em> badge on the&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_IjZS7iK5EXtb">New Layout</a>.</li>
+ href="#root/_help_IjZS7iK5EXtb">New Layout</a>.</li>
<li>Or pressing the
<img src="Read-Only Notes_image.png">button in the&nbsp;<a class="reference-link" href="#root/_help_XpOYSgsLkTJy">Floating buttons</a>&nbsp;area.</li>
</ul>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html
index 181742de48..4915a10995 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/New Layout.html
@@ -48,9 +48,8 @@ class="image">
the <em>Inline title</em>. Apart from changing the note type, it's also
possible to apply a <a href="#root/_help_KC1HB96bqqHX">template</a>.</p>
<p>The switcher will disappear as soon as a text is entered.</p>
- <p>
- <img src="6_New Layout_image.png" width="735" height="143">
- </p>
+ <img src="6_New Layout_image.png"
+ width="735" height="143">
<h3>Note badges</h3>
<p>Note badges appear near the fixed note title and indicate important information
about the note such as whether it is read-only. Some of the badges are
@@ -84,7 +83,7 @@ class="image">
</figure>
<p>The following sections have been made collapsible:</p>
<ul>
- <li class="ck-list-marker-italic"><em>Promoted Attributes</em>
+ <li><em>Promoted Attributes</em>
<ul>
<li>For full-height notes such as&nbsp;<a class="reference-link" href="#root/_help_grjYqerjn243">Canvas</a>,
the promoted attributes are collapsed by default to make room.</li>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
index dfffa198e9..bf1fe472fe 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
@@ -50,8 +50,10 @@
<h2>Adding a marker using the map</h2>
<h3>Adding a new note using the plus button</h3>
<ol>
- <li>To create a marker, first navigate to the desired point on the map. Then
- press the <em>Add marker</em> button at the center-bottom of the map.</li>
+ <li>
+ <p>To create a marker, first navigate to the desired point on the map. Then
+ press the <em>Add marker</em> button at the center-bottom of the map.</p>
+ </li>
<li>
<p>Once pressed, the map will enter in the insert mode, as illustrated by
the notification. Additionally, a preview of the marker will be shown at
@@ -59,8 +61,10 @@
<p>Simply click the point on the map where to place the marker. To cancel,
press either the &nbsp;Escape key or press again the <em>Add marker</em> button.</p>
</li>
- <li>Once clicked, the marker will show up on the map and a popup will show
- to the right with the title already selected to be changed.</li>
+ <li>
+ <p>Once clicked, the marker will show up on the map and a popup will show
+ to the right with the title already selected to be changed.</p>
+ </li>
</ol>
<h3>Adding a new note using the contextual menu</h3>
<ol>
@@ -266,17 +270,16 @@ class="admonition note">
builtin markers, or custom markers that are part of the track), only that
marker is brought into view, as opposed to the entire route.</p>
<h2>Read-only mode</h2>
- <p>When a map is <a href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/BFs8mudNFgCS/_help_CoFPLs3dRlXc">read-only</a> all
- editing features will be disabled such as:</p>
+ <p>When a map is <a href="#root/_help_CoFPLs3dRlXc">read-only</a> all editing features
+ will be disabled such as:</p>
<ul>
<li>The add button at the bottom of the map.</li>
<li>Repositioning markers.</li>
<li>Editing from the contextual menu (removing locations or adding new items).</li>
</ul>
- <p>To set a map as read-only, go to&nbsp;<a class="reference-link" href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;→ <em>Editable</em> → <em>Read-only</em> (on
+ <p>To set a map as read-only, go to&nbsp;<a class="reference-link" href="#root/_help_8YBEPzcpUgxw">Note buttons</a>&nbsp;→ <em>Editable</em> → <em>Read-only</em> (on
the new layout, or in Basic Properties on the&nbsp;<a class="reference-link"
- href="#root/pOsGYCXsbNQG/gh7bpGYxajRS/Vc8PjrjAGuOp/_help_BlN9DFI679QC">Ribbon</a>&nbsp;for
- the old layout).</p>
+ href="#root/_help_BlN9DFI679QC">Ribbon</a>&nbsp;for the old layout).</p>
<h2>Configuration</h2>
<h3>Map Style</h3>
<p>The styling of the map can be adjusted in the&nbsp;<a class="reference-link"
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Backup.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Backup.html
index c8c57deced..9caa72b0e9 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Backup.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Backup.html
@@ -18,46 +18,172 @@
<p>Note that&nbsp;<a class="reference-link" href="#root/_help_cbkrhQjrkKrh">Synchronization</a>&nbsp;provides
also some backup capabilities by its nature of distributing the data to
other computers.</p>
-<h2>Downloading backup</h2>
-<p>You can download an existing backup by going to Settings &gt; Backup &gt;
- Existing backups &gt; Download</p>
-<h2>Restoring backup</h2>
-<p>Let's assume you want to restore the weekly backup, here's how to do it:</p>
+<h2>Creating a backup</h2>
+<h3>On the desktop application and web client:</h3>
+<ol>
+ <li>Go to <strong>Settings → Backup</strong> and press the <strong>Backup Now</strong> button.</li>
+ <li>The backup creation process may take a few moments, especially for larger
+ databases. A notification will inform you when the backup is complete.</li>
+ <li>The backup will be saved as <strong>backup-now</strong> in the <strong>Existing Backups</strong> list,
+ where you can download it.</li>
+</ol>
+<h3>On the standalone client</h3>
+<ol style="list-style-type:decimal;margin-left:0px;">
+ <li style="margin-left:0px;"><strong>Go to Settings → Backup</strong> and press the "<strong>Download backup</strong>"
+ button.</li>
+ <li style="margin-left:0px;">You will be prompted to <strong>restart the app</strong>. Confirm, and
+ the app will restart automatically.</li>
+ <li style="margin-left:0px;">Set a <strong>backup name</strong> or <strong>password</strong> (both optional),
+ then press "<strong>Continue</strong>".</li>
+ <li style="margin-left:0px;">Press the "<strong>Generate and download"</strong> button and wait for
+ the download to complete.</li>
+ <li style="margin-left:0px;">Once you confirm the download is saved on your device, press <strong>"Finish"</strong> to
+ complete</li>
+</ol>
+<h2>Downloading a backup</h2>
<ul>
- <li>find <a href="#root/_help_tAassRL4RSQL">data directory</a> Trilium uses - easy
- way is to open "About Trilium Notes" from "Menu" in upper left corner and
- looking at "data directory"
- <ul>
- <li>I'll refer to <code spellcheck="false">~/trilium-data</code> as data directory
- from now on</li>
- </ul>
+ <li><strong>Desktop and web client</strong>: to download an existing backup,
+ navigate to <strong>Settings → Backup → Existing backups</strong> and select <strong>Download</strong>.</li>
+ <li><strong>Standalone client</strong>: automatic backups are not supported
+ in this version. You can manually create and download a backup by going
+ to <strong>Settings → Backup → Download backup.</strong>
</li>
- <li>find <code spellcheck="false">~/trilium-data/backup/backup-weekly.db</code> -
- this is the&nbsp;<a class="reference-link" href="#root/_help_wX4HbRucYSDD">Database</a>&nbsp;backup</li>
- <li>at this point stop/kill Trilium</li>
- <li>delete <code spellcheck="false">~/trilium-data/document.db</code>,
- <code
- spellcheck="false">~/trilium-data/document.db-wal</code>and <code spellcheck="false">~/trilium-data/document.db-shm</code> (latter
- two files are auto generated)</li>
- <li>copy and rename this <code spellcheck="false">~/trilium-data/backup/backup-weekly.db</code> to
- <code
- spellcheck="false">~/trilium-data/document.db</code>
+</ul>
+<h2>Restoring a backup</h2>
+<ul style="list-style-type:disc;margin-left:0px;">
+ <li style="margin-left:0px;">
+ <p style="margin-left:0px !important;"><strong>For a new Trilium instance</strong>: When setting up a new Trilium
+ instance, use the "Restore from backup" option in the setup menu to guide
+ you through restoring your existing backup.</p>
</li>
- <li>make sure that the file is writable, e.g. with <code spellcheck="false">chmod 600 document.db</code>
+ <li style="margin-left:0px;">
+ <p style="margin-left:0px !important;"><strong>For an existing Trilium instance</strong>: To restore a backup
+ and replace your current database, go to <strong>Settings → Backup</strong> and
+ click <strong>Restore a backup</strong>. You will be prompted to restart
+ the app for the restoration process to begin. After restarting, you can
+ choose to back up the existing database before overwriting it. Note: For
+ the web client, use the Start Over feature (<strong>Settings → Database → Start over</strong>)
+ to switch to the setup screen and restore a backup.</p>
</li>
- <li>start Trilium again</li>
</ul>
-<p>If you have configured sync then you need to do it across all members
- of the sync cluster, otherwise older version (restored backup) of the document
- will be detected and synced to the newer version.</p>
-<h2>Disabling backup</h2>
-<p>Although this is not recommended, it is possible to disable backup in
- <code
- spellcheck="false">config.ini</code>in the <a href="#root/_help_tAassRL4RSQL">data directory</a>:</p><pre><code class="language-text-x-trilium-auto">[General]
+<p style="margin-left:!important;">Next, select the backup file (.db or .tnbackup) from your device. The
+ web client is optimized for handling large backups and is resilient to
+ unstable network conditions, similar to the desktop application.</p>
+<p
+style="margin-left:0px !important;">If your database is encrypted, you will be prompted to enter the password
+ used for encrypting the backup file. Without the correct password, decryption
+ and restoration cannot proceed.</p>
+ <p style="margin-left:0px;">Restoring a backup may take some time, depending on its size. Once it
+ completes, Trilium will open the freshly restored database.</p>
+ <h3>The alternative way for restoring a backup&nbsp;</h3>
+ <p>Let's assume you want to restore the weekly backup (only in .db format,
+ .tnbackup files are not supported by this method), here's how to do it:</p>
+ <ul>
+ <li>find <a href="#root/_help_tAassRL4RSQL">data directory</a> Trilium uses - easy
+ way is to open "About Trilium Notes" from "Menu" in upper left corner and
+ looking at "data directory"
+ <ul>
+ <li>I'll refer to <code spellcheck="false">~/trilium-data</code> as data directory
+ from now on</li>
+ </ul>
+ </li>
+ <li>find <code spellcheck="false">~/trilium-data/backup/backup-weekly.db</code> -
+ this is the&nbsp;<a class="reference-link" href="#root/_help_wX4HbRucYSDD">Database</a>&nbsp;backup.</li>
+ <li>at this point stop/kill Trilium</li>
+ <li>delete <code spellcheck="false">~/trilium-data/document.db</code>,
+ <code
+ spellcheck="false">~/trilium-data/document.db-wal</code>and <code spellcheck="false">~/trilium-data/document.db-shm</code> (latter
+ two files are auto generated)</li>
+ <li>copy and rename this <code spellcheck="false">~/trilium-data/backup/backup-weekly.db</code> to
+ <code
+ spellcheck="false">~/trilium-data/document.db</code>
+ </li>
+ <li>make sure that the file is writable, e.g. with <code spellcheck="false">chmod 600 document.db</code>
+ </li>
+ <li>start Trilium again</li>
+ </ul>
+ <aside class="admonition warning">
+ <p>If you have configured sync then you need to do it across all members
+ of the sync cluster, otherwise older version (restored backup) of the document
+ will be detected and synced to the newer version.</p>
+ </aside>
+ <h2>Changing the backup location in Trilium (desktop only)</h2>
+ <p>Starting with version 0.105, the Trilium desktop client allows users to
+ change the directory where backups are stored. Follow these steps to specify
+ a custom backup directory:</p>
+ <ol>
+ <li>Navigate to <strong>Settings</strong> → <strong>Backup Location</strong>.</li>
+ <li>Click the <strong>Select Location</strong> button.</li>
+ <li>Choose any writable directory on your file system. This could include
+ network shares, depending on your operating system.</li>
+ </ol>
+ <p>Once you set a custom directory, all manual and automatic backups will
+ be saved there. If the selected directory becomes unavailable, backups
+ may fail or revert to the default location.</p>
+ <aside class="admonition tip">
+ <p>For better privacy when using unsafe backup locations, you can enable
+ backup encryption, which makes the backup file unreadable without the correct
+ password.</p>
+ </aside>
+ <h2>Backup encryption</h2>
+ <p>Trilium can secure the entire content of the database backup, ensuring
+ it remains unreadable unless the correct password is provided. This is
+ particularly useful for storing backups in unsecured locations, like network
+ shares, unencrypted external drives, or cloud services.&nbsp;</p>
+ <p>Encrypted database backups use the Trilium Backup Container (.tnbackup)
+ format, which relies on AES-256-GCM. This authenticated encryption mode
+ scrambles the data and generates a tag confirming it hasn't been altered.
+ The password itself isn't directly used as the key; it's processed through
+ scrypt, a key derivation function designed to be slow and memory-intensive,
+ making brute-force password guessing difficult even with powerful hardware.
+ Each backup also receives a random 16-byte salt, ensuring that the same
+ password never produces the same encryption key twice. Additionally, critical
+ metadata such as chunk order, length, and header flags are cryptographically
+ bound into the encryption (via "additional authenticated data"), preventing
+ undetected tampering like reorder, truncate, or splice operations.</p>
+ <h3>Enabling backup encryption</h3>
+ <p>To enable encryption for automatic backups in the Desktop application:</p>
+ <ol>
+ <li>Go to <strong>Settings → Backup → Backup Options</strong>.</li>
+ <li>Click on <strong>Turn on Encryption</strong> and set a password.</li>
+ </ol>
+ <p>Once encryption is enabled, all newly created backups (both automatic
+ and manual) will be encrypted with the specified password. Backups created
+ prior to enabling encryption will remain unsecured.</p>
+ <p>You can change the password anytime using the <strong>Change Password</strong> button.
+ The new password will apply to backups created after the change.</p>
+ <p>To disable encryption, uncheck <strong>Settings → Backup → Enable Encryption</strong>.</p>
+ <aside
+ class="admonition note">
+ <p>On some systems, a keyring may not be available for Trilium to securely
+ store the encryption password. In such cases, the encryption option is
+ disabled.</p>
+ </aside>
+ <h2>Backup compression</h2>
+ <p>Database backups can be optionally compressed to minimize storage footprint.
+ This method is effective primarily when the database consists largely of
+ text content. However, media files (images, videos, audio), along with
+ PDF, ODF, and DOCX files, are already compressed in their original formats
+ and won't benefit from further compression.</p>
+ <p>Compressed backups are stored using the Trilium Backup Container (.tnbackup),
+ employing RFC 1952 GZIP compression.</p>
+ <aside class="admonition warning">
+ <p><strong>Note:</strong> Compression increases the time required for backup
+ creation and restoration. It may also lead to higher CPU usage during automatic
+ backups, potentially draining the battery faster on battery-powered devices.
+ Enable this option only if necessary.</p>
+ </aside>
+ <h3>Enabling Backup Compression (Desktop Only)</h3>
+ <p>To enable compression for new automatic and manual backups, navigate to <strong>Settings → Backup → Backup Options</strong> and
+ toggle <strong>Enable Compression</strong> to on.</p>
+ <h2>Disabling backup</h2>
+ <p>Although this is not recommended, it is possible to disable backup in
+ <code
+ spellcheck="false">config.ini</code>in the <a href="#root/_help_tAassRL4RSQL">data directory</a>:</p><pre><code class="language-text-x-trilium-auto">[General]
... some other configs
# set to true to disable backups (e.g. because of limited space on server)
noBackup=true</code></pre>
-<p>You can also review the <a href="#root/_help_Gzjqa934BdH4">configuration</a> file
- to provide all <code spellcheck="false">config.ini</code> values as environment
- variables instead.</p>
-<p>See <a href="https://github.com/TriliumNext/Trilium/blob/master/config-sample.ini">sample config</a>.</p>
\ No newline at end of file
+ <p>You can also review the <a href="#root/_help_Gzjqa934BdH4">configuration</a> file
+ to provide all <code spellcheck="false">config.ini</code> values as environment
+ variables instead.</p>
+ <p>See <a href="https://github.com/TriliumNext/Trilium/blob/master/config-sample.ini">sample config</a>.</p>
\ No newline at end of file
diff --git a/docs/Developer Guide/!!!meta.json b/docs/Developer Guide/!!!meta.json
index 3ad6328f32..36e85974cb 100644
--- a/docs/Developer Guide/!!!meta.json
+++ b/docs/Developer Guide/!!!meta.json
@@ -3250,6 +3250,33 @@
"format": "markdown",
"dataFileName": "Exported content with extended task states.md",
"attachments": []
+ },
+ {
+ "isClone": false,
+ "noteId": "Gntibtjmzi7e",
+ "notePath": [
+ "jdjRLhLV3TtI",
+ "HMrVxa1lJBKv",
+ "Gntibtjmzi7e"
+ ],
+ "title": "Trilium Backup Container (.tnbackup) file format",
+ "notePosition": 20,
+ "prefix": null,
+ "isExpanded": false,
+ "type": "text",
+ "mime": "text/html",
+ "attributes": [
+ {
+ "type": "label",
+ "name": "iconClass",
+ "value": "bx bx-history",
+ "isInheritable": false,
+ "position": 20
+ }
+ ],
+ "format": "markdown",
+ "dataFileName": "Trilium Backup Container (.tnbackup) file format.md",
+ "attachments": []
}
]
}
diff --git a/docs/Developer Guide/Developer Guide.md b/docs/Developer Guide/Developer Guide.md
index 8f5721b305..cde67671b1 100644
--- a/docs/Developer Guide/Developer Guide.md
+++ b/docs/Developer Guide/Developer Guide.md
@@ -6,7 +6,7 @@ For the user-facing documentation, including how to write scripts and the variou
### Quick links
* <a class="reference-link" href="Developer%20Guide/Environment%20Setup.md">Environment Setup</a>
-* <a class="reference-link" href="Developer%20Guide/Project%20Structure.md">Project Structure</a>
+* <a class="reference-link" href="Developer%20Guide/Project%20Structure.md">[missing note]</a>
### External links
diff --git a/docs/Developer Guide/Developer Guide/Interoperability/Trilium Backup Container (.tnbackup) file format.md b/docs/Developer Guide/Developer Guide/Interoperability/Trilium Backup Container (.tnbackup) file format.md
new file mode 100644
index 0000000000..009e16783f
--- /dev/null
+++ b/docs/Developer Guide/Developer Guide/Interoperability/Trilium Backup Container (.tnbackup) file format.md
@@ -0,0 +1,366 @@
+# Trilium Backup Container (.tnbackup) file format
+A container wraps exactly one SQLite database file, with optional gzip compression and optional AES-256-GCM authenticated encryption. Containers are named `.tnbackup`.
+
+**Every container is written in a single forward pass.** Nothing in one is patched in afterwards, so a destination that cannot be written back to, a download already on its way to the user, holds the format as readily as a file does. That is what puts the payload digest at the end rather than in the header, and it is why even the plainest container, neither compressed nor encrypted, has a hash standing behind its contents.
+
+Whether a backup is a container at all is policy, not format: a writer may skip it and copy a plain `.db` when neither compression nor encryption is asked for.
+
+The **payload** is everything after the header: the wrapped database, in whichever of the four forms the flags select. All integers are little-endian unless stated otherwise. All offsets are absolute byte offsets from the start of the file.
+
+Normative references: gzip is RFC 1952, AES-256-GCM is NIST SP 800-38D, scrypt is RFC 7914, and the SQLite file header is section 1.3 of the SQLite file format specification.
+
+### Header layout
+
+Cells are bytes, 16 per row. The diagram shows an encrypted container. In an unencrypted one the fields from `KDF` through `Verifier tag` are absent, so the header is 40 bytes and the payload starts there.
+
+```mermaid
+---
+config:
+ packet:
+ bitsPerRow: 16
+---
+packet-beta
+0-19: "Magic: Trilium Notes Backup"
+20: "Ver"
+21-28: "Timestamp"
+29: "Flags"
+30-31: "Header length"
+32-39: "Plaintext size"
+40: "KDF"
+41-43: "KDF params"
+44-59: "Salt"
+60-67: "Nonce prefix"
+68-83: "Verifier tag"
+```
+
+The **verifier tag is always the last field of the header**. It is written once the key exists, so it is excluded from what it authenticates. Any field added by a later version goes before it and is therefore authenticated, as the timestamp is.
+
+### Fixed header
+
+Always present.
+
+| Offset | Size | Field | Value |
+| --- | --- | --- | --- |
+| 0 | 20 | Magic | ASCII `Trilium Notes Backup` |
+| 20 | 1 | Version | `1`. Version `0` is never valid |
+| 21 | 8 | Timestamp | When the backup was taken, in milliseconds since the Unix epoch. `0` when not recorded |
+| 29 | 1 | Flags | Bit 0: gzip-compressed. Bit 1: encrypted. Bits 2 to 7 reserved, must be 0 |
+| 30 | 2 | Header length | Total header size in bytes, i.e. the offset at which the payload starts |
+| 32 | 8 | Plaintext size | Size of the wrapped database in bytes, before compression. `0` when unknown. A hint; the trailer states it authoritatively |
+
+The flags byte, cells are bits:
+
+```mermaid
+---
+config:
+ packet:
+ bitsPerRow: 8
+---
+packet-beta
+0: "gzip"
+1: "enc"
+2-7: "reserved (must be 0)"
+```
+
+`Plaintext size` is a hint, never an instruction. It is unauthenticated in an unencrypted container and, in an encrypted one, is only confirmed once the verifier tag has been checked. Readers must not allocate from it, and must not let it widen any bound. When a container is encrypted but not compressed it equals the total payload plaintext length; when compressed, the payload is shorter by the compression ratio, which is therefore disclosed to anyone holding the file. That disclosure is an accepted trade-off for restore progress reporting and the final length check.
+
+### Trailer
+
+The last {`TRAILER_BYTES`} = 40 bytes of every container, and the only part of it that could not be written until the payload was complete.
+
+| Offset from EOF | Size | Field | Value |
+| --- | --- | --- | --- |
+| \-40 | 32 | Payload digest | SHA-256 over the payload exactly as stored, i.e. bytes `[headerLength, EOF - 40)` |
+| \-8 | 8 | Plaintext size | The plaintext length as counted while writing |
+
+The **payload** therefore runs from `headerLength` to `EOF - 40`, not to end of file.
+
+Putting both at the end is what makes the format forward-writable, and forward-writability is what makes the digest unconditional. A digest in the header has to be patched in after the payload is known, which a download or a socket cannot do; at the end it is simply the next thing written. So every container carries one, including the uncompressed unencrypted container that has nothing else standing behind it.
+
+#### Payload digest
+
+It digests the payload **as stored**, not the plaintext. In an encrypted container that means it covers ciphertext, so it reveals nothing that holding the file does not already reveal, and it can be checked by anyone auditing a backup directory.
+
+It is a corruption check, not an authenticity check. It lies outside everything the header authenticates, so an attacker who can rewrite the file can rewrite the digest with it. Tampering is caught by GCM in an encrypted container; the digest exists to catch bit rot, truncated copies and mangled transfers.
+
+Its practical use on the failure path: when the verifier tag does not match, a reader that then finds the digest **intact** knows the file is undamaged and the passphrase is genuinely wrong.
+
+#### Plaintext size
+
+The authoritative one, counted as the payload went past rather than promised in advance. The header's own `Plaintext size` is a hint for what has to be known up front, a `Content-Length` or a progress bar; this is what the output is actually held to. A reader rejects output that does not measure exactly this, and rejects a header hint that is non-zero and disagrees with it.
+
+#### Finding the trailer
+
+Neither end of the format requires seeking.
+
+* **Encrypted.** Frames are self-delimiting and one carries the final flag, so the trailer is simply the 40 bytes that follow the last frame, and end of file must follow immediately.
+* **Unencrypted.** Nothing announces where the payload stops, so a reader holds the last 40 bytes back as they go past and whatever it is still holding when the input ends is the trailer.
+
+A file too short to contain a trailer is truncated, and says so.
+
+### Derived length
+
+A container that is **not compressed** has a length fixed by its header, because nothing in it varies with content:
+
+```
+unencrypted: 40 + plaintextSize + 40
+encrypted: 84 + plaintextSize + (floor(plaintextSize / 1048576) + 1) * 20 + 40
+```
+
+The encrypted form adds the 4-byte length field and 16-byte tag of every frame, including the empty final frame that a payload of an exact multiple of the frame size still carries. Both forms add the trailer.
+
+Two things follow. A writer knows the exact byte count before it writes anything, which is what lets a download state a `Content-Length` and a browser draw a progress bar. And a reader can compare that figure against the actual file size from the header alone, and reject a file that is short before spending a minute decrypting the part of it that did arrive.
+
+Compression breaks this: the payload is then shorter than the plaintext by a ratio the header does not state, so a compressed container has no predictable length and must not be measured this way.
+
+### Header length
+
+In version 1 the header length is fixed by the flags, and readers must require equality rather than a minimum:
+
+| Flags | Header length |
+| --- | --- |
+| Bit 1 clear | exactly 40 |
+| Bit 1 set | exactly 84 |
+
+A version that appends fields raises the version byte, so an older reader rejects the file on the version check before header length is ever in question. Across all versions two limits hold:
+
+* A header length beyond a reader's configured maximum, for which 4096 is a sane default, is rejected before anything is allocated or sought.
+* A header length extending past the end of the file is rejected. A reader must never seek past EOF on the strength of an unverified field.
+
+### Identifying a container
+
+What a container is, it states in the clear. The version, both flags and the plaintext size all sit in the first 32 bytes and none of them are encrypted, so a reader can tell a compressed backup from an encrypted one, and say what a backup was made from, **without the passphrase and without touching the payload**. Listing a directory of backups costs 32 bytes a file, whatever the files weigh.
+
+A reader doing only this still applies the same checks as any other: the magic, the version, and the reserved flag bits. What it cannot make sense of it should report as an unidentified file rather than as a failure, so that one damaged container cannot derail a listing.
+
+### Encryption header
+
+Present only when flag bit 1 is set.
+
+| Offset | Size | Field | Value |
+| --- | --- | --- | --- |
+| 40 | 1 | KDF id | `1` = scrypt. `2` reserved for Argon2id. Other values reserved |
+| 41 | 3 | KDF params | Three bytes whose meaning is defined by `KDF id` |
+| 44 | 16 | Salt | Random, fresh per file |
+| 60 | 8 | Nonce prefix | Random, fresh per file |
+| 68 | 16 | Verifier tag | AES-256-GCM tag over an empty plaintext |
+
+#### KDF parameters
+
+The three parameter bytes are interpreted per algorithm, so a future KDF is not forced into scrypt's shape:
+
+| KDF id | Byte 33 | Byte 34 | Byte 35 |
+| --- | --- | --- | --- |
+| `1` scrypt | log2(N) | r | p |
+| `2` and above | Defined when the id is assigned | | |
+
+```
+key = scrypt(NFC(passphrase) as UTF-8, salt, 32 bytes, { N: 1 << log2N, r, p })
+```
+
+The passphrase is the user's backup passphrase, which is not the Trilium login password.
+
+**Passphrase encoding is part of the format**: the passphrase is normalised to Unicode NFC and encoded as UTF-8 before it reaches the KDF. Neither JavaScript nor Node normalises implicitly, so an implementation must call `String.prototype.normalize("NFC")` explicitly. Without this, the same passphrase typed with a composed `é` on one machine and a decomposed one on another derives a different key, and the user is told their passphrase is wrong.
+
+The salt is fresh per file, therefore the key is fresh per file, therefore a nonce can never repeat under a key.
+
+Recommended parameters for new files: log2(N) = 17, r = 8, p = 1. Readers must honour the parameters stored in the file rather than their own defaults, within the bounds below.
+
+#### Parameter bounds
+
+A container is untrusted input, and KDF parameters are a resource-exhaustion vector: `log2(N) = 30` asks a reader for more than 128 GiB before a single frame is read. Readers must reject, as an unsupported container:
+
+* scrypt outside `10 <= log2(N) <= 20`, `1 <= r <= 16`, `1 <= p <= 8`.
+* any parameter set whose derivation cost, `128 * N * r` bytes for scrypt, exceeds the reader's configured memory ceiling.
+
+The ceiling is what actually protects the reader, and it must be applied before the derivation is attempted, not caught afterwards.
+
+> A runtime may also impose a ceiling of its own, below these bounds. Node's `crypto.scrypt` defaults `maxmem` to 32 MiB, which is less than the recommended parameters need, so an implementation must raise it explicitly or every derivation fails. That limit belongs to the platform, not to the format: a container written with parameters one reader refuses is still a valid container.
+
+### Payload
+
+| Flags | Payload |
+| --- | --- |
+| Neither set | Raw database bytes, between the header and the trailer |
+| Compressed only | A single RFC 1952 gzip stream |
+| Encrypted | A sequence of frames |
+| Both | A sequence of frames whose plaintext is the RFC 1952 gzip stream |
+
+Compression is applied before encryption.
+
+Writers must emit the gzip stream with MTIME 0, no FNAME and no FEXTRA, and OS byte 255. The gzip header would otherwise carry a timestamp, possibly a source path, and the family of the operating system that wrote it, reintroducing in the payload the metadata this format deliberately keeps out of its own header.
+
+The OS byte usually needs setting after the fact. A zlib-based writer emits its build platform's code there — 3 on Unix, 10 on Windows — and typically offers no way to choose it, so the writer has to overwrite byte 9 of the gzip stream as it passes. That is safe: the byte is informational, and the gzip header lies outside the CRC32, which covers the uncompressed data alone. MTIME and the absent FNAME/FEXTRA usually need nothing, being zlib's defaults already.
+
+### Authenticated header
+
+One span, used by both the verifier tag and every frame:
+
+```
+authenticatedHeader = header bytes [0, verifierTagOffset) // [0, 68) in version 1
+```
+
+It stops before the verifier tag, because the tag is written once the key exists and cannot cover itself. Everything before it is covered, the timestamp included. The trailer is outside it too, being written after the payload, which costs nothing: its digest is a corruption check that GCM already supersedes for tampering.
+
+It matters that frames exclude the tag. Were a frame's AAD to cover the verifier tag, a single flipped bit in that tag would break every frame in the file, and the recovery below would be impossible.
+
+### Verifier tag
+
+```
+nonce = noncePrefix || uint32LE(0xFFFFFFFF)
+aad = authenticatedHeader
+plaintext = empty
+tag = 16 bytes, stored at verifierTagOffset
+```
+
+### Frames
+
+```
+frame := length (4 bytes, LE) || data (length bytes) || tag (16 bytes)
+```
+
+Cells are bytes. The data cell is drawn short: it is `length` bytes, normally 1 MiB.
+
+```mermaid
+---
+config:
+ packet:
+ bitsPerRow: 12
+---
+packet-beta
+0-3: "Length + final bit"
+4-19: "Frame data (length bytes)"
+20-35: "GCM tag"
+```
+
+The length field, cells are bits:
+
+```mermaid
+packet-beta
+0-30: "Frame data length"
+31: "Final"
+```
+
+| Field | Meaning |
+| --- | --- |
+| `length` bits 0 to 30 | Frame data length in bytes. GCM preserves length, so this is both the ciphertext and the plaintext length |
+| `length` bit 31 | Final frame flag |
+| `tag` | AES-256-GCM tag for this frame |
+
+Frames are numbered from 0 in file order. For frame `i`:
+
+```
+nonce_i = noncePrefix (8 bytes) || uint32LE(i)
+aad_i = authenticatedHeader || the 4-byte length field of this frame
+```
+
+Because the counter is in the nonce and the length field is in the AAD, every frame is authenticated to both its position and its length. Reordering, duplicating, resizing or splicing frames all fail verification.
+
+Counter `0xFFFFFFFF` is reserved for the verifier and must never be used by a frame.
+
+#### Framing is canonical
+
+One payload has exactly one valid framing:
+
+* Every frame before the final one carries exactly 1048576 bytes.
+* Exactly one frame has the final flag set, and it is the last frame in the file.
+* The final frame carries 1 to 1048576 bytes, except that it carries 0 bytes when the payload length is 0 or an exact multiple of 1048576.
+* End of file follows the final frame immediately. Trailing bytes make the container invalid.
+
+This constrains framing only. Two containers wrapping identical databases are not byte-identical: the salt and nonce prefix are random per file, and gzip output varies with encoder version and level.
+
+The empty final frame is what lets a writer stream in one pass: frames are sealed as they fill, and the flush seals whatever is left, so a writer never has to know whether more data is coming.
+
+A later version that wants a different frame size must signal it in the header, not vary it silently.
+
+#### Size limits
+
+Usable frame counters run from 0 to `0xFFFFFFFE`, which is 4294967295 frames. At 1 MiB per frame the largest representable payload is just under 4 PiB. Writers must reject a payload that would need more frames than this rather than wrapping the counter, which would repeat a nonce under the file's key.
+
+### Writer requirements
+
+* Fill salt and nonce prefix from a CSPRNG, independently for every file.
+* Normalise the passphrase to NFC and encode it as UTF-8 before deriving the key.
+* Set `Plaintext size` to the size of the source database, or `0` if it is not known.
+* Set reserved flag bits to 0.
+* Emit frames in counter order with no gaps, framed canonically as above, and stop at the frame counter limit rather than wrapping.
+* Emit exactly one final frame, as the last bytes of the file.
+* Compute the payload digest while streaming and write it, with the plaintext length counted as it went past, as the trailer. Never seek: everything is written once, in order.
+* Count the plaintext for the trailer at the input, before compression or framing, so it records the database's own length rather than what the payload became.
+
+The remaining two apply where the destination is a file. A writer streaming to something else, a download or a socket, has no rename to make atomic, and its output is not durable in any sense the writer controls.
+
+* Flush and `fsync` the file before renaming it, and `fsync` the containing directory after the rename on POSIX. Rename gives atomicity, not durability; without the flush a crash can leave a zero-length file under the final name, which is worse than no backup because it looks like one.
+* Write to a uniquely named temporary file in the destination directory and rename on success, so that a partial file never carries the final name and two writers cannot share a temporary. The final name is still a collision point, so writers must be serialised by the caller.
+
+### Reader requirements
+
+* Reject the file unless the first 20 bytes match the magic.
+* Reject version `0`, and reject a version above the reader's own.
+* Reject any reserved flag bit that is set.
+* Reject a header length that is not the exact value this version and these flags require, that exceeds the configured maximum, or that extends past the end of the file.
+* When encrypted, reject an unknown KDF id, reject out-of-bounds KDF parameters, then check the verifier tag before reading any frame.
+* Reject a frame whose claimed length exceeds 1048576, **before** reading its data. The length field can claim up to 2 GiB, and a reader that trusts it buffers that much before the tag check fails.
+* Reject a non-final frame whose length is not 1048576.
+* Verify each frame's tag before emitting any of its plaintext.
+* Reject any frame that follows the final frame, and any trailing bytes after it.
+* Reject end of file that is not preceded by a final frame.
+* Stop the payload at the trailer, not at end of file: after the final frame when encrypted, and by holding the last 40 bytes back when not.
+* Verify the payload digest over the bytes as read, and reject a mismatch. Every container has one.
+* Reject output whose length disagrees with the trailer's `Plaintext size`, and reject a header `Plaintext size` that is non-zero and disagrees with the trailer's.
+* Never allocate from `Plaintext size`. Stream the output and compare lengths at the end.
+* Reject a file with no room for a trailer, and any bytes following it.
+* Where a container is not compressed, its total length is derived from its header, so a file shorter than that is incomplete and may be rejected before any of it is read.
+* Apply a configured output ceiling to decompression **always**, and abort before the excess bytes reach the disk. A non-zero `Plaintext size` may only tighten that bound, never widen it: the field is unauthenticated in an unencrypted container, so a crafted value would otherwise disable the ceiling entirely.
+* Let the AEAD implementation verify tags. Where a tag is compared explicitly, the comparison must be constant-time.
+* Check the SQLite header of the output, as described below.
+
+#### SQLite header check
+
+Cheap, and it catches a container that wrapped something other than a database:
+
+* Bytes 0 to 15 are the magic `SQLite format 3\0`, hex `53514c69746520666f726d6174203300`.
+* Bytes 16 to 17 are the page size, a **big-endian** `uint16`. It must be a power of two between 512 and 32768, or the value `1`, which encodes a page size of 65536. A plain `<= 65536` bound wrongly rejects a 64 KiB-page database, since 65536 does not fit in the field.
+
+#### Rejection conditions
+
+| Condition | Reported as |
+| --- | --- |
+| Magic mismatch | Not a Trilium backup container |
+| Version `0` | Not a valid container |
+| Version above the reader's | Written by a newer Trilium |
+| Reserved flag bit set, unknown KDF id, or out-of-bounds KDF parameters | Unsupported container |
+| Header length wrong, too large, or past EOF | Not a valid container |
+| Verifier tag mismatch | Wrong backup passphrase, or the header is damaged |
+| Frame tag mismatch | Damaged at byte offset N |
+| Frame length out of range | Damaged at byte offset N |
+| Data after the trailer | Damaged |
+| End of file without a final frame | Incomplete or truncated |
+| Payload digest mismatch | Damaged |
+| File too short to hold a trailer | Incomplete or truncated |
+| File shorter than an uncompressed container's derived length | Incomplete or truncated |
+| Output length disagrees with the trailer's `Plaintext size` | Incomplete or truncated |
+| Header `Plaintext size` disagrees with the trailer's | Damaged |
+| Output fails the SQLite header check | Damaged |
+
+A verifier mismatch alone cannot distinguish a wrong passphrase from a bit flip in the salt, nonce prefix or tag. Two recoveries follow from the header layout:
+
+* Check the payload digest. Intact means the passphrase really is wrong.
+* Skip the verifier and attempt frame 0. This succeeds when the damage was confined to the verifier tag, because the tag lies outside the authenticated header.
+
+### Version history
+
+| Version | Change |
+| --- | --- |
+| 1 | Initial format |
+
+The format was reshaped before it shipped, and the version byte was deliberately left at 1: no container written by the old layout exists outside development, so there was nothing to stay compatible with. The two layouts are in any case distinguishable by header length, 64 or 108 against 40 or 84, should anything ever need to tell them apart.
+
+Extension rules:
+
+* Fields may only be appended, before the verifier tag and payload digest, and the version byte is raised when they are. `Header length` locates the payload without parsing the fields, and the authenticated header covers appended fields automatically.
+* Reserved flag bits may be assigned meanings without raising the version, because older readers already reject a bit they do not know. Prefer a flag over a version bump for anything that does not change the layout: it keeps every unaffected file readable by every existing reader.
+* A flag that changes what a reader must verify must say what stands in for the check it removes, and the substitute must be mandatory rather than advisory. Prefer not to have one: a check that every container carries is worth more than a flag that lets some of them skip it.
+* Fields that are only knowable once the payload is written belong in the trailer, never in the header, so that no writer ever has to seek and every destination can hold the format.
+* Version `0` is never valid, because it is what a zero-filled or truncated file produces.
+* The authenticated header is included in every frame's AAD verbatim, which is 60 bytes in version 1 and therefore free. A version that grows it to kilobytes should switch the frame AAD to a digest of it, so that per-frame authentication stays constant-cost.
\ No newline at end of file
diff --git a/docs/User Guide/!!!meta.json b/docs/User Guide/!!!meta.json
index 8dbd58e734..48f2ac4977 100644
--- a/docs/User Guide/!!!meta.json
+++ b/docs/User Guide/!!!meta.json
@@ -2217,13 +2217,6 @@
"isInheritable": false,
"position": 30
},
- {
- "type": "relation",
- "name": "internalLink",
- "value": "Gzjqa934BdH4",
- "isInheritable": false,
- "position": 40
- },
{
"type": "label",
"name": "shareAlias",
@@ -2237,6 +2230,13 @@
"value": "bx bx-hdd",
"isInheritable": false,
"position": 50
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "Gzjqa934BdH4",
+ "isInheritable": false,
+ "position": 60
}
],
"format": "markdown",
@@ -6145,38 +6145,52 @@
{
"type": "relation",
"name": "internalLink",
- "value": "BlN9DFI679QC",
+ "value": "8YBEPzcpUgxw",
"isInheritable": false,
"position": 60
},
{
"type": "relation",
"name": "internalLink",
- "value": "zEY4DaJG4YT5",
+ "value": "BlN9DFI679QC",
"isInheritable": false,
"position": 70
},
{
"type": "relation",
"name": "internalLink",
- "value": "XpOYSgsLkTJy",
+ "value": "zEY4DaJG4YT5",
"isInheritable": false,
"position": 80
},
{
"type": "relation",
"name": "internalLink",
- "value": "s1aBHPd79XYj",
+ "value": "IjZS7iK5EXtb",
"isInheritable": false,
"position": 90
},
{
"type": "relation",
"name": "internalLink",
- "value": "81SGnPGMk7Xc",
+ "value": "XpOYSgsLkTJy",
"isInheritable": false,
"position": 100
},
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "s1aBHPd79XYj",
+ "isInheritable": false,
+ "position": 110
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "81SGnPGMk7Xc",
+ "isInheritable": false,
+ "position": 120
+ },
{
"type": "label",
"name": "shareAlias",
@@ -6190,20 +6204,6 @@
"value": "bx bx-edit-alt",
"isInheritable": false,
"position": 40
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "8YBEPzcpUgxw",
- "isInheritable": false,
- "position": 110
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "IjZS7iK5EXtb",
- "isInheritable": false,
- "position": 120
}
],
"format": "markdown",
@@ -14914,17 +14914,38 @@
{
"type": "relation",
"name": "internalLink",
- "value": "CssoWBu8I7jF",
+ "value": "CoFPLs3dRlXc",
+ "isInheritable": false,
+ "position": 60
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "8YBEPzcpUgxw",
+ "isInheritable": false,
+ "position": 70
+ },
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "BlN9DFI679QC",
"isInheritable": false,
"position": 80
},
{
"type": "relation",
"name": "internalLink",
- "value": "HI6GBBIduIgv",
+ "value": "CssoWBu8I7jF",
"isInheritable": false,
"position": 90
},
+ {
+ "type": "relation",
+ "name": "internalLink",
+ "value": "HI6GBBIduIgv",
+ "isInheritable": false,
+ "position": 100
+ },
{
"type": "label",
"name": "iconClass",
@@ -14945,27 +14966,6 @@
"value": "",
"isInheritable": false,
"position": 30
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "CoFPLs3dRlXc",
- "isInheritable": false,
- "position": 100
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "8YBEPzcpUgxw",
- "isInheritable": false,
- "position": 110
- },
- {
- "type": "relation",
- "name": "internalLink",
- "value": "BlN9DFI679QC",
- "isInheritable": false,
- "position": 120
}
],
"format": "markdown",
diff --git a/docs/User Guide/User Guide/Advanced Usage/Database.md b/docs/User Guide/User Guide/Advanced Usage/Database.md
index 5a4174d64a..072fe0cee0 100644
--- a/docs/User Guide/User Guide/Advanced Usage/Database.md
+++ b/docs/User Guide/User Guide/Advanced Usage/Database.md
@@ -15,6 +15,21 @@ See [Manually altering the database](Database/Manually%20altering%20the%20datab
## How to Reset the Database
+If you want to start again and:
+
+* Create and switch to a new blank knowledge base
+* Use a different knowledge base synced from a server or desktop application
+* Restore a backup
+
+You can navigate to **Settings → Database** and click the **Start over** button. You'll be prompted to restart the application, with the option to back up your current database before proceeding.
+
+> [!IMPORTANT]
+> For the web client, Trilium cannot restart automatically. You'll need to manually restart the server/container and then reload the web application.
+
+After restarting, the setup screen will appear. You can choose to back up your existing database, then proceed with the setup menu as if it's a new installation. The existing database will only be overwritten after selecting to create a new database, sync with a server, or restore from a backup.
+
+### The Legacy Method
+
If you are experimenting with Trilium and want to return it to its original state, you can do that by deleting the current database. When you restart the application, it will generate a new database containing the original demo notes.
To delete the database, simply go to the [data directory](../Installation%20%26%20Setup/Data%20directory.md) and delete the `document.db` file (and any other files starting with `document.db`).
diff --git a/docs/User Guide/User Guide/Installation & Setup/Backup.md b/docs/User Guide/User Guide/Installation & Setup/Backup.md
index 33888c741c..ccd0a62311 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Backup.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Backup.md
@@ -12,24 +12,101 @@ This is only very basic backup solution, and you're encouraged to add some bette
Note that <a class="reference-link" href="Synchronization.md">Synchronization</a> provides also some backup capabilities by its nature of distributing the data to other computers.
-## Downloading backup
+## Creating a backup
-You can download an existing backup by going to Settings > Backup > Existing backups > Download
+### On the desktop application and web client:
-## Restoring backup
+1. Go to **Settings → Backup** and press the **Backup Now** button.
+2. The backup creation process may take a few moments, especially for larger databases. A notification will inform you when the backup is complete.
+3. The backup will be saved as **backup-now** in the **Existing Backups** list, where you can download it.
-Let's assume you want to restore the weekly backup, here's how to do it:
+### On the standalone client
+
+1. **Go to Settings → Backup** and press the "**Download backup**" button.
+2. You will be prompted to **restart the app**. Confirm, and the app will restart automatically.
+3. Set a **backup name** or **password** (both optional), then press "**Continue**".
+4. Press the "**Generate and download"** button and wait for the download to complete.
+5. Once you confirm the download is saved on your device, press **"Finish"** to complete
+
+## Downloading a backup
+
+* **Desktop and web client**: to download an existing backup, navigate to **Settings → Backup → Existing backups** and select **Download**.
+* **Standalone client**: automatic backups are not supported in this version. You can manually create and download a backup by going to **Settings → Backup → Download backup.**
+
+## Restoring a backup
+
+* **For a new Trilium instance**: When setting up a new Trilium instance, use the "Restore from backup" option in the setup menu to guide you through restoring your existing backup.
+* **For an existing Trilium instance**: To restore a backup and replace your current database, go to **Settings → Backup** and click **Restore a backup**. You will be prompted to restart the app for the restoration process to begin. After restarting, you can choose to back up the existing database before overwriting it. Note: For the web client, use the Start Over feature (**Settings → Database → Start over**) to switch to the setup screen and restore a backup.
+
+Next, select the backup file (.db or .tnbackup) from your device. The web client is optimized for handling large backups and is resilient to unstable network conditions, similar to the desktop application.
+
+If your database is encrypted, you will be prompted to enter the password used for encrypting the backup file. Without the correct password, decryption and restoration cannot proceed.
+
+Restoring a backup may take some time, depending on its size. Once it completes, Trilium will open the freshly restored database.
+
+### The alternative way for restoring a backup 
+
+Let's assume you want to restore the weekly backup (only in .db format, .tnbackup files are not supported by this method), here's how to do it:
* find [data directory](Data%20directory.md) Trilium uses - easy way is to open "About Trilium Notes" from "Menu" in upper left corner and looking at "data directory"
* I'll refer to `~/trilium-data` as data directory from now on
-* find `~/trilium-data/backup/backup-weekly.db` - this is the <a class="reference-link" href="../Advanced%20Usage/Database.md">Database</a> backup
+* find `~/trilium-data/backup/backup-weekly.db` - this is the <a class="reference-link" href="../Advanced%20Usage/Database.md">Database</a> backup.
* at this point stop/kill Trilium
* delete `~/trilium-data/document.db`, `~/trilium-data/document.db-wal` and `~/trilium-data/document.db-shm` (latter two files are auto generated)
* copy and rename this `~/trilium-data/backup/backup-weekly.db` to `~/trilium-data/document.db`
* make sure that the file is writable, e.g. with `chmod 600 document.db`
* start Trilium again
-If you have configured sync then you need to do it across all members of the sync cluster, otherwise older version (restored backup) of the document will be detected and synced to the newer version.
+> [!WARNING]
+> If you have configured sync then you need to do it across all members of the sync cluster, otherwise older version (restored backup) of the document will be detected and synced to the newer version.
+
+## Changing the backup location in Trilium (desktop only)
+
+Starting with version 0.105, the Trilium desktop client allows users to change the directory where backups are stored. Follow these steps to specify a custom backup directory:
+
+1. Navigate to **Settings** → **Backup Location**.
+2. Click the **Select Location** button.
+3. Choose any writable directory on your file system. This could include network shares, depending on your operating system.
+
+Once you set a custom directory, all manual and automatic backups will be saved there. If the selected directory becomes unavailable, backups may fail or revert to the default location.
+
+> [!TIP]
+> For better privacy when using unsafe backup locations, you can enable backup encryption, which makes the backup file unreadable without the correct password.
+
+## Backup encryption
+
+Trilium can secure the entire content of the database backup, ensuring it remains unreadable unless the correct password is provided. This is particularly useful for storing backups in unsecured locations, like network shares, unencrypted external drives, or cloud services. 
+
+Encrypted database backups use the Trilium Backup Container (.tnbackup) format, which relies on AES-256-GCM. This authenticated encryption mode scrambles the data and generates a tag confirming it hasn't been altered. The password itself isn't directly used as the key; it's processed through scrypt, a key derivation function designed to be slow and memory-intensive, making brute-force password guessing difficult even with powerful hardware. Each backup also receives a random 16-byte salt, ensuring that the same password never produces the same encryption key twice. Additionally, critical metadata such as chunk order, length, and header flags are cryptographically bound into the encryption (via "additional authenticated data"), preventing undetected tampering like reorder, truncate, or splice operations.
+
+### Enabling backup encryption
+
+To enable encryption for automatic backups in the Desktop application:
+
+1. Go to **Settings → Backup → Backup Options**.
+2. Click on **Turn on Encryption** and set a password.
+
+Once encryption is enabled, all newly created backups (both automatic and manual) will be encrypted with the specified password. Backups created prior to enabling encryption will remain unsecured.
+
+You can change the password anytime using the **Change Password** button. The new password will apply to backups created after the change.
+
+To disable encryption, uncheck **Settings → Backup → Enable Encryption**.
+
+> [!NOTE]
+> On some systems, a keyring may not be available for Trilium to securely store the encryption password. In such cases, the encryption option is disabled.
+
+## Backup compression
+
+Database backups can be optionally compressed to minimize storage footprint. This method is effective primarily when the database consists largely of text content. However, media files (images, videos, audio), along with PDF, ODF, and DOCX files, are already compressed in their original formats and won't benefit from further compression.
+
+Compressed backups are stored using the Trilium Backup Container (.tnbackup), employing RFC 1952 GZIP compression.
+
+> [!WARNING]
+> **Note:** Compression increases the time required for backup creation and restoration. It may also lead to higher CPU usage during automatic backups, potentially draining the battery faster on battery-powered devices. Enable this option only if necessary.
+
+### Enabling Backup Compression (Desktop Only)
+
+To enable compression for new automatic and manual backups, navigate to **Settings → Backup → Backup Options** and toggle **Enable Compression** to on.
## Disabling backup