@datatruck/cli 0.36.0 → 0.36.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/lib/tasks/MysqlDumpTask.js +334 -265
- package/lib/utils/datatruck/cron-server.js +7 -1
- package/lib/utils/mysql.d.ts +1 -0
- package/lib/utils/mysql.js +3 -0
- package/package.json +1 -1
|
@@ -1,4 +1,49 @@
|
|
|
1
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
|
+
});
|
|
2
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
48
|
exports.MysqlDumpTask = exports.mysqlDumpTaskName = void 0;
|
|
4
49
|
const async_1 = require("../utils/async");
|
|
@@ -24,149 +69,161 @@ const suffix = {
|
|
|
24
69
|
};
|
|
25
70
|
class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
26
71
|
async backup(data) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
(0,
|
|
74
|
-
(
|
|
72
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
73
|
+
try {
|
|
74
|
+
const compressAndClean = this.config.compress
|
|
75
|
+
? async (path) => {
|
|
76
|
+
await (0, tar_1.createTar)({
|
|
77
|
+
include: [(0, path_1.relative)(snapshotPath, path)],
|
|
78
|
+
output: `${path}.tar.gz`,
|
|
79
|
+
path: (0, path_1.dirname)(path),
|
|
80
|
+
compress: this.config.compress,
|
|
81
|
+
verbose: data.options.verbose,
|
|
82
|
+
});
|
|
83
|
+
await (0, promises_1.rm)(path);
|
|
84
|
+
}
|
|
85
|
+
: undefined;
|
|
86
|
+
const snapshotPath = data.package.path ??
|
|
87
|
+
(await (0, temp_1.mkTmpDir)(exports.mysqlDumpTaskName, "task", "backup", "snapshot"));
|
|
88
|
+
await (0, fs_1.mkdirIfNotExists)(snapshotPath);
|
|
89
|
+
await (0, fs_1.ensureEmptyDir)(snapshotPath);
|
|
90
|
+
const sql = __addDisposableResource(env_1, await (0, mysql_1.createMysqlCli)({
|
|
91
|
+
...this.config,
|
|
92
|
+
database: undefined,
|
|
93
|
+
verbose: data.options.verbose,
|
|
94
|
+
}), true);
|
|
95
|
+
const tableNames = await sql.fetchTableNames(this.config.database, this.config.includeTables, this.config.excludeTables);
|
|
96
|
+
const concurrency = this.config.concurrency ?? 4;
|
|
97
|
+
const dataFormat = this.config.dataFormat ?? "sql";
|
|
98
|
+
const sharedDir = dataFormat === "csv"
|
|
99
|
+
? await sql.initSharedDir(this.config.csvSharedPath)
|
|
100
|
+
: undefined;
|
|
101
|
+
if (this.config.oneFileByTable || sharedDir) {
|
|
102
|
+
await (0, async_1.runParallel)({
|
|
103
|
+
items: tableNames,
|
|
104
|
+
concurrency,
|
|
105
|
+
onChange: ({ processed: proccesed, buffer }) => data.onProgress({
|
|
106
|
+
relative: {
|
|
107
|
+
description: buffer.size > 1 ? `Exporting (${buffer.size})` : "Exporting",
|
|
108
|
+
payload: [...buffer.keys()].join(", "),
|
|
109
|
+
},
|
|
110
|
+
absolute: {
|
|
111
|
+
total: tableNames.length,
|
|
112
|
+
current: proccesed,
|
|
113
|
+
percent: (0, math_1.progressPercent)(tableNames.length, proccesed),
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
onItem: async ({ item: tableName, index, controller }) => {
|
|
117
|
+
if (sharedDir) {
|
|
118
|
+
const tableSharedPath = (0, path_1.join)(sharedDir, `tmp-dtt-backup-${data.snapshot.id.slice(0, 8)}-${tableName}`);
|
|
119
|
+
if (data.options.verbose) {
|
|
120
|
+
(0, cli_1.logExec)("mkdir", ["-p", tableSharedPath]);
|
|
121
|
+
(0, cli_1.logExec)("chmod", ["777", tableSharedPath]);
|
|
122
|
+
}
|
|
123
|
+
await (0, promises_1.mkdir)(tableSharedPath, { recursive: true });
|
|
124
|
+
try {
|
|
125
|
+
await (0, promises_1.chmod)(tableSharedPath, 0o777);
|
|
126
|
+
await sql.csvDump({
|
|
127
|
+
sharedPath: tableSharedPath,
|
|
128
|
+
items: [tableName],
|
|
129
|
+
database: this.config.database,
|
|
130
|
+
controller,
|
|
131
|
+
});
|
|
132
|
+
const files = await (0, promises_1.readdir)(tableSharedPath);
|
|
133
|
+
const schemaFile = `${tableName}.sql`;
|
|
134
|
+
const dataFile = `${tableName}.txt`;
|
|
135
|
+
const successCsvDump = files.length === 2 &&
|
|
136
|
+
files.every((file) => file === schemaFile || file === dataFile);
|
|
137
|
+
if (!successCsvDump)
|
|
138
|
+
throw new error_1.AppError(`Invalid csv dump files: ${files.join(", ")}`);
|
|
139
|
+
const schemaPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableSchema}`);
|
|
140
|
+
await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, schemaFile), schemaPath);
|
|
141
|
+
await compressAndClean?.(schemaPath);
|
|
142
|
+
const tablePath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableData}`);
|
|
143
|
+
await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, dataFile), tablePath);
|
|
144
|
+
await compressAndClean?.(tablePath);
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
await (0, promises_1.rm)(tableSharedPath, { recursive: true });
|
|
148
|
+
}
|
|
75
149
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await
|
|
79
|
-
|
|
80
|
-
sharedPath: tableSharedPath,
|
|
150
|
+
else {
|
|
151
|
+
const outPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.table}`);
|
|
152
|
+
await sql.dump({
|
|
153
|
+
output: outPath,
|
|
81
154
|
items: [tableName],
|
|
82
155
|
database: this.config.database,
|
|
83
156
|
controller,
|
|
157
|
+
...(concurrency === 1 && {
|
|
158
|
+
onProgress(progress) {
|
|
159
|
+
data.onProgress({
|
|
160
|
+
relative: {
|
|
161
|
+
description: "Exporting",
|
|
162
|
+
payload: tableName,
|
|
163
|
+
current: progress.totalBytes,
|
|
164
|
+
format: "size",
|
|
165
|
+
},
|
|
166
|
+
absolute: {
|
|
167
|
+
total: tableNames.length,
|
|
168
|
+
current: index,
|
|
169
|
+
percent: (0, math_1.progressPercent)(tableNames.length, index),
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
84
174
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const dataFile = `${tableName}.txt`;
|
|
88
|
-
const successCsvDump = files.length === 2 &&
|
|
89
|
-
files.every((file) => file === schemaFile || file === dataFile);
|
|
90
|
-
if (!successCsvDump)
|
|
91
|
-
throw new error_1.AppError(`Invalid csv dump files: ${files.join(", ")}`);
|
|
92
|
-
const schemaPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableSchema}`);
|
|
93
|
-
await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, schemaFile), schemaPath);
|
|
94
|
-
await compressAndClean?.(schemaPath);
|
|
95
|
-
const tablePath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableData}`);
|
|
96
|
-
await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, dataFile), tablePath);
|
|
97
|
-
await compressAndClean?.(tablePath);
|
|
175
|
+
await sql.assertDumpFile(outPath);
|
|
176
|
+
await compressAndClean?.(outPath);
|
|
98
177
|
}
|
|
99
|
-
finally {
|
|
100
|
-
await (0, promises_1.rm)(tableSharedPath, { recursive: true });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
const outPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.table}`);
|
|
105
|
-
await sql.dump({
|
|
106
|
-
output: outPath,
|
|
107
|
-
items: [tableName],
|
|
108
|
-
database: this.config.database,
|
|
109
|
-
controller,
|
|
110
|
-
...(concurrency === 1 && {
|
|
111
|
-
onProgress(progress) {
|
|
112
|
-
data.onProgress({
|
|
113
|
-
relative: {
|
|
114
|
-
description: "Exporting",
|
|
115
|
-
payload: tableName,
|
|
116
|
-
current: progress.totalBytes,
|
|
117
|
-
format: "size",
|
|
118
|
-
},
|
|
119
|
-
absolute: {
|
|
120
|
-
total: tableNames.length,
|
|
121
|
-
current: index,
|
|
122
|
-
percent: (0, math_1.progressPercent)(tableNames.length, index),
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
}),
|
|
127
|
-
});
|
|
128
|
-
await sql.assertDumpFile(outPath);
|
|
129
|
-
await compressAndClean?.(outPath);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
data.onProgress({
|
|
136
|
-
relative: { description: "Exporting" },
|
|
137
|
-
});
|
|
138
|
-
const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.database}`);
|
|
139
|
-
await sql.dump({
|
|
140
|
-
output: outPath,
|
|
141
|
-
items: tableNames,
|
|
142
|
-
database: this.config.database,
|
|
143
|
-
onProgress: (progress) => data.onProgress({
|
|
144
|
-
absolute: {
|
|
145
|
-
description: "Exporting in single file",
|
|
146
|
-
current: progress.totalBytes,
|
|
147
|
-
format: "size",
|
|
148
178
|
},
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
data.onProgress({
|
|
183
|
+
relative: { description: "Exporting" },
|
|
184
|
+
});
|
|
185
|
+
const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.database}`);
|
|
186
|
+
await sql.dump({
|
|
187
|
+
output: outPath,
|
|
188
|
+
items: tableNames,
|
|
189
|
+
database: this.config.database,
|
|
190
|
+
onProgress: (progress) => data.onProgress({
|
|
191
|
+
absolute: {
|
|
192
|
+
description: "Exporting in single file",
|
|
193
|
+
current: progress.totalBytes,
|
|
194
|
+
format: "size",
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
});
|
|
198
|
+
await sql.assertDumpFile(outPath);
|
|
199
|
+
await compressAndClean?.(outPath);
|
|
200
|
+
}
|
|
201
|
+
if (this.config.storedPrograms ?? true) {
|
|
202
|
+
data.onProgress({
|
|
203
|
+
relative: { description: "Exporting stored programs" },
|
|
204
|
+
});
|
|
205
|
+
const outPath = (0, path_1.join)(snapshotPath, `${this.config.database}${suffix.stored}`);
|
|
206
|
+
await sql.dump({
|
|
207
|
+
database: this.config.database,
|
|
208
|
+
output: outPath,
|
|
209
|
+
onlyStoredPrograms: true,
|
|
210
|
+
});
|
|
211
|
+
await sql.assertDumpFile(outPath);
|
|
212
|
+
await compressAndClean?.(outPath);
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
snapshotPath,
|
|
216
|
+
};
|
|
153
217
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
onlyStoredPrograms: true,
|
|
163
|
-
});
|
|
164
|
-
await sql.assertDumpFile(outPath);
|
|
165
|
-
await compressAndClean?.(outPath);
|
|
218
|
+
catch (e_1) {
|
|
219
|
+
env_1.error = e_1;
|
|
220
|
+
env_1.hasError = true;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
const result_1 = __disposeResources(env_1);
|
|
224
|
+
if (result_1)
|
|
225
|
+
await result_1;
|
|
166
226
|
}
|
|
167
|
-
return {
|
|
168
|
-
snapshotPath,
|
|
169
|
-
};
|
|
170
227
|
}
|
|
171
228
|
async prepareRestore(data) {
|
|
172
229
|
return {
|
|
@@ -175,145 +232,157 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
|
175
232
|
};
|
|
176
233
|
}
|
|
177
234
|
async restore(data) {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
database
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
relative: {
|
|
232
|
-
description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
|
|
233
|
-
payload: [...buffer.keys()].join(", "),
|
|
234
|
-
},
|
|
235
|
-
absolute: {
|
|
236
|
-
total: files.length,
|
|
237
|
-
current: processed,
|
|
238
|
-
percent: (0, math_1.progressPercent)(files.length, processed),
|
|
235
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
236
|
+
try {
|
|
237
|
+
const sql = __addDisposableResource(env_2, await (0, mysql_1.createMysqlCli)({
|
|
238
|
+
...this.config,
|
|
239
|
+
database: undefined,
|
|
240
|
+
verbose: data.options.verbose,
|
|
241
|
+
}), true);
|
|
242
|
+
const snapshotPath = data.snapshotPath;
|
|
243
|
+
const params = {
|
|
244
|
+
packageName: data.package.name,
|
|
245
|
+
snapshotId: data.options.snapshotId,
|
|
246
|
+
snapshotDate: data.snapshot.date,
|
|
247
|
+
action: "restore",
|
|
248
|
+
database: undefined,
|
|
249
|
+
};
|
|
250
|
+
const database = {
|
|
251
|
+
name: (0, config_1.resolveDatabaseName)(this.config.database, params),
|
|
252
|
+
};
|
|
253
|
+
if (this.config.targetDatabase && !data.options.initial)
|
|
254
|
+
database.name = (0, config_1.resolveDatabaseName)(this.config.targetDatabase.name, {
|
|
255
|
+
...params,
|
|
256
|
+
database: database.name,
|
|
257
|
+
});
|
|
258
|
+
const [files, compressed] = (0, fs_1.groupFiles)(await (0, fs_1.readDir)(snapshotPath), Object.values(suffix));
|
|
259
|
+
// Database check
|
|
260
|
+
if (files.some((f) => f.endsWith(suffix.database)) &&
|
|
261
|
+
!(await sql.isDatabaseEmpty(database.name)))
|
|
262
|
+
throw new error_1.AppError(`Target database is not empty: ${database.name}`);
|
|
263
|
+
// Table check
|
|
264
|
+
const restoreTables = [
|
|
265
|
+
...new Set(...files
|
|
266
|
+
.filter((f) => (0, string_1.endsWith)(f, [suffix.table, suffix.tableSchema, suffix.tableData]))
|
|
267
|
+
.map((f) => f.split(".")[0])),
|
|
268
|
+
];
|
|
269
|
+
const serverTables = await sql.fetchTableNames(database.name);
|
|
270
|
+
const errorTables = restoreTables.filter((v) => serverTables.includes(v));
|
|
271
|
+
if (errorTables.length)
|
|
272
|
+
throw new error_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
|
|
273
|
+
// Data check
|
|
274
|
+
const dataFiles = files.filter((f) => f.endsWith(suffix.tableData));
|
|
275
|
+
const sharedDir = dataFiles.length
|
|
276
|
+
? await sql.initSharedDir(this.config.csvSharedPath)
|
|
277
|
+
: undefined;
|
|
278
|
+
await sql.createDatabase(database);
|
|
279
|
+
if (data.options.verbose)
|
|
280
|
+
(0, cli_1.logExec)("readdir", [snapshotPath]);
|
|
281
|
+
const concurrency = this.config.concurrency ?? 1;
|
|
282
|
+
let processed = 0;
|
|
283
|
+
await (0, async_1.runParallel)({
|
|
284
|
+
items: files.filter((f) => !f.endsWith(suffix.tableData)),
|
|
285
|
+
concurrency,
|
|
286
|
+
onFinished: () => {
|
|
287
|
+
processed++;
|
|
239
288
|
},
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
:
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
289
|
+
onChange: ({ buffer }) => data.onProgress({
|
|
290
|
+
relative: {
|
|
291
|
+
description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
|
|
292
|
+
payload: [...buffer.keys()].join(", "),
|
|
293
|
+
},
|
|
294
|
+
absolute: {
|
|
295
|
+
total: files.length,
|
|
296
|
+
current: processed,
|
|
297
|
+
percent: (0, math_1.progressPercent)(files.length, processed),
|
|
298
|
+
},
|
|
299
|
+
}),
|
|
300
|
+
onItem: async ({ item: file, controller }) => {
|
|
301
|
+
let path = (0, path_1.join)(snapshotPath, file);
|
|
302
|
+
const tempDir = compressed[file]
|
|
303
|
+
? await (0, temp_1.useTempDir)(exports.mysqlDumpTaskName, "task", "restore", "decompress")
|
|
304
|
+
: undefined;
|
|
305
|
+
try {
|
|
306
|
+
if (tempDir) {
|
|
307
|
+
await (0, tar_1.extractTar)({
|
|
308
|
+
input: (0, path_1.join)(snapshotPath, compressed[file]),
|
|
309
|
+
output: tempDir.path,
|
|
310
|
+
decompress: true,
|
|
311
|
+
verbose: data.options.verbose,
|
|
312
|
+
});
|
|
313
|
+
path = await (0, fs_1.ensureSingleFile)(tempDir.path);
|
|
314
|
+
}
|
|
315
|
+
await sql.importFile({
|
|
316
|
+
path,
|
|
317
|
+
database: database.name,
|
|
318
|
+
controller,
|
|
253
319
|
});
|
|
254
|
-
path = await (0, fs_1.ensureSingleFile)(tempDir.path);
|
|
255
320
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
controller,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
finally {
|
|
263
|
-
await tempDir?.[Symbol.asyncDispose]();
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
await (0, async_1.runParallel)({
|
|
268
|
-
items: dataFiles,
|
|
269
|
-
concurrency,
|
|
270
|
-
onFinished: () => {
|
|
271
|
-
processed++;
|
|
272
|
-
},
|
|
273
|
-
onChange: ({ buffer }) => data.onProgress({
|
|
274
|
-
relative: {
|
|
275
|
-
description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
|
|
276
|
-
payload: [...buffer.keys()].join(", "),
|
|
321
|
+
finally {
|
|
322
|
+
await tempDir?.[Symbol.asyncDispose]();
|
|
323
|
+
}
|
|
277
324
|
},
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
325
|
+
});
|
|
326
|
+
await (0, async_1.runParallel)({
|
|
327
|
+
items: dataFiles,
|
|
328
|
+
concurrency,
|
|
329
|
+
onFinished: () => {
|
|
330
|
+
processed++;
|
|
282
331
|
},
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
332
|
+
onChange: ({ buffer }) => data.onProgress({
|
|
333
|
+
relative: {
|
|
334
|
+
description: buffer.size > 1 ? `Importing (${buffer.size})` : "Importing",
|
|
335
|
+
payload: [...buffer.keys()].join(", "),
|
|
336
|
+
},
|
|
337
|
+
absolute: {
|
|
338
|
+
total: files.length,
|
|
339
|
+
current: processed,
|
|
340
|
+
percent: (0, math_1.progressPercent)(files.length, processed),
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
onItem: async ({ item: file, controller }) => {
|
|
344
|
+
const id = data.snapshot.id.slice(0, 8);
|
|
345
|
+
const tableName = file.slice(0, suffix.tableData.length * -1);
|
|
346
|
+
const sharedName = `tmp-dtt-restore-${id}-${tableName}.data.csv`;
|
|
347
|
+
const temp = (0, temp_1.useTempFile)((0, path_1.join)(sharedDir, sharedName));
|
|
348
|
+
try {
|
|
349
|
+
let csvFile = temp.path;
|
|
350
|
+
if (compressed[file]) {
|
|
351
|
+
await (0, fs_1.mkdirIfNotExists)(temp.path);
|
|
352
|
+
await (0, tar_1.extractTar)({
|
|
353
|
+
input: (0, path_1.join)(snapshotPath, compressed[file]),
|
|
354
|
+
output: temp.path,
|
|
355
|
+
decompress: true,
|
|
356
|
+
verbose: data.options.verbose,
|
|
357
|
+
});
|
|
358
|
+
csvFile = await (0, fs_1.ensureSingleFile)(temp.path);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
const sourceFile = (0, path_1.join)(snapshotPath, file);
|
|
362
|
+
await (0, fs_1.safeRename)(sourceFile, temp.path);
|
|
363
|
+
}
|
|
364
|
+
await sql.importCsvFile({
|
|
365
|
+
path: csvFile,
|
|
366
|
+
database: database.name,
|
|
367
|
+
table: tableName,
|
|
368
|
+
controller,
|
|
298
369
|
});
|
|
299
|
-
csvFile = await (0, fs_1.ensureSingleFile)(temp.path);
|
|
300
370
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
await (0, fs_1.safeRename)(sourceFile, temp.path);
|
|
371
|
+
finally {
|
|
372
|
+
await temp[Symbol.asyncDispose]();
|
|
304
373
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
catch (e_2) {
|
|
378
|
+
env_2.error = e_2;
|
|
379
|
+
env_2.hasError = true;
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
const result_2 = __disposeResources(env_2);
|
|
383
|
+
if (result_2)
|
|
384
|
+
await result_2;
|
|
385
|
+
}
|
|
317
386
|
}
|
|
318
387
|
}
|
|
319
388
|
exports.MysqlDumpTask = MysqlDumpTask;
|
|
@@ -35,7 +35,13 @@ function createCronServer(options, config) {
|
|
|
35
35
|
? ({ ...action.options, confirm: true })
|
|
36
36
|
: action.options);
|
|
37
37
|
const [node, bin] = process.argv;
|
|
38
|
-
await async_process_1.AsyncProcess.exec(node, [
|
|
38
|
+
await async_process_1.AsyncProcess.exec(node, [
|
|
39
|
+
process.env.pm_exec_path ?? bin,
|
|
40
|
+
"-c",
|
|
41
|
+
config.configPath,
|
|
42
|
+
action.name,
|
|
43
|
+
...cliOptions,
|
|
44
|
+
], { $log: config.verbose });
|
|
39
45
|
if (config.log)
|
|
40
46
|
console.info(`< [job] ${index} - ${action.name}`);
|
|
41
47
|
}
|
package/lib/utils/mysql.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type MysqlCliOptions = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare function assertDumpFile(path: string): Promise<void>;
|
|
13
13
|
export declare function createMysqlCli(options: MysqlCliOptions): Promise<{
|
|
14
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
14
15
|
options: MysqlCliOptions;
|
|
15
16
|
initSharedDir: (sharedDir?: string) => Promise<string>;
|
|
16
17
|
args: () => Promise<string[]>;
|
package/lib/utils/mysql.js
CHANGED