@farhan0431/db-snap 0.3.10 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -10
- package/binaries/aarch64-apple-darwin/dbsnap +0 -0
- package/binaries/aarch64-unknown-linux-gnu/dbsnap +0 -0
- package/binaries/x86_64-apple-darwin/dbsnap +0 -0
- package/binaries/x86_64-pc-windows-msvc/dbsnap.exe +0 -0
- package/binaries/x86_64-unknown-linux-gnu/dbsnap +0 -0
- package/binaries/x86_64-unknown-linux-musl/dbsnap +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ Supports **SQLite**, **PostgreSQL**, and **MySQL/MariaDB**. The npm package
|
|
|
10
10
|
bundles prebuilt binaries for Windows x64, macOS Intel and Apple Silicon, and
|
|
11
11
|
Linux x64 (glibc and musl) and ARM64 (glibc).
|
|
12
12
|
|
|
13
|
+
**MySQL/MariaDB restore works on the original database.** Stop application
|
|
14
|
+
connections, writers, and scheduled events first. Restore is non-atomic and
|
|
15
|
+
requires a pinned safety snapshot. Interrupted restores must recover that
|
|
16
|
+
snapshot before another restore; see the recovery steps below.
|
|
17
|
+
|
|
13
18
|
## Install
|
|
14
19
|
|
|
15
20
|
Requires Node.js 16 or later.
|
|
@@ -41,7 +46,8 @@ dbsnap list
|
|
|
41
46
|
dbsnap restore "before migration" # restores the selected snapshot
|
|
42
47
|
```
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
Target resolution is `--db`, then process `DATABASE_URL`, then project `.env`,
|
|
50
|
+
then common SQLite paths. To choose a
|
|
45
51
|
database explicitly, use `dbsnap init --db ./prisma/dev.db`. Check the target
|
|
46
52
|
with `dbsnap status` before restoring: a restore changes the live database.
|
|
47
53
|
|
|
@@ -67,11 +73,32 @@ the following to your project's `.cursor/mcp.json`:
|
|
|
67
73
|
Restart your client and ask it to run `dbsnap_status` to confirm the database
|
|
68
74
|
before making changes. The server also exposes tools to create, list, restore,
|
|
69
75
|
and prune snapshots. It resolves the project from its working directory, so
|
|
70
|
-
start it in the project you want to protect.
|
|
76
|
+
start it in the project you want to protect. The six tools are:
|
|
77
|
+
|
|
78
|
+
| MCP tool | Purpose |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `dbsnap_status` | Inspect the target, engine, and snapshot storage. |
|
|
81
|
+
| `dbsnap_create_snapshot` | Save a snapshot, optionally supplying `tag`. |
|
|
82
|
+
| `dbsnap_list_snapshots` | List available restore points. |
|
|
83
|
+
| `dbsnap_diff` | Compare supported snapshots using `from` and `to`. |
|
|
84
|
+
| `dbsnap_restore_snapshot` | Restore a selected `tag_or_id`, or the newest snapshot. |
|
|
85
|
+
| `dbsnap_prune` | Prune with a positive integer `keep`; pinned snapshots survive. |
|
|
86
|
+
|
|
87
|
+
Restore and prune are disabled by default in MCP. To enable them for a server
|
|
88
|
+
session, start it with `dbsnap mcp --allow-destructive`. Each operation requires
|
|
89
|
+
approval through an MCP client supporting elicitation; otherwise use the CLI.
|
|
90
|
+
|
|
91
|
+
To configure an explicitly enabled session, change the server arguments to
|
|
92
|
+
`["mcp", "--allow-destructive"]`. Enabling the session does not approve individual
|
|
93
|
+
operations. Your MCP client must still present and return the confirmation for
|
|
94
|
+
each restore or prune.
|
|
71
95
|
|
|
72
96
|
`dbsnap init` also writes `.agents/skills/dbsnap/SKILL.md` in the project.
|
|
73
97
|
Whether that skill is loaded automatically depends on the AI client; the skill
|
|
74
98
|
file and the MCP server are separate integrations.
|
|
99
|
+
Initialization preserves an existing skill file instead of overwriting local
|
|
100
|
+
customizations. Updating the installed binary does not refresh that existing
|
|
101
|
+
file; review it against the repository's current skill when upgrading.
|
|
75
102
|
|
|
76
103
|
## Commands
|
|
77
104
|
|
|
@@ -84,11 +111,65 @@ file and the MCP server are separate integrations.
|
|
|
84
111
|
| `dbsnap restore [tag-or-id]` | Restore a snapshot; omit the selector for the latest. |
|
|
85
112
|
| `dbsnap rollback` | Restore the latest snapshot. |
|
|
86
113
|
| `dbsnap prune --keep 5` | Remove older snapshots and retain the newest five. |
|
|
87
|
-
| `dbsnap diff before after` | Compare SQLite snapshot schemas and
|
|
114
|
+
| `dbsnap diff before after` | Compare SQLite, PostgreSQL clone, or MySQL/MariaDB dump snapshot schemas and row counts. |
|
|
115
|
+
| `dbsnap pin <tag-or-id>` | Protect a snapshot from pruning; use `unpin` to remove protection. |
|
|
116
|
+
| `dbsnap unpin <tag-or-id>` | Remove protection after reviewing the snapshot. |
|
|
117
|
+
| `dbsnap prune --all` | Delete all unpinned snapshots. |
|
|
118
|
+
| `dbsnap save tag --method dump` | Create a portable PostgreSQL dump snapshot. |
|
|
119
|
+
|
|
120
|
+
`dbsnap list --json` and `dbsnap status --json` provide machine-readable output.
|
|
121
|
+
Pinned snapshots survive `prune`, including `--all`.
|
|
122
|
+
|
|
123
|
+
Use the recorded ID when undoing a specific change. Duplicate tags may be
|
|
124
|
+
ambiguous. `rollback` and `restore` without a selector choose the newest
|
|
125
|
+
snapshot, which can be an automatic safety snapshot from a previous restore.
|
|
126
|
+
|
|
127
|
+
## Snapshot diff
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
dbsnap save before
|
|
131
|
+
# Make your development changes.
|
|
132
|
+
dbsnap save after
|
|
133
|
+
dbsnap diff before after
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Diff compares **snapshots**, not the current live database. SQLite compares
|
|
137
|
+
schema objects and row counts. PostgreSQL clone diff compares table/view
|
|
138
|
+
definitions and row counts. MySQL/MariaDB diff reads verified standard dumps
|
|
139
|
+
offline, including multiline `INSERT` data, and compares table definitions
|
|
140
|
+
and row counts. It does not replay SQL into the target.
|
|
141
|
+
|
|
142
|
+
Equal row counts do not mean equal data. Individual row contents are not
|
|
143
|
+
compared. PostgreSQL diff excludes indexes, constraints, routines and triggers;
|
|
144
|
+
MySQL/MariaDB diff excludes views, routines, triggers and events. Unsupported
|
|
145
|
+
INSERT formats produce an error. PostgreSQL dump archives are not supported.
|
|
146
|
+
|
|
147
|
+
## Recovering an interrupted MySQL/MariaDB restore
|
|
148
|
+
|
|
149
|
+
A fresh restore creates, syncs and catalogs a pinned safety snapshot before
|
|
150
|
+
cleanup. It preserves the database itself and replaces objects inside it.
|
|
151
|
+
`--no-safety-snapshot` is rejected for fresh MySQL/MariaDB restores.
|
|
152
|
+
|
|
153
|
+
If restore fails after the recovery journal is written:
|
|
154
|
+
|
|
155
|
+
1. Keep application writers/connections and scheduled events stopped.
|
|
156
|
+
2. Fix the reported disk-space, connection or privilege problem. Local free
|
|
157
|
+
space checks do not measure the database server's storage.
|
|
158
|
+
3. Read the recovery ID in the error or `.dbsnap/mysql-restore.json`, then run:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
dbsnap restore RECOVERY_ID
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The journal stores the recovery ID as a JSON string. Other restore IDs and
|
|
165
|
+
unpinning are refused while recovery is pending. Recovery uses the existing
|
|
166
|
+
pinned snapshot; it does not snapshot the partially restored target.
|
|
167
|
+
If the journal is malformed or the recovery copy is missing/corrupt, preserve
|
|
168
|
+
the files and investigate. Do not delete the journal to bypass recovery.
|
|
88
169
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
170
|
+
After success, safety snapshots remain pinned until you review and explicitly
|
|
171
|
+
unpin them. Restore remains non-atomic and requires trusted dumps; preflight
|
|
172
|
+
checks do not prevent another application from reconnecting during replay.
|
|
92
173
|
|
|
93
174
|
## Database requirements
|
|
94
175
|
|
|
@@ -100,15 +181,32 @@ MySQL/MariaDB snapshot diffs are not currently supported.
|
|
|
100
181
|
|
|
101
182
|
PostgreSQL server-side clones are stored on the database server. Use dump mode
|
|
102
183
|
when the snapshot needs to survive removal of that server's data volume.
|
|
184
|
+
For dump save and restore, install `pg_dump` and `pg_restore` matching the
|
|
185
|
+
PostgreSQL server's major version. Mismatched tools are rejected before restore.
|
|
186
|
+
The SQLite database file must already exist. MySQL/MariaDB snapshots retain
|
|
187
|
+
routines, triggers and events, although diff does not compare those objects.
|
|
188
|
+
Snapshot runtime and connection disruption depend on the engine and data size.
|
|
103
189
|
|
|
104
190
|
## Safety
|
|
105
191
|
|
|
106
|
-
-
|
|
107
|
-
targets.
|
|
192
|
+
- MCP permits SQLite and loopback database hosts only. The CLI also permits
|
|
193
|
+
private-network targets by default. A local target is not necessarily safe.
|
|
108
194
|
- Project binding checks that the current target matches the recorded database.
|
|
109
|
-
- Restore
|
|
195
|
+
- Restore checks SQLite chunks and dump artifacts before applying them and, by default,
|
|
110
196
|
creates a safety snapshot first. If that snapshot cannot be created, restore
|
|
111
|
-
stops
|
|
197
|
+
stops. Only SQLite/PostgreSQL allow explicit opt-out; fresh MySQL/MariaDB
|
|
198
|
+
restores require a pinned safety snapshot.
|
|
199
|
+
- A PostgreSQL server-side clone has a metadata fingerprint, not a content
|
|
200
|
+
checksum. dbsnap checks that the clone exists before restore.
|
|
201
|
+
- PostgreSQL restore is not atomic; an interruption can require manual
|
|
202
|
+
recovery. Clone and staged dump restores journal their cutover.
|
|
203
|
+
- MySQL restore is in-place and non-atomic. Stop writers/events first. Visible
|
|
204
|
+
target connections and enabled events cause refusal before cleanup; this is
|
|
205
|
+
not a fence against future connections. Keep the pinned snapshot and recovery
|
|
206
|
+
journal if replay fails, including when server storage is full.
|
|
207
|
+
- PostgreSQL network connections require verified TLS. Set `DBSNAP_PG_CA_CERT`
|
|
208
|
+
to a trusted CA PEM file if needed; use `DBSNAP_PG_TLS=verify-full` to require
|
|
209
|
+
TLS on loopback connections as well.
|
|
112
210
|
|
|
113
211
|
dbsnap is intended for development workflows. Keep independent backups for
|
|
114
212
|
data you cannot afford to lose.
|
|
@@ -117,6 +215,8 @@ data you cannot afford to lose.
|
|
|
117
215
|
|
|
118
216
|
- [Repository and full documentation](https://github.com/farhan0431/db-snap)
|
|
119
217
|
- [MCP installation guide](https://github.com/farhan0431/db-snap/blob/main/INSTALL.md)
|
|
218
|
+
- [Testing and audit coverage](https://github.com/farhan0431/db-snap/blob/main/docs/TESTING.md)
|
|
219
|
+
- [MySQL recovery](https://github.com/farhan0431/db-snap/blob/main/docs/MYSQL-RESTORE.md)
|
|
120
220
|
- [Report an issue](https://github.com/farhan0431/db-snap/issues)
|
|
121
221
|
|
|
122
222
|
MIT license.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farhan0431/db-snap",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.14",
|
|
4
|
+
"description": "Development database snapshots and MCP server for SQLite, PostgreSQL, and MySQL/MariaDB.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
7
|
"dbsnap": "bin/dbsnap.js"
|