backupman 0.2.1 → 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 +17 -21
- 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,24 +141,21 @@ 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
|
|
|
@@ -166,9 +163,8 @@ function printUsage() {
|
|
|
166
163
|
console.log("backupman - ultra-simple local snapshot tool");
|
|
167
164
|
console.log("");
|
|
168
165
|
console.log("Commands:");
|
|
169
|
-
console.log(" backupman save \"message\"
|
|
170
|
-
console.log(" backupman restore
|
|
171
|
-
console.log("");
|
|
166
|
+
console.log(" backupman save \"message\"");
|
|
167
|
+
console.log(" backupman restore");
|
|
172
168
|
}
|
|
173
169
|
|
|
174
170
|
async function main() {
|
|
@@ -191,7 +187,7 @@ async function main() {
|
|
|
191
187
|
}
|
|
192
188
|
}
|
|
193
189
|
const id = await manager.createSnapshot(message.trim());
|
|
194
|
-
console.log(
|
|
190
|
+
console.log("Saved snapshot #" + id + ".");
|
|
195
191
|
return;
|
|
196
192
|
}
|
|
197
193
|
|
|
@@ -200,7 +196,7 @@ async function main() {
|
|
|
200
196
|
return;
|
|
201
197
|
}
|
|
202
198
|
|
|
203
|
-
console.error(
|
|
199
|
+
console.error("Unknown command: " + command);
|
|
204
200
|
printUsage();
|
|
205
201
|
process.exit(1);
|
|
206
202
|
}
|