backupman 0.2.4 → 0.3.1
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/index.js +34 -22
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -24,7 +24,7 @@ class BackupMan {
|
|
|
24
24
|
throw new Error("Corrupted index");
|
|
25
25
|
}
|
|
26
26
|
return parsed;
|
|
27
|
-
} catch {
|
|
27
|
+
} catch (err) {
|
|
28
28
|
return { lastId: 0, snapshots: [] };
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -64,7 +64,7 @@ class BackupMan {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
prompt(question) {
|
|
67
|
+
async prompt(question) {
|
|
68
68
|
const rl = readline.createInterface({
|
|
69
69
|
input: process.stdin,
|
|
70
70
|
output: process.stdout
|
|
@@ -103,9 +103,11 @@ class BackupMan {
|
|
|
103
103
|
return `#${snapshot.id} [${ts}] ${msg}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async
|
|
106
|
+
async listSnapshots() {
|
|
107
|
+
await this.ensureDirs();
|
|
108
|
+
const index = await this.loadIndex();
|
|
107
109
|
if (!index.snapshots.length) {
|
|
108
|
-
console.log(
|
|
110
|
+
console.log('No snapshots yet. Run: backupman save "message"');
|
|
109
111
|
return null;
|
|
110
112
|
}
|
|
111
113
|
|
|
@@ -116,42 +118,52 @@ class BackupMan {
|
|
|
116
118
|
console.log(" " + this.formatSnapshot(s));
|
|
117
119
|
});
|
|
118
120
|
console.log("");
|
|
121
|
+
return { index, list };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async chooseSnapshot() {
|
|
125
|
+
const data = await this.listSnapshots();
|
|
126
|
+
if (!data) return null;
|
|
127
|
+
const { index } = data;
|
|
119
128
|
|
|
120
129
|
while (true) {
|
|
121
|
-
const answer = (await this.prompt("
|
|
130
|
+
const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
|
|
122
131
|
if (!answer) return null;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
console.log("Please enter a numeric id (e.g. 1, 2, 3) or press Enter to cancel.");
|
|
132
|
+
const id = Number.parseInt(answer, 10);
|
|
133
|
+
if (Number.isNaN(id)) {
|
|
134
|
+
console.log("Please enter a valid number.");
|
|
127
135
|
continue;
|
|
128
136
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
console.log("No snapshot with that id. Check the list above and try again.");
|
|
137
|
+
const picked = index.snapshots.find(s => s.id === id);
|
|
138
|
+
if (!picked) {
|
|
139
|
+
console.log("No snapshot with that id. Try again.");
|
|
133
140
|
continue;
|
|
134
141
|
}
|
|
135
|
-
|
|
136
|
-
return target;
|
|
142
|
+
return picked;
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
145
|
|
|
140
146
|
async restore() {
|
|
141
|
-
await this.
|
|
142
|
-
const index = await this.loadIndex();
|
|
143
|
-
const snapshot = await this.chooseSnapshotById(index);
|
|
147
|
+
const snapshot = await this.chooseSnapshot();
|
|
144
148
|
if (!snapshot) {
|
|
145
149
|
console.log("Restore cancelled.");
|
|
146
150
|
return;
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
console.log("");
|
|
150
|
-
console.log("
|
|
154
|
+
console.log("You chose snapshot: " + this.formatSnapshot(snapshot));
|
|
155
|
+
const confirm = (await this.prompt("Restore this snapshot and overwrite current files? (y/n): ")).trim().toLowerCase();
|
|
156
|
+
if (confirm !== "y" && confirm !== "yes") {
|
|
157
|
+
console.log("Restore aborted.");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await this.ensureDirs();
|
|
162
|
+
|
|
151
163
|
console.log("Clearing current directory (except .backupman)...");
|
|
152
164
|
await this.deleteEverythingExceptBackupDir();
|
|
153
165
|
|
|
154
|
-
console.log("Restoring files
|
|
166
|
+
console.log("Restoring snapshot files...");
|
|
155
167
|
const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
|
|
156
168
|
await this.copyDir(srcSnapshotDir, this.rootDir);
|
|
157
169
|
|
|
@@ -163,8 +175,8 @@ function printUsage() {
|
|
|
163
175
|
console.log("backupman - ultra-simple local snapshot tool");
|
|
164
176
|
console.log("");
|
|
165
177
|
console.log("Usage:");
|
|
166
|
-
console.log(' backupman save "message"');
|
|
167
|
-
console.log(" backupman restore");
|
|
178
|
+
console.log(' backupman save "message" Save current directory as a snapshot');
|
|
179
|
+
console.log(" backupman restore Restore from a snapshot");
|
|
168
180
|
}
|
|
169
181
|
|
|
170
182
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backupman",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Ultra-simple local snapshot
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Ultra-simple local snapshot tool for when your code (or your AI) goes off the rails.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"backupman": "index.js"
|
|
7
7
|
},
|