@datatruck/cli 0.26.2 → 0.28.0
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/Action/BackupAction.d.ts +69 -34
- package/Action/BackupAction.js +284 -244
- package/Action/CleanCacheAction.d.ts +8 -4
- package/Action/CleanCacheAction.js +8 -5
- package/Action/ConfigAction.d.ts +12 -5
- package/Action/ConfigAction.js +14 -18
- package/Action/CopyAction.d.ts +49 -0
- package/Action/CopyAction.js +144 -0
- package/Action/InitAction.d.ts +3 -3
- package/Action/InitAction.js +9 -9
- package/Action/PruneAction.d.ts +9 -9
- package/Action/PruneAction.js +39 -23
- package/Action/RestoreAction.d.ts +48 -23
- package/Action/RestoreAction.js +158 -195
- package/Action/SnapshotsAction.d.ts +8 -8
- package/Action/SnapshotsAction.js +8 -8
- package/CHANGELOG.md +495 -0
- package/Command/BackupCommand.d.ts +6 -4
- package/Command/BackupCommand.js +9 -26
- package/Command/CleanCacheCommand.d.ts +4 -4
- package/Command/CleanCacheCommand.js +26 -5
- package/Command/CommandAbstract.d.ts +10 -7
- package/Command/CommandAbstract.js +4 -1
- package/Command/ConfigCommand.d.ts +6 -9
- package/Command/ConfigCommand.js +13 -8
- package/Command/CopyCommand.d.ts +15 -0
- package/Command/CopyCommand.js +61 -0
- package/Command/InitCommand.d.ts +4 -4
- package/Command/InitCommand.js +11 -15
- package/Command/PruneCommand.d.ts +3 -3
- package/Command/PruneCommand.js +13 -12
- package/Command/RestoreCommand.js +9 -17
- package/Command/SnapshotsCommand.d.ts +4 -4
- package/Command/SnapshotsCommand.js +16 -15
- package/Command/StartServerCommand.d.ts +6 -0
- package/Command/StartServerCommand.js +24 -0
- package/Config/Config.d.ts +11 -0
- package/Config/Config.js +43 -0
- package/Config/PrunePolicyConfig.d.ts +2 -2
- package/Factory/CommandFactory.d.ts +29 -33
- package/Factory/CommandFactory.js +32 -53
- package/Factory/RepositoryFactory.d.ts +1 -1
- package/Factory/RepositoryFactory.js +3 -3
- package/Factory/TaskFactory.d.ts +1 -1
- package/Factory/TaskFactory.js +3 -3
- package/Repository/DatatruckRepository.d.ts +17 -16
- package/Repository/DatatruckRepository.js +131 -149
- package/Repository/GitRepository.d.ts +9 -8
- package/Repository/GitRepository.js +22 -25
- package/Repository/RepositoryAbstract.d.ts +39 -37
- package/Repository/RepositoryAbstract.js +4 -5
- package/Repository/ResticRepository.d.ts +9 -8
- package/Repository/ResticRepository.js +30 -28
- package/Task/GitTask.d.ts +6 -7
- package/Task/GitTask.js +24 -30
- package/Task/MariadbTask.d.ts +4 -5
- package/Task/MariadbTask.js +26 -32
- package/Task/MssqlTask.d.ts +5 -3
- package/Task/MssqlTask.js +11 -12
- package/Task/MysqlDumpTask.d.ts +10 -3
- package/Task/MysqlDumpTask.js +107 -31
- package/Task/ScriptTask.d.ts +23 -18
- package/Task/ScriptTask.js +34 -24
- package/Task/SqlDumpTaskAbstract.d.ts +8 -3
- package/Task/SqlDumpTaskAbstract.js +31 -19
- package/Task/TaskAbstract.d.ts +24 -25
- package/Task/TaskAbstract.js +6 -10
- package/cli.js +14 -5
- package/config.schema.json +124 -3
- package/package.json +4 -5
- package/utils/DataFormat.d.ts +23 -12
- package/utils/DataFormat.js +36 -14
- package/utils/cli.d.ts +2 -9
- package/utils/cli.js +9 -52
- package/utils/datatruck/client.d.ts +24 -0
- package/utils/datatruck/client.js +99 -0
- package/utils/datatruck/config.d.ts +8 -6
- package/utils/datatruck/config.js +18 -3
- package/utils/datatruck/paths.d.ts +5 -9
- package/utils/datatruck/paths.js +2 -2
- package/utils/datatruck/server.d.ts +21 -0
- package/utils/datatruck/server.js +96 -0
- package/utils/datatruck/snapshot.d.ts +2 -2
- package/utils/date.d.ts +7 -3
- package/utils/date.js +22 -14
- package/utils/fs.d.ts +27 -15
- package/utils/fs.js +110 -62
- package/utils/http.d.ts +21 -0
- package/utils/http.js +154 -0
- package/utils/list.d.ts +64 -0
- package/utils/list.js +145 -0
- package/utils/mysql.d.ts +2 -0
- package/utils/mysql.js +21 -2
- package/utils/process.d.ts +1 -0
- package/utils/process.js +24 -31
- package/utils/progress.d.ts +33 -0
- package/utils/progress.js +113 -0
- package/utils/steps.d.ts +11 -0
- package/utils/steps.js +22 -10
- package/utils/stream.d.ts +7 -0
- package/utils/stream.js +10 -0
- package/utils/string.d.ts +0 -1
- package/utils/string.js +1 -13
- package/utils/tar.d.ts +10 -3
- package/utils/tar.js +70 -44
- package/utils/temp.d.ts +26 -0
- package/utils/temp.js +133 -0
- package/utils/virtual-fs.d.ts +37 -0
- package/utils/virtual-fs.js +65 -0
- package/Action/BackupSessionsAction.d.ts +0 -13
- package/Action/BackupSessionsAction.js +0 -18
- package/Action/RestoreSessionsAction.d.ts +0 -13
- package/Action/RestoreSessionsAction.js +0 -18
- package/Command/BackupSessionsCommand.d.ts +0 -12
- package/Command/BackupSessionsCommand.js +0 -92
- package/Command/RestoreSessionsCommand.d.ts +0 -12
- package/Command/RestoreSessionsCommand.js +0 -91
- package/Decorator/EntityDecorator.d.ts +0 -11
- package/Decorator/EntityDecorator.js +0 -17
- package/Entity/BackupSessionEntity.d.ts +0 -6
- package/Entity/BackupSessionEntity.js +0 -25
- package/Entity/BackupSessionRepositoryEntity.d.ts +0 -6
- package/Entity/BackupSessionRepositoryEntity.js +0 -25
- package/Entity/BackupSessionTaskEntity.d.ts +0 -5
- package/Entity/BackupSessionTaskEntity.js +0 -24
- package/Entity/CrudEntityAbstract.d.ts +0 -5
- package/Entity/CrudEntityAbstract.js +0 -9
- package/Entity/RestoreSessionEntity.d.ts +0 -5
- package/Entity/RestoreSessionEntity.js +0 -24
- package/Entity/RestoreSessionRepositoryEntity.d.ts +0 -6
- package/Entity/RestoreSessionRepositoryEntity.js +0 -25
- package/Entity/RestoreSessionTaskEntity.d.ts +0 -5
- package/Entity/RestoreSessionTaskEntity.js +0 -24
- package/Entity/StateEntityAbstract.d.ts +0 -9
- package/Entity/StateEntityAbstract.js +0 -12
- package/Factory/EntityFactory.d.ts +0 -6
- package/Factory/EntityFactory.js +0 -40
- package/SessionDriver/ConsoleSessionDriver.d.ts +0 -42
- package/SessionDriver/ConsoleSessionDriver.js +0 -208
- package/SessionDriver/SessionDriverAbstract.d.ts +0 -77
- package/SessionDriver/SessionDriverAbstract.js +0 -28
- package/SessionDriver/SqliteSessionDriver.d.ts +0 -20
- package/SessionDriver/SqliteSessionDriver.js +0 -173
- package/SessionManager/BackupSessionManager.d.ts +0 -45
- package/SessionManager/BackupSessionManager.js +0 -218
- package/SessionManager/RestoreSessionManager.d.ts +0 -47
- package/SessionManager/RestoreSessionManager.js +0 -218
- package/SessionManager/SessionManagerAbstract.d.ts +0 -18
- package/SessionManager/SessionManagerAbstract.js +0 -36
- package/migrations/001-initial.sql +0 -98
- package/utils/entity.d.ts +0 -4
- package/utils/entity.js +0 -10
package/Action/RestoreAction.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.RestoreAction = void 0;
|
|
4
|
-
const AppError_1 = require("../Error/AppError");
|
|
5
7
|
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
6
8
|
const TaskFactory_1 = require("../Factory/TaskFactory");
|
|
9
|
+
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
10
|
const cli_1 = require("../utils/cli");
|
|
8
11
|
const config_1 = require("../utils/datatruck/config");
|
|
12
|
+
const date_1 = require("../utils/date");
|
|
9
13
|
const fs_1 = require("../utils/fs");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
14
|
+
const list_1 = require("../utils/list");
|
|
15
|
+
const progress_1 = require("../utils/progress");
|
|
16
|
+
const temp_1 = require("../utils/temp");
|
|
12
17
|
const SnapshotsAction_1 = require("./SnapshotsAction");
|
|
13
18
|
const assert_1 = require("assert");
|
|
14
|
-
const
|
|
19
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
15
20
|
class RestoreAction {
|
|
16
21
|
config;
|
|
17
22
|
options;
|
|
@@ -21,36 +26,6 @@ class RestoreAction {
|
|
|
21
26
|
this.config = config;
|
|
22
27
|
this.options = options;
|
|
23
28
|
}
|
|
24
|
-
assocConfigs(packages, snapshots) {
|
|
25
|
-
return snapshots.map((snapshot) => {
|
|
26
|
-
const pkg = packages.find((pkg) => pkg.name === snapshot.packageName) ?? null;
|
|
27
|
-
return [snapshot, pkg];
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async init(session, snapshotId, snapshots) {
|
|
31
|
-
await session.initDrivers();
|
|
32
|
-
for (const [snapshot, pkg] of snapshots) {
|
|
33
|
-
if (!pkg)
|
|
34
|
-
throw new AppError_1.AppError(`Package config not found: ${snapshot.packageName}`);
|
|
35
|
-
const sessionId = await session.init({
|
|
36
|
-
snapshotId: snapshotId,
|
|
37
|
-
packageName: pkg.name,
|
|
38
|
-
});
|
|
39
|
-
if (pkg.task)
|
|
40
|
-
await session.initTask({
|
|
41
|
-
sessionId: sessionId,
|
|
42
|
-
taskName: pkg.task.name,
|
|
43
|
-
});
|
|
44
|
-
for (const repositoryName of pkg.repositoryNames ?? []) {
|
|
45
|
-
const repo = (0, config_1.findRepositoryOrFail)(this.config, repositoryName);
|
|
46
|
-
await session.initRepository({
|
|
47
|
-
sessionId: sessionId,
|
|
48
|
-
repositoryName: repositoryName,
|
|
49
|
-
repositoryType: repo.type,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
29
|
async findSnapshots() {
|
|
55
30
|
const result = [];
|
|
56
31
|
for (const repository of this.config.repositories) {
|
|
@@ -90,178 +65,166 @@ class RestoreAction {
|
|
|
90
65
|
return true;
|
|
91
66
|
});
|
|
92
67
|
}
|
|
93
|
-
async
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
error = AppError_1.AppError.create("Repository failed", this.repoErrors[pkg.name]);
|
|
104
|
-
}
|
|
105
|
-
else if (this.taskErrors[pkg.name]?.length) {
|
|
106
|
-
error = AppError_1.AppError.create("Previous task failed", this.taskErrors[pkg.name]);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
try {
|
|
110
|
-
await task.onRestore({
|
|
111
|
-
package: pkg,
|
|
68
|
+
async restore(data) {
|
|
69
|
+
let { snapshot, pkg, task } = data;
|
|
70
|
+
const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
|
|
71
|
+
const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
|
|
72
|
+
if (!this.options.restorePath)
|
|
73
|
+
pkg = { ...pkg, restorePath: pkg.path };
|
|
74
|
+
let snapshotPath = pkg.restorePath ?? pkg.path;
|
|
75
|
+
await data.gc.cleanupIfFail(async () => {
|
|
76
|
+
if (task) {
|
|
77
|
+
const taskResult = await task.prepareRestore({
|
|
112
78
|
options: this.options,
|
|
79
|
+
package: pkg,
|
|
113
80
|
snapshot,
|
|
114
|
-
targetPath,
|
|
115
|
-
onProgress: async (progress) => {
|
|
116
|
-
await session.progressTask({
|
|
117
|
-
id: taskId,
|
|
118
|
-
progress,
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
81
|
});
|
|
82
|
+
snapshotPath = taskResult?.snapshotPath;
|
|
122
83
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
await session.endTask({
|
|
130
|
-
id: taskId,
|
|
131
|
-
error: error?.stack,
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
error: error ? false : true,
|
|
135
|
-
tmpDirs: task?.tmpDirs ?? [],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
async restore(session, pkg, repo, snapshot, targetPath) {
|
|
139
|
-
const repositoryId = session.findRepositoryId({
|
|
140
|
-
packageName: pkg.name,
|
|
141
|
-
repositoryName: repo.name,
|
|
142
|
-
});
|
|
143
|
-
await session.startRepository({
|
|
144
|
-
id: repositoryId,
|
|
145
|
-
});
|
|
146
|
-
let repoError;
|
|
147
|
-
let repoInstance;
|
|
148
|
-
if (!this.options.restorePath)
|
|
149
|
-
pkg = {
|
|
150
|
-
...pkg,
|
|
151
|
-
restorePath: pkg.path,
|
|
152
|
-
};
|
|
153
|
-
try {
|
|
154
|
-
if (typeof pkg.restorePath !== "string")
|
|
155
|
-
throw new AppError_1.AppError("Restore path is not defined");
|
|
156
|
-
await (0, fs_1.mkdirIfNotExists)(pkg.restorePath);
|
|
157
|
-
if (!(await (0, fs_1.isEmptyDir)(pkg.restorePath)))
|
|
158
|
-
throw new AppError_1.AppError(`Restore path is not empty: ${pkg.restorePath}`);
|
|
159
|
-
if (this.options.verbose)
|
|
160
|
-
(0, cli_1.logExec)(`restorePath=${pkg.restorePath}`);
|
|
161
|
-
repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
|
|
162
|
-
await repoInstance.onRestore({
|
|
163
|
-
package: pkg,
|
|
164
|
-
targetPath,
|
|
165
|
-
packageConfig: pkg.repositoryConfigs?.find((config) => config.type === repo.type &&
|
|
166
|
-
(!config.names || config.names.includes(repo.name)))?.config,
|
|
84
|
+
await (0, fs_1.initEmptyDir)(snapshotPath);
|
|
85
|
+
if (this.config.minFreeDiskSpace)
|
|
86
|
+
await (0, fs_1.ensureFreeDiskSpace)([snapshotPath], this.config.minFreeDiskSpace);
|
|
87
|
+
await repo.restore({
|
|
167
88
|
options: this.options,
|
|
168
|
-
snapshot: snapshot,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
89
|
+
snapshot: data.snapshot,
|
|
90
|
+
package: pkg,
|
|
91
|
+
snapshotPath: snapshotPath,
|
|
92
|
+
packageConfig: pkg.repositoryConfigs?.find((config) => config.type === repoConfig.type &&
|
|
93
|
+
(!config.names || config.names.includes(repoConfig.name)))?.config,
|
|
94
|
+
onProgress: data.onProgress,
|
|
175
95
|
});
|
|
176
|
-
if (pkg.restorePermissions && (0, os_1.platform)() !== "win32")
|
|
177
|
-
await (0, process_1.exec)("chown", [
|
|
178
|
-
"-R",
|
|
179
|
-
`${pkg.restorePermissions.uid}:${pkg.restorePermissions.gid}`,
|
|
180
|
-
pkg.restorePath,
|
|
181
|
-
], {}, {
|
|
182
|
-
log: this.options.verbose,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
(0, object_1.push)(this.repoErrors, pkg.name, (repoError = error));
|
|
187
|
-
}
|
|
188
|
-
await session.endRepository({
|
|
189
|
-
id: repositoryId,
|
|
190
|
-
error: repoError?.stack,
|
|
191
96
|
});
|
|
192
|
-
return {
|
|
193
|
-
error: repoError ? false : true,
|
|
194
|
-
tmpDirs: repoInstance?.tmpDirs || [],
|
|
195
|
-
};
|
|
97
|
+
return { snapshotPath };
|
|
196
98
|
}
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
99
|
+
dataFormat(result, options = {}) {
|
|
100
|
+
const renderTitle = (item, color) => {
|
|
101
|
+
let title = item.key.slice(0, 1).toUpperCase() + item.key.slice(1);
|
|
102
|
+
return item.key === "restore" && color ? chalk_1.default.cyan(title) : title;
|
|
103
|
+
};
|
|
104
|
+
const renderData = (item, color) => {
|
|
105
|
+
const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
|
|
106
|
+
return item.key === "snapshots"
|
|
107
|
+
? `${item.data.id.slice(0, 8)} ${g(`${item.data.packages} packages`)}`
|
|
108
|
+
: item.key === "task"
|
|
109
|
+
? `${item.data.packageName} ${g(item.data.taskName)}`
|
|
110
|
+
: item.key === "restore"
|
|
111
|
+
? `${item.data.packageName} ${g(item.data.repositoryName)}`
|
|
112
|
+
: "";
|
|
113
|
+
};
|
|
114
|
+
return new DataFormat_1.DataFormat({
|
|
115
|
+
streams: options.streams,
|
|
116
|
+
json: result,
|
|
117
|
+
table: {
|
|
118
|
+
headers: [
|
|
119
|
+
{ value: "", width: 3 },
|
|
120
|
+
{ value: "Title", width: 15 },
|
|
121
|
+
{ value: "Data" },
|
|
122
|
+
{ value: "Duration", width: 10 },
|
|
123
|
+
{ value: "Error", width: 50 },
|
|
124
|
+
],
|
|
125
|
+
rows: () => result.map((item) => [
|
|
126
|
+
(0, cli_1.resultColumn)(item.error),
|
|
127
|
+
renderTitle(item, true),
|
|
128
|
+
renderData(item, true),
|
|
129
|
+
(0, date_1.duration)(item.elapsed),
|
|
130
|
+
(0, cli_1.errorColumn)(item.error, options.verbose),
|
|
131
|
+
]),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
208
134
|
}
|
|
209
|
-
async exec(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
...this.options,
|
|
217
|
-
sourceAction: "restore",
|
|
135
|
+
async exec() {
|
|
136
|
+
const { options } = this;
|
|
137
|
+
const pm = new progress_1.ProgressManager({
|
|
138
|
+
verbose: options.verbose,
|
|
139
|
+
tty: options.tty,
|
|
140
|
+
enabled: options.progress,
|
|
141
|
+
interval: options.progressInterval,
|
|
218
142
|
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
action: "restore",
|
|
143
|
+
const l = new list_1.Listr3({
|
|
144
|
+
streams: options.streams,
|
|
145
|
+
progressManager: pm,
|
|
223
146
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
147
|
+
return l
|
|
148
|
+
.add(l.$task({
|
|
149
|
+
key: "snapshots",
|
|
150
|
+
data: {
|
|
151
|
+
id: "",
|
|
152
|
+
packages: 0,
|
|
153
|
+
},
|
|
154
|
+
title: {
|
|
155
|
+
initial: "Fetch snapshots",
|
|
156
|
+
started: "Fetching snapshots",
|
|
157
|
+
completed: "Snapshots fetched",
|
|
158
|
+
failed: "Snapshot fetch failed",
|
|
159
|
+
},
|
|
160
|
+
run: async (_, data) => {
|
|
161
|
+
const { minFreeDiskSpace } = this.config;
|
|
162
|
+
if (minFreeDiskSpace)
|
|
163
|
+
await (0, temp_1.ensureFreeDiskTempSpace)(minFreeDiskSpace);
|
|
164
|
+
if (!options.snapshotId)
|
|
165
|
+
throw new Error("Snapshot id is required");
|
|
166
|
+
const snapshots = this.groupSnapshots(await this.findSnapshots());
|
|
167
|
+
if (!snapshots.length)
|
|
168
|
+
throw new Error("None snapshot found");
|
|
169
|
+
data.id = options.snapshotId;
|
|
170
|
+
data.packages = snapshots.length;
|
|
171
|
+
return snapshots.map((snapshot) => l.$task({
|
|
172
|
+
key: "restore",
|
|
173
|
+
keyIndex: snapshot.packageName,
|
|
174
|
+
data: snapshot,
|
|
175
|
+
title: {
|
|
176
|
+
initial: `Restore ${snapshot.packageName} snapshot`,
|
|
177
|
+
started: `Restoring ${snapshot.packageName} snapshot`,
|
|
178
|
+
completed: `Snapshot restored: ${snapshot.packageName}`,
|
|
179
|
+
failed: `Snapshot restore failed: ${snapshot.packageName}`,
|
|
180
|
+
},
|
|
181
|
+
exitOnError: false,
|
|
182
|
+
run: async (listTask) => {
|
|
183
|
+
const pkg = (0, config_1.resolvePackage)((0, config_1.findPackageOrFail)(this.config, snapshot.packageName), {
|
|
184
|
+
snapshotId: options.snapshotId,
|
|
185
|
+
snapshotDate: snapshot.date,
|
|
186
|
+
action: "restore",
|
|
187
|
+
});
|
|
188
|
+
const gc = new temp_1.GargabeCollector();
|
|
189
|
+
const task = pkg.task ? (0, TaskFactory_1.createTask)(pkg.task) : undefined;
|
|
190
|
+
const restore = await this.restore({
|
|
191
|
+
gc,
|
|
192
|
+
pkg,
|
|
193
|
+
task,
|
|
194
|
+
snapshot: snapshot,
|
|
195
|
+
onProgress: (p) => pm.update(p, (t) => (listTask.output = t)),
|
|
196
|
+
});
|
|
197
|
+
if (!task)
|
|
198
|
+
return await gc.cleanup();
|
|
199
|
+
return l.$tasks({
|
|
200
|
+
key: "task",
|
|
201
|
+
keyIndex: pkg.name,
|
|
202
|
+
data: { taskName: pkg.task.name, packageName: pkg.name },
|
|
203
|
+
title: {
|
|
204
|
+
initial: `Execute ${pkg.task?.name} task`,
|
|
205
|
+
started: `Executing ${pkg.task?.name} task`,
|
|
206
|
+
completed: `Task executed: ${pkg.task?.name}`,
|
|
207
|
+
failed: `Task execute failed: ${pkg.task?.name}`,
|
|
208
|
+
},
|
|
209
|
+
exitOnError: false,
|
|
210
|
+
runWrapper: gc.cleanup.bind(gc),
|
|
211
|
+
run: async (listTask) => {
|
|
212
|
+
const { snapshotPath } = restore;
|
|
213
|
+
(0, assert_1.ok)(snapshotPath);
|
|
214
|
+
await task.restore({
|
|
215
|
+
package: pkg,
|
|
216
|
+
options,
|
|
217
|
+
snapshot,
|
|
218
|
+
snapshotPath,
|
|
219
|
+
onProgress: (p) => pm.update(p, (t) => (listTask.output = t)),
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
}));
|
|
225
|
+
},
|
|
226
|
+
}))
|
|
227
|
+
.exec();
|
|
265
228
|
}
|
|
266
229
|
}
|
|
267
230
|
exports.RestoreAction = RestoreAction;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ConfigType } from "../Config/Config";
|
|
2
2
|
import { RepositoryConfigEnabledActionType } from "../Config/RepositoryConfig";
|
|
3
|
-
import {
|
|
3
|
+
import { Snapshot } from "../Repository/RepositoryAbstract";
|
|
4
4
|
import { IfRequireKeys } from "../utils/ts";
|
|
5
|
-
export type SnapshotGroupByType = keyof Pick<
|
|
6
|
-
export type
|
|
5
|
+
export type SnapshotGroupByType = keyof Pick<ExtendedSnapshot, "packageName" | "repositoryName" | "repositoryType">;
|
|
6
|
+
export type SnapshotsActionOptions = {
|
|
7
7
|
ids?: string[];
|
|
8
8
|
repositoryNames?: string[];
|
|
9
9
|
packageNames?: string[];
|
|
@@ -21,14 +21,14 @@ export type SnapshotsActionOptionsType = {
|
|
|
21
21
|
lastYearly?: number;
|
|
22
22
|
groupBy?: SnapshotGroupByType[];
|
|
23
23
|
};
|
|
24
|
-
export type
|
|
24
|
+
export type ExtendedSnapshot = {
|
|
25
25
|
shortId: string;
|
|
26
26
|
repositoryName: string;
|
|
27
27
|
repositoryType: string;
|
|
28
|
-
} &
|
|
28
|
+
} & Snapshot;
|
|
29
29
|
export declare class SnapshotsAction<TRequired extends boolean = true> {
|
|
30
30
|
readonly config: ConfigType;
|
|
31
|
-
readonly options: IfRequireKeys<TRequired,
|
|
32
|
-
constructor(config: ConfigType, options: IfRequireKeys<TRequired,
|
|
33
|
-
exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<
|
|
31
|
+
readonly options: IfRequireKeys<TRequired, SnapshotsActionOptions>;
|
|
32
|
+
constructor(config: ConfigType, options: IfRequireKeys<TRequired, SnapshotsActionOptions>);
|
|
33
|
+
exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<ExtendedSnapshot[]>;
|
|
34
34
|
}
|
|
@@ -15,21 +15,21 @@ class SnapshotsAction {
|
|
|
15
15
|
if (!sourceAction)
|
|
16
16
|
sourceAction = "snapshots";
|
|
17
17
|
let result = [];
|
|
18
|
-
for (const
|
|
19
|
-
if (!(0, config_1.filterRepository)(
|
|
18
|
+
for (const repoConfig of this.config.repositories) {
|
|
19
|
+
if (!(0, config_1.filterRepository)(repoConfig, sourceAction))
|
|
20
20
|
continue;
|
|
21
21
|
if (this.options.repositoryNames &&
|
|
22
|
-
!this.options.repositoryNames.includes(
|
|
22
|
+
!this.options.repositoryNames.includes(repoConfig.name))
|
|
23
23
|
continue;
|
|
24
24
|
if (this.options.repositoryTypes &&
|
|
25
|
-
!this.options.repositoryTypes.includes(
|
|
25
|
+
!this.options.repositoryTypes.includes(repoConfig.type))
|
|
26
26
|
continue;
|
|
27
|
-
const
|
|
27
|
+
const repo = (0, RepositoryFactory_1.createRepo)(repoConfig);
|
|
28
28
|
const configPackageNames = this.config.packages.map((pkg) => pkg.name);
|
|
29
29
|
const packageNames = this.options.packageConfig
|
|
30
30
|
? this.options.packageNames?.filter((name) => configPackageNames.includes(name)) || configPackageNames
|
|
31
31
|
: this.options.packageNames;
|
|
32
|
-
const snapshots = await
|
|
32
|
+
const snapshots = await repo.fetchSnapshots({
|
|
33
33
|
options: {
|
|
34
34
|
...this.options,
|
|
35
35
|
packageNames,
|
|
@@ -38,8 +38,8 @@ class SnapshotsAction {
|
|
|
38
38
|
const extentedItems = snapshots.map((ss) => ({
|
|
39
39
|
...ss,
|
|
40
40
|
shortId: ss.id.slice(0, 8),
|
|
41
|
-
repositoryName:
|
|
42
|
-
repositoryType:
|
|
41
|
+
repositoryName: repoConfig.name,
|
|
42
|
+
repositoryType: repoConfig.type,
|
|
43
43
|
}));
|
|
44
44
|
result.push(...extentedItems);
|
|
45
45
|
}
|