Merge pull request #370 from naturallaw777/arena/019fb4e9-sovran-systemsos

Manual Backup: match the system role (Desktop Only scope fix)
This commit is contained in:
Sovran Systems
2026-07-30 16:50:21 -05:00
committed by GitHub
3 changed files with 188 additions and 84 deletions
+13
View File
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
--- ---
## [Unreleased]
### Fixed
- **Manual Backup now matches the system role**: on the Desktop Only role the Hub's
"What gets backed up" list no longer shows Node / Server + Desktop items
(nix-bitcoin secrets, `/var/lib` system service data, and the database/blockchain
caveats), and the backup script skips those stages entirely — Desktop Only backups
now mirror only the NixOS configuration (`/etc/nixos`) and home directory (`/home`).
The free-space estimate, stage numbering, backup manifest, and completion message
are all role-aware; Node and Server + Desktop backups are unchanged.
---
## [1.0.4] - 2026-07-29 ## [1.0.4] - 2026-07-29
### Added ### Added
@@ -3,10 +3,18 @@
# Backs up Sovran_SystemsOS data to an external USB hard drive using rsync. # Backs up Sovran_SystemsOS data to an external USB hard drive using rsync.
# Designed for the Hub web UI (no GUI dependencies). # Designed for the Hub web UI (no GUI dependencies).
# #
# Your Sovran Pro already backs up your data automatically to its # On Server + Desktop and Node systems, your Sovran Pro already backs up
# internal second drive (BTCEcoandBackup at /run/media/Second_Drive). # your data automatically to its internal second drive (BTCEcoandBackup at
# This script creates an additional copy on an external USB drive — # /run/media/Second_Drive); this script stores a copy in a third location.
# storing your data in a third location for maximum protection. # Desktop Only systems have no internal second drive, so the external copy
# is the second location.
#
# What gets mirrored depends on the system role:
# - Node / Server + Desktop: /etc/nixos, /etc/nix-bitcoin-secrets,
# /home, and /var/lib (minus databases, blockchain data, logs, caches).
# - Desktop Only: /etc/nixos and /home. Desktop Only runs no server or
# Bitcoin services, so there are no nix-bitcoin secrets or system
# service data to back up.
# #
# The external drive must be formatted as ext4. Files are stored as # The external drive must be formatted as ext4. Files are stored as
# directly browsable files under Sovran_SystemsOS_Backup/current/. # directly browsable files under Sovran_SystemsOS_Backup/current/.
@@ -344,6 +352,19 @@ case "$ROLE" in
esac esac
log "Detected role: $ROLE_LABEL" log "Detected role: $ROLE_LABEL"
# Backup scope depends on the role. Desktop Only systems run no server or
# Bitcoin services, so only the NixOS configuration and home directory are
# mirrored (2 stages). Node and Server + Desktop systems also mirror the
# nix-bitcoin secrets and /var/lib system service data (4 stages).
if [[ "$ROLE" == "desktop" ]]; then
TOTAL_STAGES=2
HOME_STAGE_NUM=2
log "Desktop Only role: backing up the NixOS configuration (/etc/nixos) and home directory (/home) only."
else
TOTAL_STAGES=4
HOME_STAGE_NUM=3
fi
# ── Detect target drive ────────────────────────────────────────── # ── Detect target drive ──────────────────────────────────────────
if [[ -n "${BACKUP_TARGET:-}" ]]; then if [[ -n "${BACKUP_TARGET:-}" ]]; then
@@ -385,12 +406,14 @@ log "Backup destination: $BACKUP_DIR"
ETC_NIXOS_BYTES=$(estimate_path_bytes /etc/nixos) ETC_NIXOS_BYTES=$(estimate_path_bytes /etc/nixos)
HOME_BYTES=$(estimate_path_bytes /home --exclude='*/.cache' --exclude='*/.local/share/Trash' --exclude='*/Trash') HOME_BYTES=$(estimate_path_bytes /home --exclude='*/.cache' --exclude='*/.local/share/Trash' --exclude='*/Trash')
# nix-bitcoin secrets and /var/lib system service data exist only on the
# Node and Server + Desktop roles — they are skipped entirely on Desktop Only.
SECRETS_BYTES=0 SECRETS_BYTES=0
VAR_LIB_BYTES=0
if [[ "$ROLE" != "desktop" ]]; then if [[ "$ROLE" != "desktop" ]]; then
SECRETS_BYTES=$(estimate_path_bytes /etc/nix-bitcoin-secrets) SECRETS_BYTES=$(estimate_path_bytes /etc/nix-bitcoin-secrets)
fi VAR_LIB_BYTES=$(estimate_path_bytes /var/lib \
VAR_LIB_BYTES=$(estimate_path_bytes /var/lib \
--exclude='postgresql' \ --exclude='postgresql' \
--exclude='mysql' \ --exclude='mysql' \
--exclude='mariadb' \ --exclude='mariadb' \
@@ -400,6 +423,7 @@ VAR_LIB_BYTES=$(estimate_path_bytes /var/lib \
--exclude='*/logs' \ --exclude='*/logs' \
--exclude='*/cache' \ --exclude='*/cache' \
--exclude='*/tmp') --exclude='*/tmp')
fi
ESTIMATED_BYTES=$(( ETC_NIXOS_BYTES + HOME_BYTES + SECRETS_BYTES + VAR_LIB_BYTES )) ESTIMATED_BYTES=$(( ETC_NIXOS_BYTES + HOME_BYTES + SECRETS_BYTES + VAR_LIB_BYTES ))
# Require 20% growth headroom plus a fixed 1 GiB safety margin. # Require 20% growth headroom plus a fixed 1 GiB safety margin.
@@ -418,10 +442,10 @@ log "Free space on drive: ${FREE_GB} GB"
(( FREE_BYTES >= REQUIRED_BYTES )) || \ (( FREE_BYTES >= REQUIRED_BYTES )) || \
fail "Not enough free space on drive (${FREE_GB} GB available, ${REQUIRED_GB} GB required)." fail "Not enough free space on drive (${FREE_GB} GB available, ${REQUIRED_GB} GB required)."
# ── Stage 1/4: NixOS configuration ────────────────────────────── # ── Stage 1: NixOS configuration ────────────────────────────────
log "" log ""
log "── Stage 1/4: NixOS configuration (/etc/nixos) ──────────────" log "── Stage 1/${TOTAL_STAGES}: NixOS configuration (/etc/nixos) ──────────────"
if [[ -d /etc/nixos ]]; then if [[ -d /etc/nixos ]]; then
sync_tree "/etc/nixos" no /etc/nixos/ "$BACKUP_DIR/etc/nixos/" sync_tree "/etc/nixos" no /etc/nixos/ "$BACKUP_DIR/etc/nixos/"
log "Stage 1 complete." log "Stage 1 complete."
@@ -429,26 +453,30 @@ else
log "WARNING: /etc/nixos not found — skipping." log "WARNING: /etc/nixos not found — skipping."
fi fi
# ── Stage 2/4: Secrets ────────────────────────────────────────── # ── Stage 2: Secrets ────────────────────────────────────────────
# Only applies to the Node and Server + Desktop roles. Desktop Only systems
# run no nix-bitcoin services, so there are no secrets to back up and this
# stage does not exist for them.
log "" if [[ "$ROLE" != "desktop" ]]; then
log "── Stage 2/4: Secrets (/etc/nix-bitcoin-secrets) ───────────" log ""
if [[ "$ROLE" == "desktop" ]]; then log "── Stage 2/${TOTAL_STAGES}: Secrets (/etc/nix-bitcoin-secrets) ───────────"
log "Skipping /etc/nix-bitcoin-secrets — not applicable for Desktop Only role." if [[ -e /etc/nix-bitcoin-secrets ]]; then
elif [[ -e /etc/nix-bitcoin-secrets ]]; then
sync_tree "/etc/nix-bitcoin-secrets" no /etc/nix-bitcoin-secrets/ "$BACKUP_DIR/etc/nix-bitcoin-secrets/" sync_tree "/etc/nix-bitcoin-secrets" no /etc/nix-bitcoin-secrets/ "$BACKUP_DIR/etc/nix-bitcoin-secrets/"
else else
log "(not found: /etc/nix-bitcoin-secrets — skipping)" log "(not found: /etc/nix-bitcoin-secrets — skipping)"
fi
log "Stage 2 complete."
fi fi
log "Stage 2 complete."
# ── Stage 3/4: Home directory ─────────────────────────────────── # ── Home directory ──────────────────────────────────────────────
# Stage 2/2 on Desktop Only, stage 3/4 on Node and Server + Desktop.
# Rsync exit code 24 (vanished source files) is treated as nonfatal here # Rsync exit code 24 (vanished source files) is treated as nonfatal here
# because the desktop may be active and files can disappear between the # because the desktop may be active and files can disappear between the
# directory scan and the copy. All other nonzero exit codes remain fatal. # directory scan and the copy. All other nonzero exit codes remain fatal.
log "" log ""
log "── Stage 3/4: Home directory (/home) ───────────────────────" log "── Stage ${HOME_STAGE_NUM}/${TOTAL_STAGES}: Home directory (/home) ───────────────────────"
if [[ -d /home ]]; then if [[ -d /home ]]; then
sync_tree "/home" yes /home/ "$BACKUP_DIR/home/" \ sync_tree "/home" yes /home/ "$BACKUP_DIR/home/" \
--exclude='.cache/' \ --exclude='.cache/' \
@@ -467,19 +495,22 @@ if [[ -d /home ]]; then
--exclude='.thumbnails/' \ --exclude='.thumbnails/' \
--exclude='.xsession-errors' \ --exclude='.xsession-errors' \
--exclude='.xsession-errors.old' --exclude='.xsession-errors.old'
log "Stage 3 complete." log "Stage ${HOME_STAGE_NUM} complete."
else else
log "WARNING: /home not found — skipping." log "WARNING: /home not found — skipping."
fi fi
# ── Stage 4/4: System data ────────────────────────────────────── # ── Stage 4: System data ────────────────────────────────────────
# Only applies to the Node and Server + Desktop roles — Desktop Only systems
# run no server services, so /var/lib holds no service data worth mirroring.
# PostgreSQL/MariaDB raw database directories are excluded. Application # PostgreSQL/MariaDB raw database directories are excluded. Application
# databases must be backed up separately with native database tools. # databases must be backed up separately with native database tools.
# Bitcoin/Electrs data are excluded; they live on the internal second drive. # Bitcoin/Electrs data are excluded; they live on the internal second drive.
log "" if [[ "$ROLE" != "desktop" ]]; then
log "── Stage 4/4: System data (/var/lib) ───────────────────────" log ""
if [[ -d /var/lib ]]; then log "── Stage 4/${TOTAL_STAGES}: System data (/var/lib) ───────────────────────"
if [[ -d /var/lib ]]; then
sync_tree "/var/lib" no /var/lib/ "$BACKUP_DIR/var/lib/" \ sync_tree "/var/lib" no /var/lib/ "$BACKUP_DIR/var/lib/" \
--exclude='postgresql/' \ --exclude='postgresql/' \
--exclude='mysql/' \ --exclude='mysql/' \
@@ -491,8 +522,9 @@ if [[ -d /var/lib ]]; then
--exclude='*/cache/' \ --exclude='*/cache/' \
--exclude='*/tmp/' --exclude='*/tmp/'
log "Stage 4 complete." log "Stage 4 complete."
else else
log "WARNING: /var/lib not found — skipping." log "WARNING: /var/lib not found — skipping."
fi
fi fi
# ── Generate manifest ──────────────────────────────────────────── # ── Generate manifest ────────────────────────────────────────────
@@ -517,23 +549,29 @@ MANIFEST_FILE="$BACKUP_DIR/BACKUP_MANIFEST.txt"
echo "- /etc/nix-bitcoin-secrets (when present) → current/etc/nix-bitcoin-secrets/" echo "- /etc/nix-bitcoin-secrets (when present) → current/etc/nix-bitcoin-secrets/"
fi fi
echo "- /home → current/home/" echo "- /home → current/home/"
if [[ "$ROLE" != "desktop" ]]; then
echo "- /var/lib → current/var/lib/" echo "- /var/lib → current/var/lib/"
fi
echo "" echo ""
echo "Exclusions:" echo "Exclusions:"
if [[ "$ROLE" != "desktop" ]]; then
echo "- /var/lib/postgresql (PostgreSQL raw database files — not included)" echo "- /var/lib/postgresql (PostgreSQL raw database files — not included)"
echo "- /var/lib/mysql, /var/lib/mariadb (MariaDB raw database files — not included)" echo "- /var/lib/mysql, /var/lib/mariadb (MariaDB raw database files — not included)"
echo "- /var/lib/bitcoind (Bitcoin blockchain — excluded; lives on internal second drive)" echo "- /var/lib/bitcoind (Bitcoin blockchain — excluded; lives on internal second drive)"
echo "- /var/lib/electrs (Electrs index — excluded; lives on internal second drive)" echo "- /var/lib/electrs (Electrs index — excluded; lives on internal second drive)"
echo "- /run/media/Second_Drive (internal second drive — never traversed)" echo "- /run/media/Second_Drive (internal second drive — never traversed)"
echo "- /var/lib/*/log, /var/lib/*/logs, /var/lib/*/cache, /var/lib/*/tmp" echo "- /var/lib/*/log, /var/lib/*/logs, /var/lib/*/cache, /var/lib/*/tmp"
fi
echo "- Browser disk caches, thumbnail caches, trash directories, X session error logs" echo "- Browser disk caches, thumbnail caches, trash directories, X session error logs"
echo "" echo ""
echo "Important limitations:" echo "Important limitations:"
if [[ "$ROLE" != "desktop" ]]; then
echo "- PostgreSQL and MariaDB/MySQL application databases are NOT included in this" echo "- PostgreSQL and MariaDB/MySQL application databases are NOT included in this"
echo " backup. If you use Nextcloud, Matrix/Synapse, or other database-backed" echo " backup. If you use Nextcloud, Matrix/Synapse, or other database-backed"
echo " applications, their data must be backed up separately using native tools." echo " applications, their data must be backed up separately using native tools."
echo "- Bitcoin blockchain data and Electrs indexes are NOT included; they are" echo "- Bitcoin blockchain data and Electrs indexes are NOT included; they are"
echo " reconstructable or stored on the internal second drive." echo " reconstructable or stored on the internal second drive."
fi
echo "- This is a live file-level mirror, not a transactional database backup." echo "- This is a live file-level mirror, not a transactional database backup."
echo " Files being written during the backup may be in an inconsistent state." echo " Files being written during the backup may be in an inconsistent state."
echo "" echo ""
@@ -542,7 +580,9 @@ MANIFEST_FILE="$BACKUP_DIR/BACKUP_MANIFEST.txt"
echo "- To restore a directory:" echo "- To restore a directory:"
echo " sudo rsync -aAXH --numeric-ids current/etc/nixos/ /etc/nixos/" echo " sudo rsync -aAXH --numeric-ids current/etc/nixos/ /etc/nixos/"
echo " sudo rsync -aAXH --numeric-ids current/home/ /home/" echo " sudo rsync -aAXH --numeric-ids current/home/ /home/"
if [[ "$ROLE" != "desktop" ]]; then
echo " sudo rsync -aAXH --numeric-ids current/var/lib/ /var/lib/" echo " sudo rsync -aAXH --numeric-ids current/var/lib/ /var/lib/"
fi
echo "- To copy individual files:" echo "- To copy individual files:"
echo " sudo cp -a current/home/username/ /home/username/" echo " sudo cp -a current/home/username/ /home/username/"
echo "- When restoring /etc/nixos to replacement hardware, regenerate" echo "- When restoring /etc/nixos to replacement hardware, regenerate"
@@ -556,10 +596,12 @@ MANIFEST_FILE="$BACKUP_DIR/BACKUP_MANIFEST.txt"
echo "- $warning" echo "- $warning"
done done
fi fi
if [[ "$ROLE" != "desktop" ]]; then
echo "" echo ""
echo "Note: Bitcoin blockchain and Electrs index data are intentionally excluded" echo "Note: Bitcoin blockchain and Electrs index data are intentionally excluded"
echo "from manual external backup because they already live on the internal second drive" echo "from manual external backup because they already live on the internal second drive"
echo "(/run/media/Second_Drive) and are reconstructable/internal-backup data." echo "(/run/media/Second_Drive) and are reconstructable/internal-backup data."
fi
} > "$MANIFEST_FILE" } > "$MANIFEST_FILE"
log "Manifest written to $MANIFEST_FILE" log "Manifest written to $MANIFEST_FILE"
@@ -576,7 +618,11 @@ if [[ "${#RSYNC_WARNINGS[@]}" -gt 0 ]]; then
log "vanished during backup, which is normal on an active desktop." log "vanished during backup, which is normal on an active desktop."
log "" log ""
fi fi
log "All Finished! Your data is now backed up to a third location." if [[ "$ROLE" == "desktop" ]]; then
log "All Finished! Your data is now backed up to a second, external location."
else
log "All Finished! Your data is now backed up to a third location."
fi
log "Files are directly browsable on the drive under: ${BACKUP_DIR}" log "Files are directly browsable on the drive under: ${BACKUP_DIR}"
log "Please eject the drive safely before removing it from your Sovran Pro." log "Please eject the drive safely before removing it from your Sovran Pro."
+60 -15
View File
@@ -473,11 +473,27 @@ function renderBackupReady(drives) {
].join(""); ].join("");
} }
$supportBody.innerHTML = [ // ── Role-aware backup description ─────────────────────────────
'<div class="support-section">', // Desktop Only systems run no server or Bitcoin services and have no
'<div class="support-icon-big">\ud83d\udcbe</div>', // internal second drive, so the backup mirrors only the NixOS configuration
'<h3 class="support-heading">Manual Backup</h3>', // and home directory. nix-bitcoin secrets, /var/lib system service data,
// and the database/blockchain caveats apply only to the Node and
// Server + Desktop roles.
var isDesktopOnly = (_currentRole === "desktop");
var introHtml;
if (isDesktopOnly) {
introHtml = [
'<div class="support-wallet-box support-wallet-protected" style="margin-bottom:16px;">',
'<p class="support-wallet-desc">',
'This manual backup lets you create a copy of your system on an external USB drive \u2014 ',
'storing your data in a second location, outside the computer, for maximum protection ',
'against hardware failure or physical damage.',
'</p>',
'</div>',
].join("");
} else {
introHtml = [
'<div class="support-wallet-box support-wallet-protected" style="margin-bottom:16px;">', '<div class="support-wallet-box support-wallet-protected" style="margin-bottom:16px;">',
'<p class="support-wallet-desc">', '<p class="support-wallet-desc">',
'Your Sovran Pro already backs up your data automatically to its internal second drive. ', 'Your Sovran Pro already backs up your data automatically to its internal second drive. ',
@@ -486,6 +502,44 @@ function renderBackupReady(drives) {
'against hardware failure or physical damage.', 'against hardware failure or physical damage.',
'</p>', '</p>',
'</div>', '</div>',
].join("");
}
var backupItemsHtml;
if (isDesktopOnly) {
backupItemsHtml = [
'<li>NixOS configuration (<code>/etc/nixos</code>)</li>',
'<li>Home directory (<code>/home</code>)</li>',
].join("");
} else {
backupItemsHtml = [
'<li>NixOS configuration (<code>/etc/nixos</code>)</li>',
'<li>nix-bitcoin secrets (<code>/etc/nix-bitcoin-secrets</code>)</li>',
'<li>System service data (<code>/var/lib</code>) — excluding databases and blockchain data (see note below)</li>',
'<li>Home directory (<code>/home</code>)</li>',
].join("");
}
// The database/blockchain caveat is only relevant when server services exist.
var dbNoteHtml = "";
if (!isDesktopOnly) {
dbNoteHtml = [
'<div class="support-wallet-box support-wallet-warning">',
'<div class="support-wallet-header">',
'<span class="support-wallet-icon">\u2139\ufe0f</span>',
'<span class="support-wallet-title">Database and Blockchain Data</span>',
'</div>',
'<p class="support-wallet-desc">Application databases stored in PostgreSQL or MariaDB/MySQL are <strong>not included</strong> in Manual Backup. Bitcoin blockchain and Electrs index data are also excluded (they are stored on the internal second drive). If you use Nextcloud, Matrix, or other database-backed applications, back up those databases separately with their native tools.</p>',
'</div>',
].join("");
}
$supportBody.innerHTML = [
'<div class="support-section">',
'<div class="support-icon-big">\ud83d\udcbe</div>',
'<h3 class="support-heading">Manual Backup</h3>',
introHtml,
'<div class="support-steps">', '<div class="support-steps">',
'<div class="support-steps-title">Requirements</div>', '<div class="support-steps-title">Requirements</div>',
@@ -500,20 +554,11 @@ function renderBackupReady(drives) {
'<div class="support-steps">', '<div class="support-steps">',
'<div class="support-steps-title">What gets backed up</div>', '<div class="support-steps-title">What gets backed up</div>',
'<ol class="support-backup-steps">', '<ol class="support-backup-steps">',
'<li>NixOS configuration (<code>/etc/nixos</code>)</li>', backupItemsHtml,
'<li>nix-bitcoin secrets (<code>/etc/nix-bitcoin-secrets</code>)</li>',
'<li>System service data (<code>/var/lib</code>) — excluding databases and blockchain data (see note below)</li>',
'<li>Home directory (<code>/home</code>)</li>',
'</ol>', '</ol>',
'</div>', '</div>',
'<div class="support-wallet-box support-wallet-warning">', dbNoteHtml,
'<div class="support-wallet-header">',
'<span class="support-wallet-icon">\u2139\ufe0f</span>',
'<span class="support-wallet-title">Database and Blockchain Data</span>',
'</div>',
'<p class="support-wallet-desc">Application databases stored in PostgreSQL or MariaDB/MySQL are <strong>not included</strong> in Manual Backup. Bitcoin blockchain and Electrs index data are also excluded (they are stored on the internal second drive). If you use Nextcloud, Matrix, or other database-backed applications, back up those databases separately with their native tools.</p>',
'</div>',
'<div class="support-wallet-box support-wallet-protected">', '<div class="support-wallet-box support-wallet-protected">',
'<div class="support-wallet-header">', '<div class="support-wallet-header">',