feat(miner): add backup and restore commands for the local-state directory (#4872)#5551
feat(miner): add backup and restore commands for the local-state directory (#4872)#5551carlh7777 wants to merge 1 commit into
Conversation
This update introduces two new commands, `gittensory-miner backup` and `gittensory-miner restore`, allowing users to create and restore backups of the entire local-state directory. The backup command ensures that existing directories are not overwritten, while the restore command requires the miner to be stopped to prevent data corruption. Documentation has been updated to reflect these changes, and unit tests have been added to ensure functionality and error handling. Closes JSONbored#4872.
|
🚨 Contributor flagged. Click here for more info: Superagent Dashboard |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5551 +/- ##
=======================================
Coverage 94.87% 94.88%
=======================================
Files 568 569 +1
Lines 45055 45104 +49
Branches 14675 14675
=======================================
+ Hits 42746 42795 +49
Misses 1575 1575
Partials 734 734
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Caution 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥 🛑 Gittensory review result - reject/close recommendedReview updated: 2026-07-13 04:47:31 UTC
🛑 Suggested Action - Reject/Close Review summary Blockers
Nits — 5 non-blocking
Why this is blocked
📋 Copy for AI agents — paste into your coding agentFlagged checks (non-blocking)
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
[BETA] Chat with GittensoryAsk Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
|
Gittensory is closing this pull request on the maintainer's behalf (AI reviewers agree on a likely critical defect: packages/gittensory-miner/lib/backup-cli.js:44 copies only `resolveMinerStateDir(env)`, so a user with documented per-store overrides like `GITTENSORY_MINER_PORTFOLIO_QUEUE_DB=/data/queue.sqlite3` gets a successful backup that silently omits live state; either enumerate/include overridden store paths or change the command/docs/output contract so it does not claim a complete local-state backup.). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed. |
Summary
There was no backup/restore tooling for the miner's local SQLite state. This adds two offline CLI commands:
gittensory-miner backup <target-dir>— copies the entire local-state directory (every SQLite store plus its WAL/-shmsidecars) to<target-dir>. Refuses to overwrite an existing directory, so a backup never silently clobbers a previous one.gittensory-miner restore <source-dir>— copies a backup back over the live state directory.Both resolve the same directory the rest of the CLI uses (
GITTENSORY_MINER_CONFIG_DIR, else the XDG default), are purely local file operations (dispatched before the update check, likestatus/doctor/migrate), and support--json(reusing the sharedcli-error.jsfailure helper, #4836) for a monitored backup job.Whole-directory, not per-file. The miner has no central store registry — each store module resolves its own path — so a hand-maintained per-file list would go stale as stores are added. Copying the directory as a unit is complete by construction and future-proof, and it brings the WAL sidecars along so an un-checkpointed write isn't lost. Per the issue, this is the "straightforward file-copy-based" approach; the consistency caveat (a copy taken mid-write can capture a torn page; a restore overwrites open files) is surfaced both in the command's own output and in the docs: stop the miner first.
Documentation: a Backup & restore section in
docs/operations-runbook.md.Closes #4872
Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
git diff --checknpm run typechecknode --checkon the changedlib/binfiles (the miner build gate)npm run docs:drift-checkminer-backup-cli.test.tsexercise real temp-directory file ops end-to-end — backup (files + sidecars, refuse-overwrite, no-state-dir,--json), restore (data round-trip, no-backup-dir,--json), parse errors, both fail-safe catch paths, empty-arg, and theprocess.envfallback. 100% statement + branch coverage onbackup-cli.js.npm run test:workers·build:mcp·ui:*— N/A (miner-package + test change only; no worker/MCP/UI/OpenAPI surface).If any required check was skipped, explain why:
Change is confined to the miner package (
libauthored JS validated bynode --check+ its.d.ts, a newbindispatch case, a help line, an ops-runbook doc section) and a unit test. No workersrc/**, workflow, orscripts/**guarded paths are touched.Safety
UI Evidence
N/A — CLI + docs only.
Notes
backupintentionally errors rather than overwriting an existing target directory; use a fresh (e.g. date-stamped) path per backup.GITTENSORY_MINER_CONFIG_DIRalready does that; backup/restore are for point-in-time snapshots.