backupman 0.2.2 → 0.2.3
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 +31 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -103,7 +103,9 @@ 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
110
|
console.log("No snapshots yet. Use `backupman save \"message\"` first.");
|
|
109
111
|
return null;
|
|
@@ -116,55 +118,57 @@ class BackupMan {
|
|
|
116
118
|
console.log(" " + this.formatSnapshot(s));
|
|
117
119
|
});
|
|
118
120
|
console.log("");
|
|
119
|
-
|
|
120
|
-
while (true) {
|
|
121
|
-
const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
|
|
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
|
-
}
|
|
130
|
-
console.log("Invalid id. Please type an existing snapshot id or press Enter to cancel.");
|
|
131
|
-
}
|
|
121
|
+
return { index, list };
|
|
132
122
|
}
|
|
133
123
|
|
|
134
124
|
async restore() {
|
|
135
|
-
await this.
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
125
|
+
const loaded = await this.listSnapshots();
|
|
126
|
+
if (!loaded) return;
|
|
127
|
+
const { index } = loaded;
|
|
128
|
+
|
|
129
|
+
const answer = (await this.prompt("Type snapshot id to restore (empty = cancel): ")).trim();
|
|
130
|
+
if (!answer) {
|
|
139
131
|
console.log("Restore cancelled.");
|
|
140
132
|
return;
|
|
141
133
|
}
|
|
142
134
|
|
|
135
|
+
const id = Number.parseInt(answer, 10);
|
|
136
|
+
if (Number.isNaN(id)) {
|
|
137
|
+
console.log("Invalid id. Restore aborted.");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const snapshot = index.snapshots.find(s => s.id === id);
|
|
142
|
+
if (!snapshot) {
|
|
143
|
+
console.log("Snapshot not found. Restore aborted.");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
143
147
|
console.log("");
|
|
144
|
-
console.log(
|
|
145
|
-
const confirm = (await this.prompt("
|
|
148
|
+
console.log(`You chose snapshot: ${this.formatSnapshot(snapshot)}`);
|
|
149
|
+
const confirm = (await this.prompt("Restore this snapshot and overwrite current folder? (y/n): ")).trim().toLowerCase();
|
|
146
150
|
if (confirm !== "y" && confirm !== "yes") {
|
|
147
151
|
console.log("Restore aborted.");
|
|
148
152
|
return;
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
console.log("Clearing current directory...");
|
|
155
|
+
console.log("Clearing current directory (except .backupman)...");
|
|
152
156
|
await this.deleteEverythingExceptBackupDir();
|
|
153
157
|
|
|
154
158
|
console.log("Restoring snapshot files...");
|
|
155
159
|
const srcSnapshotDir = path.join(this.snapshotsDir, String(snapshot.id));
|
|
156
160
|
await this.copyDir(srcSnapshotDir, this.rootDir);
|
|
157
161
|
|
|
158
|
-
console.log(
|
|
162
|
+
console.log(`Done. Restored snapshot #${snapshot.id}.`);
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
function printUsage() {
|
|
163
167
|
console.log("backupman - ultra-simple local snapshot tool");
|
|
164
168
|
console.log("");
|
|
165
|
-
console.log("
|
|
166
|
-
console.log(
|
|
167
|
-
console.log(" backupman restore");
|
|
169
|
+
console.log("Usage:");
|
|
170
|
+
console.log(' backupman save "message" Save current directory as a snapshot');
|
|
171
|
+
console.log(" backupman restore Restore from a snapshot");
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
async function main() {
|
|
@@ -187,7 +191,7 @@ async function main() {
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
const id = await manager.createSnapshot(message.trim());
|
|
190
|
-
console.log(
|
|
194
|
+
console.log(`Saved snapshot #${id}.`);
|
|
191
195
|
return;
|
|
192
196
|
}
|
|
193
197
|
|
|
@@ -196,7 +200,7 @@ async function main() {
|
|
|
196
200
|
return;
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
console.error(
|
|
203
|
+
console.error(`Unknown command: ${command}`);
|
|
200
204
|
printUsage();
|
|
201
205
|
process.exit(1);
|
|
202
206
|
}
|