@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/Task/ScriptTask.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = exports.ScriptTaskDefinitionEnum = void 0;
|
|
3
|
+
exports.ScriptTask = exports.scriptTaskDefinition = exports.scriptTaskName = exports.ScriptTaskDefinitionEnum = exports.scriptTaskCode = void 0;
|
|
4
4
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
5
|
-
const fs_1 = require("../utils/fs");
|
|
6
5
|
const steps_1 = require("../utils/steps");
|
|
6
|
+
const temp_1 = require("../utils/temp");
|
|
7
7
|
const TaskAbstract_1 = require("./TaskAbstract");
|
|
8
|
-
|
|
8
|
+
function scriptTaskCode(cb) {
|
|
9
|
+
return `(${cb.toString()})(...arguments);`;
|
|
10
|
+
}
|
|
11
|
+
exports.scriptTaskCode = scriptTaskCode;
|
|
9
12
|
var ScriptTaskDefinitionEnum;
|
|
10
13
|
(function (ScriptTaskDefinitionEnum) {
|
|
11
14
|
ScriptTaskDefinitionEnum["step"] = "step";
|
|
12
15
|
ScriptTaskDefinitionEnum["processStepConfig"] = "processStepConfig";
|
|
13
16
|
ScriptTaskDefinitionEnum["nodeStepConfig"] = "nodeStepConfig";
|
|
17
|
+
ScriptTaskDefinitionEnum["telegramMessageStepConfig"] = "telegramMessageStepConfig";
|
|
14
18
|
})(ScriptTaskDefinitionEnum || (exports.ScriptTaskDefinitionEnum = ScriptTaskDefinitionEnum = {}));
|
|
15
19
|
const stepTypes = {
|
|
16
20
|
process: ScriptTaskDefinitionEnum.processStepConfig,
|
|
17
21
|
node: ScriptTaskDefinitionEnum.nodeStepConfig,
|
|
22
|
+
"telegram-message": ScriptTaskDefinitionEnum.telegramMessageStepConfig,
|
|
18
23
|
};
|
|
19
24
|
exports.scriptTaskName = "script";
|
|
20
25
|
exports.scriptTaskDefinition = {
|
|
@@ -71,6 +76,15 @@ exports.scriptTaskDefinition = {
|
|
|
71
76
|
},
|
|
72
77
|
},
|
|
73
78
|
},
|
|
79
|
+
telegramMessageStepConfig: {
|
|
80
|
+
type: "object",
|
|
81
|
+
required: ["bot", "chatId"],
|
|
82
|
+
properties: {
|
|
83
|
+
command: { type: "string" },
|
|
84
|
+
chatId: { type: "integer" },
|
|
85
|
+
text: { type: "string" },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
74
88
|
},
|
|
75
89
|
type: "object",
|
|
76
90
|
additionalProperties: false,
|
|
@@ -94,11 +108,6 @@ exports.scriptTaskDefinition = {
|
|
|
94
108
|
};
|
|
95
109
|
class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
96
110
|
verbose;
|
|
97
|
-
async onBeforeBackup(data) {
|
|
98
|
-
return {
|
|
99
|
-
targetPath: data.package.path ?? (await this.mkTmpDir(`script-task_backup_target`)),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
111
|
getVars(data) {
|
|
103
112
|
return {
|
|
104
113
|
process: {
|
|
@@ -106,51 +115,52 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
106
115
|
DTT_SNAPSHOT_DATE: data.snapshot.date,
|
|
107
116
|
DTT_PACKAGE_NAME: data.package.name,
|
|
108
117
|
DTT_PACKAGE_PATH: data.package.path,
|
|
109
|
-
|
|
118
|
+
DTT_SNAPSHOT_PATH: data.snapshotPath,
|
|
110
119
|
},
|
|
111
120
|
node: {
|
|
112
121
|
dtt: {
|
|
113
122
|
snapshot: data.snapshot,
|
|
114
123
|
package: data.package,
|
|
115
|
-
|
|
124
|
+
snapshotPath: data.snapshotPath,
|
|
116
125
|
},
|
|
117
126
|
},
|
|
118
127
|
};
|
|
119
128
|
}
|
|
120
|
-
async
|
|
129
|
+
async backup(data) {
|
|
121
130
|
const config = this.config;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const vars = this.getVars(
|
|
125
|
-
|
|
131
|
+
const snapshotPath = data.package.path ??
|
|
132
|
+
(await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "snapshot"));
|
|
133
|
+
const vars = this.getVars({
|
|
134
|
+
...data,
|
|
135
|
+
snapshotPath,
|
|
136
|
+
});
|
|
126
137
|
await (0, steps_1.runSteps)(config.backupSteps, {
|
|
127
138
|
env: config.env,
|
|
139
|
+
cwd: snapshotPath,
|
|
128
140
|
verbose: data.options.verbose,
|
|
129
141
|
process: { vars: vars.process },
|
|
130
142
|
node: {
|
|
131
|
-
tempDir: () =>
|
|
143
|
+
tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "backup", "nodeStep"),
|
|
132
144
|
vars: vars.node,
|
|
133
145
|
},
|
|
134
146
|
});
|
|
147
|
+
return { snapshotPath };
|
|
135
148
|
}
|
|
136
|
-
async
|
|
149
|
+
async prepareRestore(data) {
|
|
137
150
|
return {
|
|
138
|
-
|
|
139
|
-
(await
|
|
151
|
+
snapshotPath: data.package.restorePath ??
|
|
152
|
+
(await (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "snapshot")),
|
|
140
153
|
};
|
|
141
154
|
}
|
|
142
|
-
async
|
|
155
|
+
async restore(data) {
|
|
143
156
|
const config = this.config;
|
|
144
|
-
const targetPath = data.targetPath;
|
|
145
|
-
(0, assert_1.ok)(typeof targetPath === "string");
|
|
146
|
-
await (0, fs_1.mkdirIfNotExists)(targetPath);
|
|
147
157
|
const vars = this.getVars(data);
|
|
148
158
|
await (0, steps_1.runSteps)(config.restoreSteps, {
|
|
149
159
|
env: config.env,
|
|
150
160
|
verbose: data.options.verbose,
|
|
151
161
|
process: { vars: vars.process },
|
|
152
162
|
node: {
|
|
153
|
-
tempDir: () =>
|
|
163
|
+
tempDir: () => (0, temp_1.mkTmpDir)(exports.scriptTaskName, "task", "restore", "nodeStep"),
|
|
154
164
|
vars: vars.node,
|
|
155
165
|
},
|
|
156
166
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { exec } from "../utils/process";
|
|
2
|
-
import {
|
|
2
|
+
import { TaskBackupData, TaskPrepareRestoreData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
|
|
3
3
|
import { JSONSchema7, JSONSchema7Definition } from "json-schema";
|
|
4
4
|
export type TargetDatabaseType = {
|
|
5
5
|
name: string;
|
|
@@ -37,6 +37,11 @@ export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskCon
|
|
|
37
37
|
}) => void): Promise<void>;
|
|
38
38
|
abstract onExportStoredPrograms(output: string): Promise<void>;
|
|
39
39
|
abstract onImport(path: string, database: string): Promise<void>;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
backup(data: TaskBackupData): Promise<{
|
|
41
|
+
snapshotPath: string;
|
|
42
|
+
}>;
|
|
43
|
+
prepareRestore(data: TaskPrepareRestoreData): Promise<{
|
|
44
|
+
snapshotPath: string;
|
|
45
|
+
}>;
|
|
46
|
+
restore(data: TaskRestoreData): Promise<void>;
|
|
42
47
|
}
|
|
@@ -7,6 +7,7 @@ const cli_1 = require("../utils/cli");
|
|
|
7
7
|
const config_1 = require("../utils/datatruck/config");
|
|
8
8
|
const fs_1 = require("../utils/fs");
|
|
9
9
|
const math_1 = require("../utils/math");
|
|
10
|
+
const temp_1 = require("../utils/temp");
|
|
10
11
|
const TaskAbstract_1 = require("./TaskAbstract");
|
|
11
12
|
const assert_1 = require("assert");
|
|
12
13
|
const promises_1 = require("fs/promises");
|
|
@@ -104,10 +105,13 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
104
105
|
return result;
|
|
105
106
|
}, []);
|
|
106
107
|
}
|
|
107
|
-
async
|
|
108
|
+
async backup(data) {
|
|
108
109
|
this.verbose = data.options.verbose;
|
|
110
|
+
const snapshotPath = data.package.path ??
|
|
111
|
+
(await (0, temp_1.mkTmpDir)("sqldump", "task", "backup", "snapshot"));
|
|
112
|
+
await (0, fs_1.mkdirIfNotExists)(snapshotPath);
|
|
113
|
+
await (0, fs_1.ensureEmptyDir)(snapshotPath);
|
|
109
114
|
const config = this.config;
|
|
110
|
-
const outputPath = data.package.path;
|
|
111
115
|
const allTableNames = await this.onFetchTableNames(this.config.database);
|
|
112
116
|
const tableNames = allTableNames.filter((tableName) => {
|
|
113
117
|
if (config.includeTables && !(0, micromatch_1.isMatch)(tableName, config.includeTables))
|
|
@@ -116,18 +120,18 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
116
120
|
return false;
|
|
117
121
|
return true;
|
|
118
122
|
});
|
|
119
|
-
(0, assert_1.ok)(typeof
|
|
120
|
-
if (!(await (0, fs_1.existsDir)(
|
|
121
|
-
await (0, promises_1.mkdir)(
|
|
123
|
+
(0, assert_1.ok)(typeof snapshotPath === "string");
|
|
124
|
+
if (!(await (0, fs_1.existsDir)(snapshotPath)))
|
|
125
|
+
await (0, promises_1.mkdir)(snapshotPath, { recursive: true });
|
|
122
126
|
if (!this.config.oneFileByTable) {
|
|
123
|
-
const outPath = (0, path_1.join)(
|
|
124
|
-
|
|
127
|
+
const outPath = (0, path_1.join)(snapshotPath, serializeSqlFile({ database: this.config.database }));
|
|
128
|
+
data.onProgress({
|
|
125
129
|
relative: {
|
|
126
130
|
description: "Exporting",
|
|
127
131
|
},
|
|
128
132
|
});
|
|
129
133
|
await this.onExportTables(tableNames, outPath, async (progress) => {
|
|
130
|
-
|
|
134
|
+
data.onProgress({
|
|
131
135
|
absolute: {
|
|
132
136
|
description: "Exporting in single file",
|
|
133
137
|
current: progress.totalBytes,
|
|
@@ -139,7 +143,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
139
143
|
else {
|
|
140
144
|
let current = 0;
|
|
141
145
|
for (const tableName of tableNames) {
|
|
142
|
-
|
|
146
|
+
data.onProgress({
|
|
143
147
|
relative: {
|
|
144
148
|
description: "Exporting",
|
|
145
149
|
payload: tableName,
|
|
@@ -150,9 +154,9 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
150
154
|
percent: (0, math_1.progressPercent)(tableNames.length, current),
|
|
151
155
|
},
|
|
152
156
|
});
|
|
153
|
-
const outPath = (0, path_1.join)(
|
|
157
|
+
const outPath = (0, path_1.join)(snapshotPath, serializeSqlFile({ table: tableName }));
|
|
154
158
|
await this.onExportTables([tableName], outPath, async (progress) => {
|
|
155
|
-
|
|
159
|
+
data.onProgress({
|
|
156
160
|
relative: {
|
|
157
161
|
description: "Exporting",
|
|
158
162
|
payload: tableName,
|
|
@@ -170,19 +174,27 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
170
174
|
}
|
|
171
175
|
}
|
|
172
176
|
if (this.config.storedPrograms) {
|
|
173
|
-
const outPath = (0, path_1.join)(
|
|
174
|
-
|
|
177
|
+
const outPath = (0, path_1.join)(snapshotPath, "stored-programs.sql");
|
|
178
|
+
data.onProgress({
|
|
175
179
|
relative: {
|
|
176
180
|
description: "Exporting storaged programs",
|
|
177
181
|
},
|
|
178
182
|
});
|
|
179
183
|
await this.onExportStoredPrograms(outPath);
|
|
180
184
|
}
|
|
185
|
+
return {
|
|
186
|
+
snapshotPath: snapshotPath,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
async prepareRestore(data) {
|
|
190
|
+
return {
|
|
191
|
+
snapshotPath: data.package.restorePath ??
|
|
192
|
+
(await (0, temp_1.mkTmpDir)("sqldump", "task", "restore", "snapshot")),
|
|
193
|
+
};
|
|
181
194
|
}
|
|
182
|
-
async
|
|
183
|
-
const
|
|
195
|
+
async restore(data) {
|
|
196
|
+
const snapshotPath = data.snapshotPath;
|
|
184
197
|
this.verbose = data.options.verbose;
|
|
185
|
-
(0, assert_1.ok)(typeof restorePath === "string");
|
|
186
198
|
const database = {
|
|
187
199
|
name: (0, config_1.resolveDatabaseName)(this.config.database, {
|
|
188
200
|
packageName: data.package.name,
|
|
@@ -201,7 +213,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
201
213
|
database: database.name,
|
|
202
214
|
});
|
|
203
215
|
}
|
|
204
|
-
const items = (await (0, fs_1.readDir)(
|
|
216
|
+
const items = (await (0, fs_1.readDir)(snapshotPath))
|
|
205
217
|
.map(parseSqlFile)
|
|
206
218
|
.filter((v) => !!v);
|
|
207
219
|
// Database check
|
|
@@ -219,10 +231,10 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
219
231
|
}
|
|
220
232
|
await this.onCreateDatabase(database);
|
|
221
233
|
if (this.verbose)
|
|
222
|
-
(0, cli_1.logExec)("readdir", [
|
|
234
|
+
(0, cli_1.logExec)("readdir", [snapshotPath]);
|
|
223
235
|
let current = 0;
|
|
224
236
|
for (const item of items) {
|
|
225
|
-
const path = (0, path_1.join)(
|
|
237
|
+
const path = (0, path_1.join)(snapshotPath, item.fileName);
|
|
226
238
|
data.onProgress({
|
|
227
239
|
relative: {
|
|
228
240
|
description: "Importing",
|
package/Task/TaskAbstract.d.ts
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BackupActionOptions } from "../Action/BackupAction";
|
|
2
|
+
import { RestoreActionOptions } from "../Action/RestoreAction";
|
|
3
3
|
import { PackageConfigType } from "../Config/PackageConfig";
|
|
4
|
-
import {
|
|
4
|
+
import { PreSnapshot } from "../Repository/RepositoryAbstract";
|
|
5
5
|
import { Progress } from "../utils/progress";
|
|
6
|
-
|
|
7
|
-
onProgress: (data: Progress) => Promise<void>;
|
|
8
|
-
options: BackupActionOptionsType;
|
|
6
|
+
type TaskCommonData = {
|
|
9
7
|
package: PackageConfigType;
|
|
10
|
-
|
|
11
|
-
snapshot: SnapshotType;
|
|
8
|
+
snapshot: PreSnapshot;
|
|
12
9
|
};
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
export type TaskBackupData = TaskCommonData & {
|
|
11
|
+
onProgress: (data: Progress) => void;
|
|
12
|
+
options: BackupActionOptions;
|
|
13
|
+
snapshotPath?: string;
|
|
14
|
+
};
|
|
15
|
+
export type TaskRestoreData = TaskCommonData & {
|
|
16
|
+
onProgress: (data: Progress) => void;
|
|
17
|
+
options: RestoreActionOptions;
|
|
18
|
+
snapshotPath: string;
|
|
19
|
+
};
|
|
20
|
+
export type TaskPrepareRestoreData = TaskCommonData & {
|
|
21
|
+
options: RestoreActionOptions;
|
|
20
22
|
};
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} | undefined | void>;
|
|
23
|
+
export type TaskReturn = Promise<{
|
|
24
|
+
snapshotPath?: string;
|
|
25
|
+
} | undefined>;
|
|
25
26
|
export declare abstract class TaskAbstract<TConfig = any> {
|
|
26
27
|
readonly config: TConfig;
|
|
27
|
-
readonly tmpDirs: string[];
|
|
28
28
|
constructor(config: TConfig);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
onBeforeRestore(data: BeforeRestoreDataType): BeforeReturn;
|
|
33
|
-
onRestore(data: RestoreDataType): Promise<void>;
|
|
29
|
+
backup(data: TaskBackupData): TaskReturn;
|
|
30
|
+
prepareRestore(data: TaskPrepareRestoreData): TaskReturn;
|
|
31
|
+
restore(data: TaskRestoreData): Promise<void>;
|
|
34
32
|
}
|
|
33
|
+
export {};
|
package/Task/TaskAbstract.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TaskAbstract = void 0;
|
|
4
|
-
const fs_1 = require("../utils/fs");
|
|
5
4
|
class TaskAbstract {
|
|
6
5
|
config;
|
|
7
|
-
tmpDirs = [];
|
|
8
6
|
constructor(config) {
|
|
9
7
|
this.config = config;
|
|
10
8
|
}
|
|
11
|
-
async
|
|
12
|
-
|
|
13
|
-
this.tmpDirs.push(dir);
|
|
14
|
-
return dir;
|
|
9
|
+
async backup(data) {
|
|
10
|
+
return;
|
|
15
11
|
}
|
|
16
|
-
async
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
async
|
|
12
|
+
async prepareRestore(data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
async restore(data) { }
|
|
20
16
|
}
|
|
21
17
|
exports.TaskAbstract = TaskAbstract;
|
package/cli.js
CHANGED
|
@@ -12,12 +12,20 @@ const cli_1 = require("./utils/cli");
|
|
|
12
12
|
const fs_1 = require("./utils/fs");
|
|
13
13
|
const process_1 = require("./utils/process");
|
|
14
14
|
const string_1 = require("./utils/string");
|
|
15
|
+
const temp_1 = require("./utils/temp");
|
|
15
16
|
const chalk_1 = require("chalk");
|
|
16
17
|
const commander_1 = require("commander");
|
|
17
18
|
const fs_2 = require("fs");
|
|
18
19
|
const path_1 = require("path");
|
|
19
20
|
function getGlobalOptions() {
|
|
20
|
-
|
|
21
|
+
const result = program.opts();
|
|
22
|
+
return {
|
|
23
|
+
...result,
|
|
24
|
+
tty: result.tty === "auto" ? "auto" : result.tty === "true",
|
|
25
|
+
progress: result.progress === "auto" || result.progress === "interval"
|
|
26
|
+
? result.progress
|
|
27
|
+
: result.progress === "true",
|
|
28
|
+
};
|
|
21
29
|
}
|
|
22
30
|
function makeCommand(command) {
|
|
23
31
|
const programCommand = program.command(command);
|
|
@@ -80,17 +88,18 @@ program.description(description);
|
|
|
80
88
|
program.usage("dtt");
|
|
81
89
|
program.option("-v,--verbose", "Verbose", (_, previous) => previous + 1, 0);
|
|
82
90
|
program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFIG"] ?? (cwd.endsWith(path_1.sep) ? cwd : `${cwd}${path_1.sep}`));
|
|
83
|
-
program.option("--
|
|
91
|
+
program.option("--tty <value>", "TTY mode (auto, true, false)", "auto");
|
|
92
|
+
program.option("--progress <value>", "Progress type (auto, true, false, interval)", "auto");
|
|
84
93
|
program.option("--progress-interval <ms>", "Progress interval", Number, 1000);
|
|
85
94
|
program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
|
|
95
|
+
makeCommand(CommandFactory_1.CommandEnum.startServer).alias("start");
|
|
86
96
|
makeCommand(CommandFactory_1.CommandEnum.config).alias("c");
|
|
87
97
|
makeCommand(CommandFactory_1.CommandEnum.init).alias("i");
|
|
88
98
|
makeCommand(CommandFactory_1.CommandEnum.snapshots).alias("s");
|
|
89
99
|
makeCommand(CommandFactory_1.CommandEnum.prune).alias("p");
|
|
90
100
|
makeCommand(CommandFactory_1.CommandEnum.backup).alias("b");
|
|
91
|
-
makeCommand(CommandFactory_1.CommandEnum.backupSessions).alias("bs");
|
|
92
101
|
makeCommand(CommandFactory_1.CommandEnum.restore).alias("r");
|
|
93
|
-
makeCommand(CommandFactory_1.CommandEnum.
|
|
102
|
+
makeCommand(CommandFactory_1.CommandEnum.copy).alias("cp");
|
|
94
103
|
makeCommand(CommandFactory_1.CommandEnum.cleanCache).alias("cc");
|
|
95
104
|
function buildArgs(input, options) {
|
|
96
105
|
const optionsArray = Object.keys(options).flatMap((name) => [
|
|
@@ -112,7 +121,7 @@ function parseArgs(args) {
|
|
|
112
121
|
}
|
|
113
122
|
if (!verbose)
|
|
114
123
|
try {
|
|
115
|
-
(0, fs_2.rmSync)((0,
|
|
124
|
+
(0, fs_2.rmSync)((0, temp_1.sessionTmpDir)(), {
|
|
116
125
|
force: true,
|
|
117
126
|
recursive: true,
|
|
118
127
|
maxRetries: 5,
|
package/config.schema.json
CHANGED
|
@@ -444,11 +444,11 @@
|
|
|
444
444
|
"datatruck-repository": {
|
|
445
445
|
"type": "object",
|
|
446
446
|
"required": [
|
|
447
|
-
"
|
|
447
|
+
"backend"
|
|
448
448
|
],
|
|
449
449
|
"additionalProperties": false,
|
|
450
450
|
"properties": {
|
|
451
|
-
"
|
|
451
|
+
"backend": {
|
|
452
452
|
"type": "string"
|
|
453
453
|
},
|
|
454
454
|
"compress": {
|
|
@@ -902,6 +902,16 @@
|
|
|
902
902
|
"csvSharedPath": {
|
|
903
903
|
"type": "string"
|
|
904
904
|
},
|
|
905
|
+
"compress": {
|
|
906
|
+
"anyOf": [
|
|
907
|
+
{
|
|
908
|
+
"type": "boolean"
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
"$ref": "#/definitions/compress-util"
|
|
912
|
+
}
|
|
913
|
+
]
|
|
914
|
+
},
|
|
905
915
|
"password": {
|
|
906
916
|
"anyOf": [
|
|
907
917
|
{
|
|
@@ -985,6 +995,43 @@
|
|
|
985
995
|
"tempDir": {
|
|
986
996
|
"type": "string"
|
|
987
997
|
},
|
|
998
|
+
"minFreeDiskSpace": {
|
|
999
|
+
"anyOf": [
|
|
1000
|
+
{
|
|
1001
|
+
"type": "integer"
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
"type": "string"
|
|
1005
|
+
}
|
|
1006
|
+
]
|
|
1007
|
+
},
|
|
1008
|
+
"reports": {
|
|
1009
|
+
"type": "array",
|
|
1010
|
+
"items": {
|
|
1011
|
+
"type": "object",
|
|
1012
|
+
"additionalProperties": false,
|
|
1013
|
+
"properties": {
|
|
1014
|
+
"when": {
|
|
1015
|
+
"enum": [
|
|
1016
|
+
"success",
|
|
1017
|
+
"error"
|
|
1018
|
+
]
|
|
1019
|
+
},
|
|
1020
|
+
"format": {
|
|
1021
|
+
"enum": [
|
|
1022
|
+
"json",
|
|
1023
|
+
"list",
|
|
1024
|
+
"pjson",
|
|
1025
|
+
"table",
|
|
1026
|
+
"yaml"
|
|
1027
|
+
]
|
|
1028
|
+
},
|
|
1029
|
+
"run": {
|
|
1030
|
+
"$ref": "#/definitions/script-task_step"
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
988
1035
|
"repositories": {
|
|
989
1036
|
"type": "array",
|
|
990
1037
|
"items": {
|
|
@@ -996,6 +1043,42 @@
|
|
|
996
1043
|
"items": {
|
|
997
1044
|
"$ref": "#/definitions/package"
|
|
998
1045
|
}
|
|
1046
|
+
},
|
|
1047
|
+
"server": {
|
|
1048
|
+
"type": "object",
|
|
1049
|
+
"additionalProperties": false,
|
|
1050
|
+
"properties": {
|
|
1051
|
+
"path": {
|
|
1052
|
+
"type": "string"
|
|
1053
|
+
},
|
|
1054
|
+
"users": {
|
|
1055
|
+
"type": "array",
|
|
1056
|
+
"items": {
|
|
1057
|
+
"type": "object",
|
|
1058
|
+
"additionalProperties": false,
|
|
1059
|
+
"properties": {
|
|
1060
|
+
"name": {
|
|
1061
|
+
"type": "string"
|
|
1062
|
+
},
|
|
1063
|
+
"password": {
|
|
1064
|
+
"type": "string"
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
"listen": {
|
|
1070
|
+
"type": "object",
|
|
1071
|
+
"additionalProperties": false,
|
|
1072
|
+
"properties": {
|
|
1073
|
+
"port": {
|
|
1074
|
+
"type": "integer"
|
|
1075
|
+
},
|
|
1076
|
+
"address": {
|
|
1077
|
+
"type": "string"
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
999
1082
|
}
|
|
1000
1083
|
}
|
|
1001
1084
|
},
|
|
@@ -1075,7 +1158,8 @@
|
|
|
1075
1158
|
"type": {
|
|
1076
1159
|
"enum": [
|
|
1077
1160
|
"process",
|
|
1078
|
-
"node"
|
|
1161
|
+
"node",
|
|
1162
|
+
"telegram-message"
|
|
1079
1163
|
]
|
|
1080
1164
|
},
|
|
1081
1165
|
"config": {}
|
|
@@ -1118,6 +1202,25 @@
|
|
|
1118
1202
|
}
|
|
1119
1203
|
},
|
|
1120
1204
|
"else": false
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
"if": {
|
|
1208
|
+
"type": "object",
|
|
1209
|
+
"properties": {
|
|
1210
|
+
"type": {
|
|
1211
|
+
"const": "telegram-message"
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
},
|
|
1215
|
+
"then": {
|
|
1216
|
+
"type": "object",
|
|
1217
|
+
"properties": {
|
|
1218
|
+
"config": {
|
|
1219
|
+
"$ref": "#/definitions/script-task_telegramMessageStepConfig"
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
"else": false
|
|
1121
1224
|
}
|
|
1122
1225
|
]
|
|
1123
1226
|
},
|
|
@@ -1174,6 +1277,24 @@
|
|
|
1174
1277
|
}
|
|
1175
1278
|
}
|
|
1176
1279
|
}
|
|
1280
|
+
},
|
|
1281
|
+
"script-task_telegramMessageStepConfig": {
|
|
1282
|
+
"type": "object",
|
|
1283
|
+
"required": [
|
|
1284
|
+
"bot",
|
|
1285
|
+
"chatId"
|
|
1286
|
+
],
|
|
1287
|
+
"properties": {
|
|
1288
|
+
"command": {
|
|
1289
|
+
"type": "string"
|
|
1290
|
+
},
|
|
1291
|
+
"chatId": {
|
|
1292
|
+
"type": "integer"
|
|
1293
|
+
},
|
|
1294
|
+
"text": {
|
|
1295
|
+
"type": "string"
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1177
1298
|
}
|
|
1178
1299
|
},
|
|
1179
1300
|
"$ref": "#/definitions/config"
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datatruck/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@supercharge/promise-pool": "^3.1.0",
|
|
6
6
|
"ajv": "^8.12.0",
|
|
7
7
|
"async": "^3.2.4",
|
|
8
|
+
"bytes": "^3.1.2",
|
|
8
9
|
"chalk": "^4.1.2",
|
|
9
|
-
"cli-table3": "^0.6.3",
|
|
10
10
|
"commander": "^11.0.0",
|
|
11
11
|
"dayjs": "^1.11.10",
|
|
12
12
|
"fast-folder-size": "^2.2.0",
|
|
13
13
|
"fast-glob": "^3.3.1",
|
|
14
|
+
"listr2": "^7.0.1",
|
|
14
15
|
"micromatch": "^4.0.5",
|
|
15
16
|
"mysql2": "^3.6.1",
|
|
16
|
-
"
|
|
17
|
-
"sqlite": "^5.0.1",
|
|
18
|
-
"sqlite3": "^5.1.6"
|
|
17
|
+
"tty-table": "^4.2.2"
|
|
19
18
|
},
|
|
20
19
|
"optionalDependencies": {
|
|
21
20
|
"ts-node": "^10.9.1",
|
package/utils/DataFormat.d.ts
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Streams } from "./stream";
|
|
2
|
+
import { Header } from "tty-table";
|
|
3
|
+
export type FormatType = "json" | "list" | "pjson" | "table" | "yaml" | "custom" | "tpl";
|
|
4
|
+
export declare const dataFormats: FormatType[];
|
|
5
|
+
export declare class DataFormat {
|
|
3
6
|
readonly options: {
|
|
4
|
-
|
|
5
|
-
json
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
streams?: Partial<Streams>;
|
|
8
|
+
json: any;
|
|
9
|
+
list?: () => string[];
|
|
10
|
+
table?: {
|
|
11
|
+
headers: Header[];
|
|
12
|
+
rows: () => (string | number | null | undefined)[][];
|
|
9
13
|
};
|
|
10
14
|
};
|
|
15
|
+
protected streams: Streams;
|
|
11
16
|
constructor(options: {
|
|
12
|
-
|
|
13
|
-
json
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
streams?: Partial<Streams>;
|
|
18
|
+
json: any;
|
|
19
|
+
list?: () => string[];
|
|
20
|
+
table?: {
|
|
21
|
+
headers: Header[];
|
|
22
|
+
rows: () => (string | number | null | undefined)[][];
|
|
17
23
|
};
|
|
18
24
|
});
|
|
25
|
+
protected getJson(): any;
|
|
19
26
|
protected formatToJson(): string;
|
|
20
27
|
protected formatToPrettyJson(): string;
|
|
21
28
|
protected formatToYaml(): any;
|
|
22
29
|
protected formatToTable(): string;
|
|
30
|
+
protected formatToList(): string;
|
|
31
|
+
log(format: FormatType, options?: {
|
|
32
|
+
tpl?: Record<string, () => string>;
|
|
33
|
+
}): void;
|
|
23
34
|
format(format: FormatType, options?: {
|
|
24
35
|
tpl?: Record<string, () => string>;
|
|
25
36
|
}): any;
|