backupman 0.2.2 → 0.2.4
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 +27 -27
- package/package.json +1 -1
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 {
|
|
28
28
|
return { lastId: 0, snapshots: [] };
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -64,7 +64,7 @@ class BackupMan {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
prompt(question) {
|
|
68
68
|
const rl = readline.createInterface({
|
|
69
69
|
input: process.stdin,
|
|
70
70
|
output: process.stdout
|
|
@@ -103,9 +103,9 @@ class BackupMan {
|
|
|
103
103
|
return `#${snapshot.id} [${ts}] ${msg}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async
|
|
106
|
+
async chooseSnapshotById(index) {
|
|
107
107
|
if (!index.snapshots.length) {
|
|
108
|
-
console.log("No snapshots yet.
|
|
108
|
+
console.log("No snapshots yet. Run `backupman save \"message\"` first.");
|
|
109
109
|
return null;
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -118,52 +118,52 @@ class BackupMan {
|
|
|
118
118
|
console.log("");
|
|
119
119
|
|
|
120
120
|
while (true) {
|
|
121
|
-
const answer = (await this.prompt("
|
|
122
|
-
if (!answer)
|
|
123
|
-
|
|
124
|
-
}
|
|
121
|
+
const answer = (await this.prompt("Snapshot id to restore (empty = cancel): ")).trim();
|
|
122
|
+
if (!answer) return null;
|
|
123
|
+
|
|
125
124
|
const n = Number.parseInt(answer, 10);
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
if (Number.isNaN(n)) {
|
|
126
|
+
console.log("Please enter a numeric id (e.g. 1, 2, 3) or press Enter to cancel.");
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const target = index.snapshots.find(s => s.id === n);
|
|
131
|
+
if (!target) {
|
|
132
|
+
console.log("No snapshot with that id. Check the list above and try again.");
|
|
133
|
+
continue;
|
|
129
134
|
}
|
|
130
|
-
|
|
135
|
+
|
|
136
|
+
return target;
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
async restore() {
|
|
135
141
|
await this.ensureDirs();
|
|
136
142
|
const index = await this.loadIndex();
|
|
137
|
-
const snapshot = await this.
|
|
143
|
+
const snapshot = await this.chooseSnapshotById(index);
|
|
138
144
|
if (!snapshot) {
|
|
139
145
|
console.log("Restore cancelled.");
|
|
140
146
|
return;
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
console.log("");
|
|
144
|
-
console.log("
|
|
145
|
-
|
|
146
|
-
if (confirm !== "y" && confirm !== "yes") {
|
|
147
|
-
console.log("Restore aborted.");
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
console.log("Clearing current directory...");
|
|
150
|
+
console.log("Restoring snapshot: " + this.formatSnapshot(snapshot));
|
|
151
|
+
console.log("Clearing current directory (except .backupman)...");
|
|
152
152
|
await this.deleteEverythingExceptBackupDir();
|
|
153
153
|
|
|
154
|
-
console.log("Restoring snapshot
|
|
154
|
+
console.log("Restoring files from snapshot...");
|
|
155
155
|
const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
|
|
156
156
|
await this.copyDir(srcSnapshotDir, this.rootDir);
|
|
157
157
|
|
|
158
|
-
console.log(
|
|
158
|
+
console.log(`Done. Restored snapshot #${snapshot.id}.`);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
function printUsage() {
|
|
163
163
|
console.log("backupman - ultra-simple local snapshot tool");
|
|
164
164
|
console.log("");
|
|
165
|
-
console.log("
|
|
166
|
-
console.log(
|
|
165
|
+
console.log("Usage:");
|
|
166
|
+
console.log(' backupman save "message"');
|
|
167
167
|
console.log(" backupman restore");
|
|
168
168
|
}
|
|
169
169
|
|
|
@@ -187,7 +187,7 @@ async function main() {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
const id = await manager.createSnapshot(message.trim());
|
|
190
|
-
console.log(
|
|
190
|
+
console.log(`Saved snapshot #${id}.`);
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -196,7 +196,7 @@ async function main() {
|
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
console.error(
|
|
199
|
+
console.error(`Unknown command: ${command}`);
|
|
200
200
|
printUsage();
|
|
201
201
|
process.exit(1);
|
|
202
202
|
}
|