backupman 0.2.0 → 0.2.2
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 +18 -26
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
2
|
const fs = require("fs");
|
|
5
3
|
const path = require("path");
|
|
6
4
|
const readline = require("readline");
|
|
@@ -22,11 +20,11 @@ class BackupMan {
|
|
|
22
20
|
try {
|
|
23
21
|
const data = await fs.promises.readFile(this.indexFile, "utf8");
|
|
24
22
|
const parsed = JSON.parse(data);
|
|
25
|
-
if (!
|
|
23
|
+
if (!parsed.snapshots || typeof parsed.lastId !== "number") {
|
|
26
24
|
throw new Error("Corrupted index");
|
|
27
25
|
}
|
|
28
26
|
return parsed;
|
|
29
|
-
} catch (
|
|
27
|
+
} catch (err) {
|
|
30
28
|
return { lastId: 0, snapshots: [] };
|
|
31
29
|
}
|
|
32
30
|
}
|
|
@@ -121,11 +119,13 @@ class BackupMan {
|
|
|
121
119
|
|
|
122
120
|
while (true) {
|
|
123
121
|
const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
|
|
124
|
-
if (!answer)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
if (!answer) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const n = Number.parseInt(answer, 10);
|
|
126
|
+
if (!Number.isNaN(n)) {
|
|
127
|
+
const found = list.find(s => s.id === n);
|
|
128
|
+
if (found) return found;
|
|
129
129
|
}
|
|
130
130
|
console.log("Invalid id. Please type an existing snapshot id or press Enter to cancel.");
|
|
131
131
|
}
|
|
@@ -141,38 +141,30 @@ class BackupMan {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
console.log("");
|
|
144
|
-
console.log(
|
|
145
|
-
const confirm = (await this.prompt("
|
|
144
|
+
console.log("You chose: " + this.formatSnapshot(snapshot));
|
|
145
|
+
const confirm = (await this.prompt("Overwrite current files with this snapshot? [y/n]: ")).trim().toLowerCase();
|
|
146
146
|
if (confirm !== "y" && confirm !== "yes") {
|
|
147
147
|
console.log("Restore aborted.");
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
console.log("
|
|
152
|
-
await this.createSnapshot(`[auto] before restore from #${snapshot.id}`);
|
|
153
|
-
|
|
154
|
-
console.log("Clearing current directory (except .backupman)...");
|
|
151
|
+
console.log("Clearing current directory...");
|
|
155
152
|
await this.deleteEverythingExceptBackupDir();
|
|
156
153
|
|
|
157
154
|
console.log("Restoring snapshot files...");
|
|
158
155
|
const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
|
|
159
156
|
await this.copyDir(srcSnapshotDir, this.rootDir);
|
|
160
157
|
|
|
161
|
-
console.log(
|
|
158
|
+
console.log("Done. Restored snapshot #" + snapshot.id + ".");
|
|
162
159
|
}
|
|
163
160
|
}
|
|
164
161
|
|
|
165
162
|
function printUsage() {
|
|
166
163
|
console.log("backupman - ultra-simple local snapshot tool");
|
|
167
164
|
console.log("");
|
|
168
|
-
console.log("
|
|
169
|
-
console.log(" backupman save \"message\"
|
|
170
|
-
console.log(" backupman restore
|
|
171
|
-
console.log("");
|
|
172
|
-
console.log("Notes:");
|
|
173
|
-
console.log(" - Run this inside the folder you want to protect (e.g. your project root or src)");
|
|
174
|
-
console.log(" - Snapshots are stored in .backupman/snapshots");
|
|
175
|
-
console.log(" - .backupman, node_modules, .git are ignored when copying");
|
|
165
|
+
console.log("Commands:");
|
|
166
|
+
console.log(" backupman save \"message\"");
|
|
167
|
+
console.log(" backupman restore");
|
|
176
168
|
}
|
|
177
169
|
|
|
178
170
|
async function main() {
|
|
@@ -195,7 +187,7 @@ async function main() {
|
|
|
195
187
|
}
|
|
196
188
|
}
|
|
197
189
|
const id = await manager.createSnapshot(message.trim());
|
|
198
|
-
console.log(
|
|
190
|
+
console.log("Saved snapshot #" + id + ".");
|
|
199
191
|
return;
|
|
200
192
|
}
|
|
201
193
|
|
|
@@ -204,7 +196,7 @@ async function main() {
|
|
|
204
196
|
return;
|
|
205
197
|
}
|
|
206
198
|
|
|
207
|
-
console.error(
|
|
199
|
+
console.error("Unknown command: " + command);
|
|
208
200
|
printUsage();
|
|
209
201
|
process.exit(1);
|
|
210
202
|
}
|