@datatruck/cli 0.32.3 → 0.34.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/config.schema.json +377 -31
- package/lib/{Action → actions}/BackupAction.d.ts +13 -19
- package/lib/{Action → actions}/BackupAction.js +52 -91
- package/lib/{Action → actions}/ConfigAction.d.ts +4 -2
- package/lib/{Action → actions}/ConfigAction.js +16 -8
- package/lib/{Action → actions}/CopyAction.d.ts +20 -13
- package/lib/actions/CopyAction.js +296 -0
- package/lib/{Action → actions}/InitAction.d.ts +1 -1
- package/lib/{Action → actions}/InitAction.js +3 -3
- package/lib/{Action → actions}/PruneAction.d.ts +1 -2
- package/lib/{Action → actions}/PruneAction.js +2 -2
- package/lib/{Action → actions}/RestoreAction.d.ts +4 -13
- package/lib/{Action → actions}/RestoreAction.js +17 -17
- package/lib/{Action → actions}/SnapshotsAction.d.ts +2 -3
- package/lib/{Action → actions}/SnapshotsAction.js +3 -3
- package/lib/cli.d.ts +3 -3
- package/lib/cli.js +18 -17
- package/lib/commands/BackupCommand.d.ts +45 -0
- package/lib/{Command → commands}/BackupCommand.js +7 -6
- package/lib/{Command → commands}/CleanCacheCommand.d.ts +4 -2
- package/lib/{Command → commands}/CleanCacheCommand.js +6 -5
- package/lib/{Command → commands}/CommandAbstract.d.ts +10 -6
- package/lib/{Command → commands}/CommandAbstract.js +5 -3
- package/lib/commands/ConfigCommand.d.ts +22 -0
- package/lib/{Command → commands}/ConfigCommand.js +5 -5
- package/lib/commands/CopyCommand.d.ts +17 -0
- package/lib/{Command → commands}/CopyCommand.js +7 -6
- package/lib/commands/InitCommand.d.ts +19 -0
- package/lib/{Command → commands}/InitCommand.js +9 -9
- package/lib/{Command → commands}/PruneCommand.d.ts +7 -4
- package/lib/{Command → commands}/PruneCommand.js +11 -11
- package/lib/commands/RestoreCommand.d.ts +38 -0
- package/lib/{Command → commands}/RestoreCommand.js +7 -6
- package/lib/{Command → commands}/SnapshotsCommand.d.ts +8 -6
- package/lib/{Command → commands}/SnapshotsCommand.js +12 -12
- package/lib/{Command → commands}/StartServerCommand.d.ts +4 -2
- package/lib/{Command → commands}/StartServerCommand.js +5 -5
- package/lib/index.d.ts +20 -23
- package/lib/index.js +8 -8
- package/lib/{Repository → repositories}/DatatruckRepository.d.ts +6 -2
- package/lib/{Repository → repositories}/DatatruckRepository.js +13 -5
- package/lib/{Repository → repositories}/GitRepository.d.ts +6 -2
- package/lib/{Repository → repositories}/GitRepository.js +8 -3
- package/lib/{Repository → repositories}/RepositoryAbstract.d.ts +13 -9
- package/lib/{Repository → repositories}/ResticRepository.d.ts +6 -2
- package/lib/{Repository → repositories}/ResticRepository.js +17 -10
- package/lib/{Task → tasks}/MssqlTask.js +2 -2
- package/lib/{Task → tasks}/MysqlDumpTask.js +4 -4
- package/lib/{Task → tasks}/ScriptTask.d.ts +2 -2
- package/lib/{Task → tasks}/SqlDumpTaskAbstract.js +4 -4
- package/lib/{Task → tasks}/TaskAbstract.d.ts +4 -4
- package/lib/utils/DataFormat.js +3 -3
- package/lib/utils/Restic.d.ts +2 -2
- package/lib/utils/Restic.js +12 -10
- package/lib/utils/cli.d.ts +9 -3
- package/lib/utils/cli.js +17 -1
- package/lib/utils/cron.d.ts +11 -0
- package/lib/utils/cron.js +27 -0
- package/lib/utils/datatruck/client.d.ts +3 -1
- package/lib/utils/datatruck/client.js +1 -1
- package/lib/utils/datatruck/command.d.ts +29 -0
- package/lib/utils/datatruck/command.js +61 -0
- package/lib/{Config/RepositoryConfig.d.ts → utils/datatruck/config-repository-type.d.ts} +19 -8
- package/lib/{Config/TaskConfig.d.ts → utils/datatruck/config-task-type.d.ts} +6 -6
- package/lib/utils/datatruck/config-type.d.ts +51 -0
- package/lib/utils/datatruck/config.d.ts +19 -10
- package/lib/utils/datatruck/config.js +43 -7
- package/lib/utils/datatruck/cron-server.d.ts +27 -6
- package/lib/utils/datatruck/cron-server.js +38 -20
- package/lib/utils/datatruck/paths.d.ts +2 -2
- package/lib/utils/datatruck/report-list.d.ts +14 -0
- package/lib/utils/datatruck/report-list.js +57 -0
- package/lib/utils/datatruck/repository-server.js +3 -2
- package/lib/utils/datatruck/repository.d.ts +16 -0
- package/lib/utils/datatruck/repository.js +30 -0
- package/lib/utils/datatruck/snapshot.d.ts +2 -2
- package/lib/utils/datatruck/task.d.ts +3 -0
- package/lib/{Factory/TaskFactory.js → utils/datatruck/task.js} +8 -8
- package/lib/utils/date.js +6 -2
- package/lib/utils/fs.d.ts +3 -0
- package/lib/utils/fs.js +24 -4
- package/lib/utils/http.d.ts +3 -1
- package/lib/utils/http.js +6 -1
- package/lib/utils/list.d.ts +5 -5
- package/lib/utils/mysql.js +5 -5
- package/lib/utils/object.d.ts +13 -0
- package/lib/utils/object.js +32 -1
- package/lib/utils/process.js +4 -1
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +7 -3
- package/lib/utils/ts.d.ts +16 -0
- package/lib/utils/virtual-fs.d.ts +6 -2
- package/lib/utils/virtual-fs.js +4 -1
- package/lib/utils/watcher.d.ts +10 -0
- package/lib/utils/watcher.js +34 -0
- package/package.json +4 -4
- package/lib/Action/CopyAction.js +0 -164
- package/lib/Command/BackupCommand.d.ts +0 -19
- package/lib/Command/ConfigCommand.d.ts +0 -15
- package/lib/Command/CopyCommand.d.ts +0 -16
- package/lib/Command/InitCommand.d.ts +0 -13
- package/lib/Command/RestoreCommand.d.ts +0 -17
- package/lib/Config/Config.d.ts +0 -28
- package/lib/Config/PackageConfig.d.ts +0 -24
- package/lib/Config/PackageRepositoryConfig.d.ts +0 -15
- package/lib/Config/PrunePolicyConfig.d.ts +0 -2
- package/lib/Config/RepositoryConfig.js +0 -2
- package/lib/Config/TaskConfig.js +0 -2
- package/lib/Factory/CommandFactory.d.ts +0 -45
- package/lib/Factory/CommandFactory.js +0 -96
- package/lib/Factory/RepositoryFactory.d.ts +0 -3
- package/lib/Factory/RepositoryFactory.js +0 -23
- package/lib/Factory/TaskFactory.d.ts +0 -3
- /package/lib/{Action → actions}/CleanCacheAction.d.ts +0 -0
- /package/lib/{Action → actions}/CleanCacheAction.js +0 -0
- /package/lib/{Repository → repositories}/RepositoryAbstract.js +0 -0
- /package/lib/{Task → tasks}/GitTask.d.ts +0 -0
- /package/lib/{Task → tasks}/GitTask.js +0 -0
- /package/lib/{Task → tasks}/MariadbTask.d.ts +0 -0
- /package/lib/{Task → tasks}/MariadbTask.js +0 -0
- /package/lib/{Task → tasks}/MssqlTask.d.ts +0 -0
- /package/lib/{Task → tasks}/MysqlDumpTask.d.ts +0 -0
- /package/lib/{Task → tasks}/PostgresqlDumpTask.d.ts +0 -0
- /package/lib/{Task → tasks}/PostgresqlDumpTask.js +0 -0
- /package/lib/{Task → tasks}/ScriptTask.js +0 -0
- /package/lib/{Task → tasks}/SqlDumpTaskAbstract.d.ts +0 -0
- /package/lib/{Task → tasks}/TaskAbstract.js +0 -0
- /package/lib/{Config/Config.js → utils/datatruck/config-repository-type.js} +0 -0
- /package/lib/{Config/PackageConfig.js → utils/datatruck/config-task-type.js} +0 -0
- /package/lib/{Config/PackageRepositoryConfig.js → utils/datatruck/config-type.js} +0 -0
- /package/lib/{Error/AppError.d.ts → utils/datatruck/error.d.ts} +0 -0
- /package/lib/{Error/AppError.js → utils/datatruck/error.js} +0 -0
- /package/lib/{Config/PrunePolicyConfig.js → utils/ts.js} +0 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
3
|
+
if (value !== null && value !== void 0) {
|
|
4
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
5
|
+
var dispose;
|
|
6
|
+
if (async) {
|
|
7
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8
|
+
dispose = value[Symbol.asyncDispose];
|
|
9
|
+
}
|
|
10
|
+
if (dispose === void 0) {
|
|
11
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
12
|
+
dispose = value[Symbol.dispose];
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
16
|
+
}
|
|
17
|
+
else if (async) {
|
|
18
|
+
env.stack.push({ async: true });
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
23
|
+
return function (env) {
|
|
24
|
+
function fail(e) {
|
|
25
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
26
|
+
env.hasError = true;
|
|
27
|
+
}
|
|
28
|
+
function next() {
|
|
29
|
+
while (env.stack.length) {
|
|
30
|
+
var rec = env.stack.pop();
|
|
31
|
+
try {
|
|
32
|
+
var result = rec.dispose && rec.dispose.call(rec.value);
|
|
33
|
+
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
fail(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (env.hasError) throw env.error;
|
|
40
|
+
}
|
|
41
|
+
return next();
|
|
42
|
+
};
|
|
43
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
});
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.CopyAction = void 0;
|
|
52
|
+
const DataFormat_1 = require("../utils/DataFormat");
|
|
53
|
+
const bytes_1 = require("../utils/bytes");
|
|
54
|
+
const cli_1 = require("../utils/cli");
|
|
55
|
+
const config_1 = require("../utils/datatruck/config");
|
|
56
|
+
const report_list_1 = require("../utils/datatruck/report-list");
|
|
57
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
58
|
+
const snapshot_1 = require("../utils/datatruck/snapshot");
|
|
59
|
+
const date_1 = require("../utils/date");
|
|
60
|
+
const list_1 = require("../utils/list");
|
|
61
|
+
const object_1 = require("../utils/object");
|
|
62
|
+
const progress_1 = require("../utils/progress");
|
|
63
|
+
const temp_1 = require("../utils/temp");
|
|
64
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
65
|
+
const os_1 = require("os");
|
|
66
|
+
class CopyAction {
|
|
67
|
+
config;
|
|
68
|
+
options;
|
|
69
|
+
constructor(config, options) {
|
|
70
|
+
this.config = config;
|
|
71
|
+
this.options = options;
|
|
72
|
+
}
|
|
73
|
+
dataFormat(result, options = {}) {
|
|
74
|
+
const renderTitle = (item, color) => {
|
|
75
|
+
let title = item.key.slice(0, 1).toUpperCase() + item.key.slice(1);
|
|
76
|
+
return item.key === "copy" && color ? chalk_1.default.cyan(title) : title;
|
|
77
|
+
};
|
|
78
|
+
const renderData = (item, color, items = []) => {
|
|
79
|
+
const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
|
|
80
|
+
return (0, cli_1.renderListTaskItem)(item, color, {
|
|
81
|
+
snapshots: (data) => data.snapshots.length,
|
|
82
|
+
copy: (data) => [
|
|
83
|
+
data.packageName,
|
|
84
|
+
g([
|
|
85
|
+
data.snapshotId.slice(0, 8),
|
|
86
|
+
data.mirrorRepositoryName,
|
|
87
|
+
(0, bytes_1.formatBytes)(data.bytes),
|
|
88
|
+
].join(" ")),
|
|
89
|
+
],
|
|
90
|
+
report: (data) => data.type,
|
|
91
|
+
summary: (data) => ({
|
|
92
|
+
errors: data.errors,
|
|
93
|
+
copied: items.filter((i) => i.key === "copy" && !i.error && !i.data.skipped).length,
|
|
94
|
+
skipped: items.filter((i) => i.key === "copy" && !i.error && i.data.skipped).length,
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return new DataFormat_1.DataFormat({
|
|
99
|
+
streams: options.streams,
|
|
100
|
+
json: result,
|
|
101
|
+
table: {
|
|
102
|
+
headers: [
|
|
103
|
+
{ value: "", width: 3 },
|
|
104
|
+
{ value: "Title", width: 15 },
|
|
105
|
+
{ value: "Data" },
|
|
106
|
+
{ value: "Duration", width: 10 },
|
|
107
|
+
{ value: "Error", width: 50 },
|
|
108
|
+
],
|
|
109
|
+
rows: () => result.map((item) => [
|
|
110
|
+
(0, cli_1.renderResult)(item.error),
|
|
111
|
+
renderTitle(item, true),
|
|
112
|
+
renderData(item, true, result),
|
|
113
|
+
(0, date_1.duration)(item.elapsed),
|
|
114
|
+
(0, cli_1.renderError)(item.error, options.verbose),
|
|
115
|
+
]),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async fetchSnapshots(repo) {
|
|
120
|
+
const snapshots = await repo.fetchSnapshots({
|
|
121
|
+
options: {
|
|
122
|
+
ids: this.options.ids,
|
|
123
|
+
packageNames: this.options.packageNames,
|
|
124
|
+
packageTaskNames: this.options.packageTaskNames,
|
|
125
|
+
verbose: this.options.verbose,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const result = this.options.last
|
|
129
|
+
? (0, snapshot_1.groupAndFilter)(snapshots, ["packageName"], {
|
|
130
|
+
last: this.options.last,
|
|
131
|
+
}).map(({ item }) => item)
|
|
132
|
+
: snapshots;
|
|
133
|
+
if (!result.length)
|
|
134
|
+
throw new Error("No snapshots found");
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
createSourceRepoMap() {
|
|
138
|
+
return new object_1.StrictMap(([snapshot, config]) => [config.type, snapshot.id, snapshot.packageName].join("|"));
|
|
139
|
+
}
|
|
140
|
+
async copyCrossRepository(options) {
|
|
141
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
142
|
+
try {
|
|
143
|
+
const { repo, repoConfig, mirrorRepo, mirrorConfig, snapshot } = options;
|
|
144
|
+
const tmp = __addDisposableResource(env_1, await (0, temp_1.useTempDir)("copy", "restore"), true);
|
|
145
|
+
const pkg = (0, config_1.findPackageOrFail)(this.config, snapshot.packageName);
|
|
146
|
+
await repo.restore({
|
|
147
|
+
options: {
|
|
148
|
+
verbose: this.options.verbose,
|
|
149
|
+
snapshotId: snapshot.id,
|
|
150
|
+
},
|
|
151
|
+
snapshot: { id: snapshot.id, date: snapshot.date },
|
|
152
|
+
package: { name: snapshot.packageName },
|
|
153
|
+
packageConfig: (0, config_1.findPackageRepositoryConfig)(pkg, repoConfig),
|
|
154
|
+
snapshotPath: tmp.path,
|
|
155
|
+
onProgress: options.onProgress,
|
|
156
|
+
});
|
|
157
|
+
if (this.config.minFreeDiskSpace)
|
|
158
|
+
await mirrorRepo.ensureFreeDiskSpace(mirrorConfig.config, this.config.minFreeDiskSpace);
|
|
159
|
+
return await mirrorRepo.backup({
|
|
160
|
+
options: {
|
|
161
|
+
verbose: this.options.verbose,
|
|
162
|
+
tags: snapshot.tags,
|
|
163
|
+
},
|
|
164
|
+
snapshot: { id: snapshot.id, date: snapshot.date },
|
|
165
|
+
package: {
|
|
166
|
+
name: snapshot.packageName,
|
|
167
|
+
path: tmp.path,
|
|
168
|
+
},
|
|
169
|
+
packageConfig: (0, config_1.findPackageRepositoryConfig)(pkg, mirrorConfig),
|
|
170
|
+
onProgress: options.onProgress,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (e_1) {
|
|
174
|
+
env_1.error = e_1;
|
|
175
|
+
env_1.hasError = true;
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
const result_1 = __disposeResources(env_1);
|
|
179
|
+
if (result_1)
|
|
180
|
+
await result_1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async exec() {
|
|
184
|
+
const { options } = this;
|
|
185
|
+
const pm = new progress_1.ProgressManager({
|
|
186
|
+
verbose: options.verbose,
|
|
187
|
+
tty: options.tty,
|
|
188
|
+
mode: options.progress,
|
|
189
|
+
});
|
|
190
|
+
const l = new list_1.Listr3({ progressManager: pm });
|
|
191
|
+
return l
|
|
192
|
+
.add([
|
|
193
|
+
l.$task({
|
|
194
|
+
key: "snapshots",
|
|
195
|
+
data: { snapshots: [] },
|
|
196
|
+
title: {
|
|
197
|
+
initial: "Fetch snapshots",
|
|
198
|
+
started: "Fetching snapshots",
|
|
199
|
+
completed: "Snapshots fetched",
|
|
200
|
+
failed: "Snapshot fetch failed",
|
|
201
|
+
},
|
|
202
|
+
run: async (task, data) => {
|
|
203
|
+
if (this.config.minFreeDiskSpace)
|
|
204
|
+
await (0, temp_1.ensureFreeDiskTempSpace)(this.config.minFreeDiskSpace);
|
|
205
|
+
const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, this.options.repositoryName);
|
|
206
|
+
const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
|
|
207
|
+
data.snapshots = await this.fetchSnapshots(repo);
|
|
208
|
+
task.title = `Snapshots fetched: ${data.snapshots.length}`;
|
|
209
|
+
const repositoryNames2 = (0, config_1.sortReposByType)((0, config_1.filterRepository)(this.config.repositories, {
|
|
210
|
+
include: this.options.repositoryNames2,
|
|
211
|
+
exclude: [repoConfig.name],
|
|
212
|
+
action: "backup",
|
|
213
|
+
}), [repoConfig.type]);
|
|
214
|
+
if (!repositoryNames2.length)
|
|
215
|
+
throw new Error("No mirror snapshots found");
|
|
216
|
+
const sourceRepoMap = this.createSourceRepoMap();
|
|
217
|
+
return data.snapshots.flatMap((snapshot) => repositoryNames2.map((repo2) => {
|
|
218
|
+
const id = snapshot.id.slice(0, 8);
|
|
219
|
+
const pkgName = snapshot.packageName;
|
|
220
|
+
return l.$task({
|
|
221
|
+
key: "copy",
|
|
222
|
+
keyIndex: [snapshot.packageName, repo2.name, snapshot.id],
|
|
223
|
+
data: {
|
|
224
|
+
snapshotId: snapshot.id,
|
|
225
|
+
packageName: snapshot.packageName,
|
|
226
|
+
repositoryName: repoConfig.name,
|
|
227
|
+
mirrorRepositoryName: repo2.name,
|
|
228
|
+
bytes: 0,
|
|
229
|
+
skipped: false,
|
|
230
|
+
},
|
|
231
|
+
title: {
|
|
232
|
+
initial: `Copy snapshot: ${pkgName} (${id}) » ${repo2.name}`,
|
|
233
|
+
started: `Copying snapshot: ${pkgName} (${id}) » ${repo2.name}`,
|
|
234
|
+
completed: `Snapshot copied: ${pkgName} (${id}) » ${repo2.name}`,
|
|
235
|
+
failed: `Snapshot copy failed: ${pkgName} (${id}) » ${repo2.name}`,
|
|
236
|
+
},
|
|
237
|
+
exitOnError: false,
|
|
238
|
+
run: async (task, data) => {
|
|
239
|
+
const mirrorConfig = (0, config_1.findRepositoryOrFail)(this.config, repo2.name);
|
|
240
|
+
const mirrorRepo = await (0, repository_1.createAndInitRepo)(mirrorConfig, this.options.verbose);
|
|
241
|
+
const currentCopies = await mirrorRepo.fetchSnapshots({
|
|
242
|
+
options: {
|
|
243
|
+
ids: [snapshot.id],
|
|
244
|
+
packageNames: [snapshot.packageName],
|
|
245
|
+
verbose: this.options.verbose,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
if (currentCopies.length) {
|
|
249
|
+
data.skipped = true;
|
|
250
|
+
return task.skip(`Already exists at ${mirrorConfig.name}: ${pkgName} (${id})`);
|
|
251
|
+
}
|
|
252
|
+
if (this.config.minFreeDiskSpace)
|
|
253
|
+
await mirrorRepo.ensureFreeDiskSpace(mirrorConfig.config, this.config.minFreeDiskSpace);
|
|
254
|
+
const sourceRepo = sourceRepoMap.with([
|
|
255
|
+
snapshot,
|
|
256
|
+
mirrorConfig,
|
|
257
|
+
]);
|
|
258
|
+
if (sourceRepo.has()) {
|
|
259
|
+
const copy = await sourceRepo.get().copy({
|
|
260
|
+
mirrorRepositoryConfig: mirrorConfig.config,
|
|
261
|
+
options: { verbose: this.options.verbose },
|
|
262
|
+
package: { name: snapshot.packageName },
|
|
263
|
+
snapshot,
|
|
264
|
+
onProgress: (p) => pm.update(p, (d) => (task.output = d)),
|
|
265
|
+
});
|
|
266
|
+
data.bytes = copy.bytes;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
const copy = await this.copyCrossRepository({
|
|
270
|
+
mirrorConfig,
|
|
271
|
+
mirrorRepo,
|
|
272
|
+
repo,
|
|
273
|
+
repoConfig,
|
|
274
|
+
snapshot,
|
|
275
|
+
onProgress: (p) => pm.update(p, (d) => (task.output = d)),
|
|
276
|
+
});
|
|
277
|
+
data.bytes = copy.bytes;
|
|
278
|
+
sourceRepo.set(mirrorRepo);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
}));
|
|
283
|
+
},
|
|
284
|
+
}),
|
|
285
|
+
...(0, report_list_1.createReportListTasks)(l, {
|
|
286
|
+
hostname: this.config.hostname ?? (0, os_1.hostname)(),
|
|
287
|
+
action: "copy",
|
|
288
|
+
reports: this.config.reports || [],
|
|
289
|
+
verbose: this.options.verbose,
|
|
290
|
+
onMessage: (result, report) => this.dataFormat(result).format(report.format ?? "list"),
|
|
291
|
+
}),
|
|
292
|
+
])
|
|
293
|
+
.exec();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.CopyAction = CopyAction;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitAction = void 0;
|
|
4
|
-
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
4
|
const config_1 = require("../utils/datatruck/config");
|
|
5
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
6
6
|
class InitAction {
|
|
7
7
|
config;
|
|
8
8
|
options;
|
|
@@ -13,7 +13,7 @@ class InitAction {
|
|
|
13
13
|
async exec() {
|
|
14
14
|
const result = [];
|
|
15
15
|
for (const repoConfig of this.config.repositories) {
|
|
16
|
-
if (!(0, config_1.
|
|
16
|
+
if (!(0, config_1.filterRepositoryByEnabled)(repoConfig, "init"))
|
|
17
17
|
continue;
|
|
18
18
|
if (this.options.repositoryNames &&
|
|
19
19
|
!this.options.repositoryNames.includes(repoConfig.name))
|
|
@@ -21,7 +21,7 @@ class InitAction {
|
|
|
21
21
|
if (this.options.repositoryTypes &&
|
|
22
22
|
!this.options.repositoryTypes.includes(repoConfig.type))
|
|
23
23
|
continue;
|
|
24
|
-
const repo = (0,
|
|
24
|
+
const repo = (0, repository_1.createRepo)(repoConfig);
|
|
25
25
|
let initError = null;
|
|
26
26
|
try {
|
|
27
27
|
await repo.init({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Config } from "../
|
|
2
|
-
import { RepositoryConfig } from "../Config/RepositoryConfig";
|
|
1
|
+
import type { Config, RepositoryConfig } from "../utils/datatruck/config-type";
|
|
3
2
|
import { KeepObject } from "../utils/date";
|
|
4
3
|
import { IfRequireKeys } from "../utils/ts";
|
|
5
4
|
import { ExtendedSnapshot, SnapshotsActionOptions } from "./SnapshotsAction";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PruneAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
5
5
|
const snapshot_1 = require("../utils/datatruck/snapshot");
|
|
6
6
|
const date_1 = require("../utils/date");
|
|
7
7
|
const object_1 = require("../utils/object");
|
|
@@ -17,7 +17,7 @@ class PruneAction {
|
|
|
17
17
|
const repository = (0, object_1.groupBy)(this.config.repositories, "name", true);
|
|
18
18
|
for (const snapshot of snapshots) {
|
|
19
19
|
if (!snapshot.exclusionReasons?.length) {
|
|
20
|
-
const repo = (0,
|
|
20
|
+
const repo = await (0, repository_1.createAndInitRepo)(repository[snapshot.repositoryName], this.options.verbose);
|
|
21
21
|
await repo.prune({
|
|
22
22
|
snapshot: snapshot,
|
|
23
23
|
options: { verbose: this.options.verbose },
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { Snapshot } from "../Repository/RepositoryAbstract";
|
|
4
|
-
import { TaskAbstract } from "../Task/TaskAbstract";
|
|
1
|
+
import { Snapshot } from "../repositories/RepositoryAbstract";
|
|
2
|
+
import { TaskAbstract } from "../tasks/TaskAbstract";
|
|
5
3
|
import { DataFormat } from "../utils/DataFormat";
|
|
4
|
+
import type { Config, PackageConfig } from "../utils/datatruck/config-type";
|
|
6
5
|
import { Listr3TaskResultEnd } from "../utils/list";
|
|
7
6
|
import { Progress, ProgressMode } from "../utils/progress";
|
|
8
7
|
import { Streams } from "../utils/stream";
|
|
@@ -57,14 +56,6 @@ export declare class RestoreAction<TRequired extends boolean = true> {
|
|
|
57
56
|
streams?: Streams;
|
|
58
57
|
verbose?: number;
|
|
59
58
|
}): DataFormat;
|
|
60
|
-
exec(): Promise<(
|
|
61
|
-
key: "summary";
|
|
62
|
-
keyIndex?: string | undefined;
|
|
63
|
-
data: {
|
|
64
|
-
errors: number;
|
|
65
|
-
};
|
|
66
|
-
elapsed: number;
|
|
67
|
-
error?: Error | undefined;
|
|
68
|
-
} | import("../utils/list").Listr3TaskResult<Context>)[]>;
|
|
59
|
+
exec(): Promise<(import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<Context>)[]>;
|
|
69
60
|
}
|
|
70
61
|
export {};
|
|
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RestoreAction = void 0;
|
|
7
|
-
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
8
|
-
const TaskFactory_1 = require("../Factory/TaskFactory");
|
|
9
7
|
const DataFormat_1 = require("../utils/DataFormat");
|
|
10
8
|
const cli_1 = require("../utils/cli");
|
|
11
9
|
const config_1 = require("../utils/datatruck/config");
|
|
10
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
11
|
+
const task_1 = require("../utils/datatruck/task");
|
|
12
12
|
const date_1 = require("../utils/date");
|
|
13
13
|
const fs_1 = require("../utils/fs");
|
|
14
14
|
const list_1 = require("../utils/list");
|
|
@@ -68,7 +68,7 @@ class RestoreAction {
|
|
|
68
68
|
async restore(data) {
|
|
69
69
|
let { snapshot, pkg, task } = data;
|
|
70
70
|
const repoConfig = (0, config_1.findRepositoryOrFail)(this.config, snapshot.repositoryName);
|
|
71
|
-
const repo = (0,
|
|
71
|
+
const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
|
|
72
72
|
if (this.options.initial)
|
|
73
73
|
pkg = { ...pkg, restorePath: pkg.path };
|
|
74
74
|
let snapshotPath = pkg.restorePath ?? pkg.path;
|
|
@@ -103,19 +103,19 @@ class RestoreAction {
|
|
|
103
103
|
};
|
|
104
104
|
const renderData = (item, color, result = []) => {
|
|
105
105
|
const g = (v) => (color ? `${chalk_1.default.gray(`(${v})`)}` : `(${v})`);
|
|
106
|
-
return item
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
return (0, cli_1.renderListTaskItem)(item, color, {
|
|
107
|
+
snapshots: (data) => [
|
|
108
|
+
data.id.slice(0, 8),
|
|
109
|
+
g(`${data.packages} packages`),
|
|
110
|
+
],
|
|
111
|
+
task: (data) => [data.packageName, g(data.taskName)],
|
|
112
|
+
restore: (data) => [data.packageName, g(data.repositoryName)],
|
|
113
|
+
summary: (data) => ({
|
|
114
|
+
errors: data.errors,
|
|
115
|
+
restores: result.filter((r) => !r.error && r.key === "restore")
|
|
116
|
+
.length,
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
119
|
};
|
|
120
120
|
return new DataFormat_1.DataFormat({
|
|
121
121
|
streams: options.streams,
|
|
@@ -191,7 +191,7 @@ class RestoreAction {
|
|
|
191
191
|
action: "restore",
|
|
192
192
|
});
|
|
193
193
|
const gc = new temp_1.GargabeCollector();
|
|
194
|
-
const task = pkg.task ? (0,
|
|
194
|
+
const task = pkg.task ? (0, task_1.createTask)(pkg.task) : undefined;
|
|
195
195
|
const restore = await this.restore({
|
|
196
196
|
gc,
|
|
197
197
|
pkg,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RepositoryConfigEnabledAction } from "../
|
|
3
|
-
import { Snapshot } from "../Repository/RepositoryAbstract";
|
|
1
|
+
import { Snapshot } from "../repositories/RepositoryAbstract";
|
|
2
|
+
import type { Config, RepositoryConfigEnabledAction } from "../utils/datatruck/config-type";
|
|
4
3
|
import { IfRequireKeys } from "../utils/ts";
|
|
5
4
|
export type SnapshotGroupByType = keyof Pick<ExtendedSnapshot, "packageName" | "repositoryName" | "repositoryType">;
|
|
6
5
|
export type SnapshotsActionOptions = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SnapshotsAction = void 0;
|
|
4
|
-
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
4
|
const config_1 = require("../utils/datatruck/config");
|
|
5
|
+
const repository_1 = require("../utils/datatruck/repository");
|
|
6
6
|
const snapshot_1 = require("../utils/datatruck/snapshot");
|
|
7
7
|
class SnapshotsAction {
|
|
8
8
|
config;
|
|
@@ -16,7 +16,7 @@ class SnapshotsAction {
|
|
|
16
16
|
sourceAction = "snapshots";
|
|
17
17
|
let result = [];
|
|
18
18
|
for (const repoConfig of this.config.repositories) {
|
|
19
|
-
if (!(0, config_1.
|
|
19
|
+
if (!(0, config_1.filterRepositoryByEnabled)(repoConfig, sourceAction))
|
|
20
20
|
continue;
|
|
21
21
|
if (this.options.repositoryNames &&
|
|
22
22
|
!this.options.repositoryNames.includes(repoConfig.name))
|
|
@@ -24,7 +24,7 @@ class SnapshotsAction {
|
|
|
24
24
|
if (this.options.repositoryTypes &&
|
|
25
25
|
!this.options.repositoryTypes.includes(repoConfig.type))
|
|
26
26
|
continue;
|
|
27
|
-
const repo = (0,
|
|
27
|
+
const repo = await (0, repository_1.createAndInitRepo)(repoConfig, this.options.verbose);
|
|
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
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function buildArgs<
|
|
1
|
+
import { DatatruckCommandMap, InferDatatruckCommandOptions } from "./utils/datatruck/command";
|
|
2
|
+
export declare function buildArgs<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): any[];
|
|
3
3
|
export declare function parseArgs(args: string[]): void;
|
|
4
|
-
export declare function exec<
|
|
4
|
+
export declare function exec<T extends keyof DatatruckCommandMap>(input: T, options: InferDatatruckCommandOptions<T>): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.exec = exports.parseArgs = exports.buildArgs = void 0;
|
|
7
|
-
const ConfigAction_1 = require("./
|
|
8
|
-
const AppError_1 = require("./Error/AppError");
|
|
9
|
-
const CommandFactory_1 = require("./Factory/CommandFactory");
|
|
7
|
+
const ConfigAction_1 = require("./actions/ConfigAction");
|
|
10
8
|
const globalData_1 = __importDefault(require("./globalData"));
|
|
11
9
|
const cli_1 = require("./utils/cli");
|
|
10
|
+
const command_1 = require("./utils/datatruck/command");
|
|
11
|
+
const error_1 = require("./utils/datatruck/error");
|
|
12
12
|
const exit_1 = require("./utils/exit");
|
|
13
13
|
const fs_1 = require("./utils/fs");
|
|
14
14
|
const string_1 = require("./utils/string");
|
|
@@ -28,8 +28,8 @@ function getGlobalOptions() {
|
|
|
28
28
|
}
|
|
29
29
|
function makeCommand(command) {
|
|
30
30
|
const programCommand = program.command(command);
|
|
31
|
-
const instance = (0,
|
|
32
|
-
const options = instance.
|
|
31
|
+
const instance = (0, command_1.createCommand)(command, getGlobalOptions(), null);
|
|
32
|
+
const options = instance.optionsConfig();
|
|
33
33
|
for (const key in options) {
|
|
34
34
|
const option = options[key];
|
|
35
35
|
const description = `${option.description}${option.defaults ? ` (defaults: ${option.defaults})` : ""}`;
|
|
@@ -56,10 +56,11 @@ function makeCommandAction(command) {
|
|
|
56
56
|
globalData_1.default.tempDir = (0, path_1.isAbsolute)(config.data.tempDir)
|
|
57
57
|
? config.data.tempDir
|
|
58
58
|
: (0, path_1.join)((0, path_1.dirname)(config.path), config.data.tempDir);
|
|
59
|
-
|
|
59
|
+
const response = await (0, command_1.createCommand)(command, {
|
|
60
60
|
...globalOptions,
|
|
61
61
|
config: config.data,
|
|
62
|
-
}, options, {}, globalOptions.config).
|
|
62
|
+
}, options, {}, globalOptions.config).exec();
|
|
63
|
+
exitCode = response.exitCode;
|
|
63
64
|
}
|
|
64
65
|
catch (e) {
|
|
65
66
|
const error = e;
|
|
@@ -67,7 +68,7 @@ function makeCommandAction(command) {
|
|
|
67
68
|
console.error((0, chalk_1.red)(error.stack));
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
70
|
-
if (error instanceof
|
|
71
|
+
if (error instanceof error_1.AppError) {
|
|
71
72
|
console.error((0, chalk_1.red)(error.message));
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
@@ -90,15 +91,15 @@ program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFI
|
|
|
90
91
|
program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
|
|
91
92
|
program.option("--progress <value>", "Progress type (auto, true, false, interval, interval:[ms])", "auto");
|
|
92
93
|
program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
|
|
93
|
-
makeCommand(
|
|
94
|
-
makeCommand(
|
|
95
|
-
makeCommand(
|
|
96
|
-
makeCommand(
|
|
97
|
-
makeCommand(
|
|
98
|
-
makeCommand(
|
|
99
|
-
makeCommand(
|
|
100
|
-
makeCommand(
|
|
101
|
-
makeCommand(
|
|
94
|
+
makeCommand("startServer").alias("start");
|
|
95
|
+
makeCommand("config").alias("c");
|
|
96
|
+
makeCommand("init").alias("i");
|
|
97
|
+
makeCommand("snapshots").alias("s");
|
|
98
|
+
makeCommand("prune").alias("p");
|
|
99
|
+
makeCommand("backup").alias("b");
|
|
100
|
+
makeCommand("restore").alias("r");
|
|
101
|
+
makeCommand("copy").alias("cp");
|
|
102
|
+
makeCommand("cleanCache").alias("cc");
|
|
102
103
|
function buildArgs(input, options) {
|
|
103
104
|
const optionsArray = Object.keys(options).flatMap((name) => [
|
|
104
105
|
`--${(0, string_1.snakeCase)(name, "-")}`,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RepositoryConfig } from "../utils/datatruck/config-type";
|
|
2
|
+
import { If } from "../utils/ts";
|
|
3
|
+
import { CommandAbstract } from "./CommandAbstract";
|
|
4
|
+
export type BackupCommandOptions<TResolved = false> = {
|
|
5
|
+
package?: If<TResolved, string[]>;
|
|
6
|
+
packageTask?: If<TResolved, string[]>;
|
|
7
|
+
repository?: If<TResolved, string[]>;
|
|
8
|
+
repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
|
|
9
|
+
tag?: If<TResolved, string[]>;
|
|
10
|
+
dryRun?: boolean;
|
|
11
|
+
date?: string;
|
|
12
|
+
prune?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare class BackupCommand extends CommandAbstract<BackupCommandOptions<false>, BackupCommandOptions<true>> {
|
|
15
|
+
optionsConfig(): import("../utils/cli").OptionsConfig<BackupCommandOptions<false>, BackupCommandOptions<true>>;
|
|
16
|
+
exec(): Promise<{
|
|
17
|
+
result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
|
|
18
|
+
snapshot: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
task: {
|
|
22
|
+
taskName: string;
|
|
23
|
+
packageName: string;
|
|
24
|
+
};
|
|
25
|
+
backup: {
|
|
26
|
+
packageName: string;
|
|
27
|
+
repositoryName: string;
|
|
28
|
+
bytes: number;
|
|
29
|
+
};
|
|
30
|
+
cleanup: {};
|
|
31
|
+
copy: {
|
|
32
|
+
packageName: string;
|
|
33
|
+
repositoryName: string;
|
|
34
|
+
mirrorRepositoryName: string;
|
|
35
|
+
bytes: number;
|
|
36
|
+
};
|
|
37
|
+
prune: {
|
|
38
|
+
packageName: string;
|
|
39
|
+
total: number;
|
|
40
|
+
pruned: number;
|
|
41
|
+
};
|
|
42
|
+
} & import("../utils/datatruck/report-list").ReportListTaskContext>)[];
|
|
43
|
+
exitCode: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BackupCommand = void 0;
|
|
4
|
-
const BackupAction_1 = require("../
|
|
5
|
-
const ConfigAction_1 = require("../
|
|
4
|
+
const BackupAction_1 = require("../actions/BackupAction");
|
|
5
|
+
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
6
6
|
const string_1 = require("../utils/string");
|
|
7
7
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
8
8
|
class BackupCommand extends CommandAbstract_1.CommandAbstract {
|
|
9
|
-
|
|
10
|
-
return this.
|
|
9
|
+
optionsConfig() {
|
|
10
|
+
return this.castOptionsConfig({
|
|
11
11
|
dryRun: {
|
|
12
12
|
description: "Skip execution",
|
|
13
13
|
option: "--dryRun",
|
|
@@ -47,7 +47,7 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
async
|
|
50
|
+
async exec() {
|
|
51
51
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
52
52
|
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
53
53
|
const backup = new BackupAction_1.BackupAction(config, {
|
|
@@ -69,7 +69,8 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
69
69
|
backup
|
|
70
70
|
.dataFormat(result, { streams: this.streams, verbose })
|
|
71
71
|
.log(this.globalOptions.outputFormat);
|
|
72
|
-
|
|
72
|
+
const exitCode = result.some((item) => item.error) ? 1 : 0;
|
|
73
|
+
return { result, exitCode };
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
exports.BackupCommand = BackupCommand;
|