@datatruck/cli 0.20.0 → 0.21.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/JsonSchema/DefinitionEnum.d.ts +2 -1
- package/JsonSchema/DefinitionEnum.js +1 -0
- package/JsonSchema/JsonSchema.js +2 -0
- package/Repository/DatatruckRepository.d.ts +4 -3
- package/Repository/DatatruckRepository.js +8 -3
- package/Task/MariadbTask.js +1 -1
- package/config.schema.json +53 -2
- package/package.json +1 -1
- package/utils/tar.d.ts +21 -2
- package/utils/tar.js +90 -6
|
@@ -19,7 +19,8 @@ export declare enum DefinitionEnum {
|
|
|
19
19
|
sqlDumpTask = "sqldump-task",
|
|
20
20
|
stringListUtil = "stringlist-util",
|
|
21
21
|
prunePolicy = "prune-policy",
|
|
22
|
-
pathsObject = "paths-object"
|
|
22
|
+
pathsObject = "paths-object",
|
|
23
|
+
compressUtil = "compress-util"
|
|
23
24
|
}
|
|
24
25
|
export declare function makeRef(type: DefinitionEnum, subType?: string): {
|
|
25
26
|
$ref: string;
|
|
@@ -24,6 +24,7 @@ var DefinitionEnum;
|
|
|
24
24
|
DefinitionEnum["stringListUtil"] = "stringlist-util";
|
|
25
25
|
DefinitionEnum["prunePolicy"] = "prune-policy";
|
|
26
26
|
DefinitionEnum["pathsObject"] = "paths-object";
|
|
27
|
+
DefinitionEnum["compressUtil"] = "compress-util";
|
|
27
28
|
})(DefinitionEnum || (exports.DefinitionEnum = DefinitionEnum = {}));
|
|
28
29
|
function makeRef(type, subType) {
|
|
29
30
|
return {
|
package/JsonSchema/JsonSchema.js
CHANGED
|
@@ -17,6 +17,7 @@ const MysqlDumpTask_1 = require("../Task/MysqlDumpTask");
|
|
|
17
17
|
const PostgresqlDumpTask_1 = require("../Task/PostgresqlDumpTask");
|
|
18
18
|
const ScriptTask_1 = require("../Task/ScriptTask");
|
|
19
19
|
const SqlDumpTaskAbstract_1 = require("../Task/SqlDumpTaskAbstract");
|
|
20
|
+
const tar_1 = require("../utils/tar");
|
|
20
21
|
const DefinitionEnum_1 = require("./DefinitionEnum");
|
|
21
22
|
exports.definitions = {
|
|
22
23
|
[DefinitionEnum_1.DefinitionEnum.stringListUtil]: {
|
|
@@ -45,6 +46,7 @@ exports.definitions = {
|
|
|
45
46
|
[DefinitionEnum_1.DefinitionEnum.config]: Config_1.configDefinition,
|
|
46
47
|
[DefinitionEnum_1.DefinitionEnum.prunePolicy]: PrunePolicyConfig_1.prunePolicyConfigDefinition,
|
|
47
48
|
[DefinitionEnum_1.DefinitionEnum.pathsObject]: PackageConfig_1.pathsObjectDefinition,
|
|
49
|
+
[DefinitionEnum_1.DefinitionEnum.compressUtil]: tar_1.compressDefinition,
|
|
48
50
|
};
|
|
49
51
|
for (const key in exports.definitions) {
|
|
50
52
|
const schemaKey = key;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CompressOptions } from "../utils/tar";
|
|
1
2
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
|
|
2
3
|
import type { JSONSchema7 } from "json-schema";
|
|
3
4
|
export type MetaDataType = {
|
|
@@ -11,17 +12,17 @@ export type MetaDataType = {
|
|
|
11
12
|
};
|
|
12
13
|
export type DatatruckRepositoryConfigType = {
|
|
13
14
|
outPath: string;
|
|
14
|
-
compress?: boolean;
|
|
15
|
+
compress?: boolean | CompressOptions;
|
|
15
16
|
};
|
|
16
17
|
type PackObject = {
|
|
17
18
|
name?: string;
|
|
18
|
-
compress?: boolean;
|
|
19
|
+
compress?: boolean | CompressOptions;
|
|
19
20
|
include: string[];
|
|
20
21
|
exclude?: string[];
|
|
21
22
|
onePackByResult?: boolean;
|
|
22
23
|
};
|
|
23
24
|
export type DatatruckPackageRepositoryConfigType = {
|
|
24
|
-
compress?: boolean;
|
|
25
|
+
compress?: boolean | CompressOptions;
|
|
25
26
|
packs?: PackObject[];
|
|
26
27
|
};
|
|
27
28
|
export declare const datatruckRepositoryName = "datatruck";
|
|
@@ -20,7 +20,9 @@ exports.datatruckRepositoryDefinition = {
|
|
|
20
20
|
additionalProperties: false,
|
|
21
21
|
properties: {
|
|
22
22
|
outPath: { type: "string" },
|
|
23
|
-
compress: {
|
|
23
|
+
compress: {
|
|
24
|
+
anyOf: [{ type: "boolean" }, (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.compressUtil)],
|
|
25
|
+
},
|
|
24
26
|
},
|
|
25
27
|
};
|
|
26
28
|
exports.datatruckPackageRepositoryDefinition = {
|
|
@@ -28,7 +30,7 @@ exports.datatruckPackageRepositoryDefinition = {
|
|
|
28
30
|
additionalProperties: false,
|
|
29
31
|
properties: {
|
|
30
32
|
compress: {
|
|
31
|
-
type: "boolean",
|
|
33
|
+
anyOf: [{ type: "boolean" }, (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.compressUtil)],
|
|
32
34
|
},
|
|
33
35
|
packs: {
|
|
34
36
|
type: "array",
|
|
@@ -38,6 +40,9 @@ exports.datatruckPackageRepositoryDefinition = {
|
|
|
38
40
|
required: ["include"],
|
|
39
41
|
properties: {
|
|
40
42
|
name: { type: "string" },
|
|
43
|
+
compress: {
|
|
44
|
+
anyOf: [{ type: "boolean" }, (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.compressUtil)],
|
|
45
|
+
},
|
|
41
46
|
include: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
|
|
42
47
|
exclude: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
|
|
43
48
|
onePackByResult: { type: "boolean" },
|
|
@@ -323,7 +328,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
323
328
|
await (0, tar_1.extractTar)({
|
|
324
329
|
input: tarFile,
|
|
325
330
|
output: restorePath,
|
|
326
|
-
|
|
331
|
+
decompress: tarFile.endsWith(".tar.gz"),
|
|
327
332
|
verbose: data.options.verbose,
|
|
328
333
|
onEntry: async (data) => await scanner.progress(tarFile.endsWith(".tar.gz") ? "Extracting" : "Unpacking", data.path),
|
|
329
334
|
});
|
package/Task/MariadbTask.js
CHANGED
|
@@ -258,7 +258,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
|
|
|
258
258
|
});
|
|
259
259
|
await (0, tar_1.extractTar)({
|
|
260
260
|
input: (0, path_1.join)(restorePath, zipFile),
|
|
261
|
-
|
|
261
|
+
decompress: true,
|
|
262
262
|
output: restorePath,
|
|
263
263
|
verbose: this.verbose,
|
|
264
264
|
async onEntry(item) {
|
package/config.schema.json
CHANGED
|
@@ -449,7 +449,14 @@
|
|
|
449
449
|
"type": "string"
|
|
450
450
|
},
|
|
451
451
|
"compress": {
|
|
452
|
-
"
|
|
452
|
+
"anyOf": [
|
|
453
|
+
{
|
|
454
|
+
"type": "boolean"
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
"$ref": "#/definitions/compress-util"
|
|
458
|
+
}
|
|
459
|
+
]
|
|
453
460
|
}
|
|
454
461
|
}
|
|
455
462
|
},
|
|
@@ -458,7 +465,14 @@
|
|
|
458
465
|
"additionalProperties": false,
|
|
459
466
|
"properties": {
|
|
460
467
|
"compress": {
|
|
461
|
-
"
|
|
468
|
+
"anyOf": [
|
|
469
|
+
{
|
|
470
|
+
"type": "boolean"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"$ref": "#/definitions/compress-util"
|
|
474
|
+
}
|
|
475
|
+
]
|
|
462
476
|
},
|
|
463
477
|
"packs": {
|
|
464
478
|
"type": "array",
|
|
@@ -472,6 +486,16 @@
|
|
|
472
486
|
"name": {
|
|
473
487
|
"type": "string"
|
|
474
488
|
},
|
|
489
|
+
"compress": {
|
|
490
|
+
"anyOf": [
|
|
491
|
+
{
|
|
492
|
+
"type": "boolean"
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
"$ref": "#/definitions/compress-util"
|
|
496
|
+
}
|
|
497
|
+
]
|
|
498
|
+
},
|
|
475
499
|
"include": {
|
|
476
500
|
"$ref": "#/definitions/stringlist-util"
|
|
477
501
|
},
|
|
@@ -975,6 +999,33 @@
|
|
|
975
999
|
}
|
|
976
1000
|
]
|
|
977
1001
|
},
|
|
1002
|
+
"compress-util": {
|
|
1003
|
+
"type": "object",
|
|
1004
|
+
"additionalProperties": false,
|
|
1005
|
+
"properties": {
|
|
1006
|
+
"level": {
|
|
1007
|
+
"type": "integer"
|
|
1008
|
+
},
|
|
1009
|
+
"cores": {
|
|
1010
|
+
"anyOf": [
|
|
1011
|
+
{
|
|
1012
|
+
"type": "integer"
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
"type": "object",
|
|
1016
|
+
"required": [
|
|
1017
|
+
"percent"
|
|
1018
|
+
],
|
|
1019
|
+
"properties": {
|
|
1020
|
+
"percent": {
|
|
1021
|
+
"type": "integer"
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
]
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
978
1029
|
"script-task_step": {
|
|
979
1030
|
"type": "object",
|
|
980
1031
|
"required": [
|
package/package.json
CHANGED
package/utils/tar.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
1
2
|
export type Progress = {
|
|
2
3
|
percent: number;
|
|
3
4
|
current: number;
|
|
@@ -7,22 +8,39 @@ export type TarEntry = {
|
|
|
7
8
|
path: string;
|
|
8
9
|
progress: Progress;
|
|
9
10
|
};
|
|
11
|
+
export type CoresOptions = number | {
|
|
12
|
+
percent: number;
|
|
13
|
+
};
|
|
14
|
+
export type CompressOptions = {
|
|
15
|
+
level?: number;
|
|
16
|
+
/**
|
|
17
|
+
* @default {percent:50}
|
|
18
|
+
*/
|
|
19
|
+
cores?: CoresOptions;
|
|
20
|
+
};
|
|
21
|
+
export type DecompressOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* @default {percent:50}
|
|
24
|
+
*/
|
|
25
|
+
cores?: CoresOptions;
|
|
26
|
+
};
|
|
10
27
|
export interface CreateTarOptions {
|
|
11
28
|
path: string;
|
|
12
29
|
verbose?: boolean;
|
|
13
30
|
output: string;
|
|
14
31
|
includeList: string;
|
|
15
|
-
compress?: boolean;
|
|
32
|
+
compress?: boolean | CompressOptions;
|
|
16
33
|
onEntry?: (entry: TarEntry) => void;
|
|
17
34
|
}
|
|
18
35
|
export interface ExtractOptions {
|
|
19
36
|
input: string;
|
|
20
37
|
output: string;
|
|
21
38
|
verbose?: boolean;
|
|
22
|
-
|
|
39
|
+
decompress?: boolean | DecompressOptions;
|
|
23
40
|
total?: number;
|
|
24
41
|
onEntry?: (entry: TarEntry) => void;
|
|
25
42
|
}
|
|
43
|
+
export declare const compressDefinition: JSONSchema7;
|
|
26
44
|
export type TarVendor = "busybox" | "bsdtar" | "gnu";
|
|
27
45
|
export declare function getTarVendor(cache?: boolean, log?: boolean): Promise<TarVendor | null>;
|
|
28
46
|
export type ListTarOptions = {
|
|
@@ -31,5 +49,6 @@ export type ListTarOptions = {
|
|
|
31
49
|
verbose?: boolean;
|
|
32
50
|
};
|
|
33
51
|
export declare function listTar(options: ListTarOptions): Promise<number>;
|
|
52
|
+
export declare function checkPigzLib(cache?: boolean): Promise<boolean>;
|
|
34
53
|
export declare function createTar(options: CreateTarOptions): Promise<void>;
|
|
35
54
|
export declare function extractTar(options: ExtractOptions): Promise<void>;
|
package/utils/tar.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractTar = exports.createTar = exports.listTar = exports.getTarVendor = void 0;
|
|
3
|
+
exports.extractTar = exports.createTar = exports.checkPigzLib = exports.listTar = exports.getTarVendor = exports.compressDefinition = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
const fs_1 = require("./fs");
|
|
6
6
|
const math_1 = require("./math");
|
|
7
7
|
const process_1 = require("./process");
|
|
8
8
|
const promises_1 = require("fs/promises");
|
|
9
9
|
const os_1 = require("os");
|
|
10
|
+
exports.compressDefinition = {
|
|
11
|
+
type: "object",
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
properties: {
|
|
14
|
+
level: { type: "integer" },
|
|
15
|
+
cores: {
|
|
16
|
+
anyOf: [
|
|
17
|
+
{ type: "integer" },
|
|
18
|
+
{
|
|
19
|
+
type: "object",
|
|
20
|
+
required: ["percent"],
|
|
21
|
+
properties: { percent: { type: "integer" } },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
10
27
|
let tarVendor;
|
|
11
28
|
async function getTarVendor(cache = true, log = false) {
|
|
12
29
|
if (cache && typeof tarVendor !== "undefined")
|
|
@@ -49,21 +66,76 @@ async function listTar(options) {
|
|
|
49
66
|
return total;
|
|
50
67
|
}
|
|
51
68
|
exports.listTar = listTar;
|
|
69
|
+
let pigzLib;
|
|
70
|
+
async function checkPigzLib(cache = true) {
|
|
71
|
+
if (cache && pigzLib !== undefined)
|
|
72
|
+
return pigzLib;
|
|
73
|
+
try {
|
|
74
|
+
return !(await (0, process_1.exec)("pigz", ["-V"])).exitCode;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.checkPigzLib = checkPigzLib;
|
|
81
|
+
async function resolveCores(input) {
|
|
82
|
+
if (!(await checkPigzLib()))
|
|
83
|
+
return 1;
|
|
84
|
+
const total = (0, os_1.cpus)().length;
|
|
85
|
+
return Math.min(total, typeof input === "number"
|
|
86
|
+
? input
|
|
87
|
+
: Math.max(0, Math.round(((input?.percent || 50) * total) / 100)));
|
|
88
|
+
}
|
|
89
|
+
async function ifX(input, cb) {
|
|
90
|
+
return input ? await cb((input === true ? {} : input)) : undefined;
|
|
91
|
+
}
|
|
52
92
|
async function createTar(options) {
|
|
53
93
|
const vendor = await getTarVendor(true, options.verbose);
|
|
54
94
|
const total = await (0, fs_1.countFileLines)(options.includeList);
|
|
95
|
+
const compress = await ifX(options.compress, async (compress) => ({
|
|
96
|
+
...compress,
|
|
97
|
+
cores: await resolveCores(compress.cores),
|
|
98
|
+
}));
|
|
55
99
|
let current = 0;
|
|
100
|
+
const env = {
|
|
101
|
+
...(compress?.cores === 1 &&
|
|
102
|
+
compress.level && {
|
|
103
|
+
GZIP_OPT: compress.level.toString(),
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
56
106
|
await (0, process_1.exec)("tar", [
|
|
57
107
|
"-C",
|
|
58
108
|
toLocalPath(options.path),
|
|
59
|
-
|
|
109
|
+
compress?.cores === 1 ? "-czvf" : "-cvf",
|
|
60
110
|
toLocalPath(options.output),
|
|
61
111
|
"-T",
|
|
62
112
|
toLocalPath(options.includeList),
|
|
63
113
|
"--ignore-failed-read",
|
|
64
114
|
"--force-local",
|
|
65
|
-
|
|
66
|
-
|
|
115
|
+
...(compress && compress.cores > 1
|
|
116
|
+
? [
|
|
117
|
+
"-I",
|
|
118
|
+
`"${[
|
|
119
|
+
"pigz",
|
|
120
|
+
"-r",
|
|
121
|
+
!!compress.level && `-${compress.level}`,
|
|
122
|
+
`-p ${compress.cores}`,
|
|
123
|
+
]
|
|
124
|
+
.filter(Boolean)
|
|
125
|
+
.join(" ")}"`,
|
|
126
|
+
]
|
|
127
|
+
: []),
|
|
128
|
+
], {
|
|
129
|
+
...(compress &&
|
|
130
|
+
compress.cores > 1 && {
|
|
131
|
+
shell: true,
|
|
132
|
+
}),
|
|
133
|
+
env: {
|
|
134
|
+
...process.env,
|
|
135
|
+
...env,
|
|
136
|
+
},
|
|
137
|
+
}, {
|
|
138
|
+
log: options.verbose ? { envNames: Object.keys(env) } : false,
|
|
67
139
|
stderr: { toExitCode: true },
|
|
68
140
|
stdout: {
|
|
69
141
|
parseLines: "skip-empty",
|
|
@@ -96,14 +168,26 @@ async function extractTar(options) {
|
|
|
96
168
|
(0, cli_1.logExec)("mkdir", ["-p", options.output]);
|
|
97
169
|
await (0, promises_1.mkdir)(options.output, { recursive: true });
|
|
98
170
|
await (0, fs_1.ensureEmptyDir)(options.output);
|
|
171
|
+
const decompress = await ifX(options.decompress, async (decompress) => ({
|
|
172
|
+
...decompress,
|
|
173
|
+
cores: await resolveCores(decompress.cores),
|
|
174
|
+
}));
|
|
99
175
|
let current = 0;
|
|
100
176
|
await (0, process_1.exec)("tar", [
|
|
101
|
-
|
|
177
|
+
decompress?.cores === 1 ? "-xzvpf" : "-xvpf",
|
|
102
178
|
toLocalPath(options.input),
|
|
103
179
|
"-C",
|
|
104
180
|
toLocalPath(options.output),
|
|
105
181
|
"--force-local",
|
|
106
|
-
|
|
182
|
+
...(decompress && decompress.cores > 1
|
|
183
|
+
? ["-I", `"pigz -p ${decompress.cores}"`]
|
|
184
|
+
: []),
|
|
185
|
+
], {
|
|
186
|
+
...(decompress &&
|
|
187
|
+
decompress.cores > 1 && {
|
|
188
|
+
shell: true,
|
|
189
|
+
}),
|
|
190
|
+
}, {
|
|
107
191
|
log: options.verbose,
|
|
108
192
|
stderr: {
|
|
109
193
|
toExitCode: true,
|