@datatruck/cli 0.17.2 → 0.19.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.js +4 -2
- package/Action/BackupSessionsAction.js +2 -0
- package/Action/CleanCacheAction.js +1 -0
- package/Action/ConfigAction.js +1 -0
- package/Action/InitAction.js +2 -0
- package/Action/PruneAction.js +2 -0
- package/Action/RestoreAction.js +4 -2
- package/Action/RestoreSessionsAction.js +2 -0
- package/Action/SnapshotsAction.js +2 -0
- package/Command/CommandAbstract.js +2 -0
- package/Entity/BackupSessionEntity.js +5 -2
- package/Entity/BackupSessionRepositoryEntity.js +5 -2
- package/Entity/BackupSessionTaskEntity.js +4 -2
- package/Entity/CrudEntityAbstract.js +3 -0
- package/Entity/RestoreSessionEntity.js +4 -2
- package/Entity/RestoreSessionRepositoryEntity.js +5 -2
- package/Entity/RestoreSessionTaskEntity.js +4 -2
- package/Entity/StateEntityAbstract.js +5 -0
- package/Factory/CommandFactory.js +1 -1
- package/JsonSchema/DefinitionEnum.js +1 -1
- package/Repository/DatatruckRepository.d.ts +8 -14
- package/Repository/DatatruckRepository.js +115 -298
- package/Repository/GitRepository.js +1 -1
- package/Repository/RepositoryAbstract.js +4 -2
- package/Repository/ResticRepository.js +2 -1
- package/SessionDriver/ConsoleSessionDriver.js +9 -5
- package/SessionDriver/SessionDriverAbstract.js +3 -2
- package/SessionDriver/SqliteSessionDriver.js +2 -4
- package/SessionManager/BackupSessionManager.js +3 -6
- package/SessionManager/RestoreSessionManager.js +3 -6
- package/SessionManager/SessionManagerAbstract.js +4 -0
- package/Task/GitTask.js +1 -0
- package/Task/MariadbTask.d.ts +11 -0
- package/Task/MariadbTask.js +234 -51
- package/Task/MssqlTask.js +2 -1
- package/Task/ScriptTask.js +1 -0
- package/Task/SqlDumpTaskAbstract.js +1 -0
- package/Task/TaskAbstract.js +2 -1
- package/config.schema.json +67 -37
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +10 -9
- package/utils/DataFormat.js +1 -0
- package/utils/Git.js +1 -0
- package/utils/ObjectVault.js +3 -5
- package/utils/Restic.js +1 -0
- package/utils/datatruck/config.d.ts +1 -1
- package/utils/fs.d.ts +17 -2
- package/utils/fs.js +58 -7
- package/utils/process.d.ts +55 -3
- package/utils/process.js +159 -19
- package/utils/tar.d.ts +32 -0
- package/utils/tar.js +92 -0
- package/utils/zip.d.ts +0 -97
- package/utils/zip.js +0 -238
package/utils/zip.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unzip = exports.zip = exports.listZip = exports.checkSSEOption = exports.buildArguments = void 0;
|
|
4
|
-
const process_1 = require("./process");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
function buildArguments(filters) {
|
|
7
|
-
const args = [];
|
|
8
|
-
for (const item of filters) {
|
|
9
|
-
let filter;
|
|
10
|
-
if (typeof item === "string") {
|
|
11
|
-
filter = {
|
|
12
|
-
recursive: false,
|
|
13
|
-
exclude: false,
|
|
14
|
-
patterns: [item],
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
filter = item;
|
|
19
|
-
}
|
|
20
|
-
args.push(...filter.patterns.map((value) => {
|
|
21
|
-
let option = "-";
|
|
22
|
-
option += filter.exclude ? "x" : "i";
|
|
23
|
-
if (filter.recursive)
|
|
24
|
-
option += "r";
|
|
25
|
-
option += "!";
|
|
26
|
-
option += (0, path_1.normalize)(value);
|
|
27
|
-
return option;
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
return args;
|
|
31
|
-
}
|
|
32
|
-
exports.buildArguments = buildArguments;
|
|
33
|
-
let checkSSEOptionResult;
|
|
34
|
-
async function checkSSEOption(command = "7z") {
|
|
35
|
-
const result = await (0, process_1.exec)(command, [], {}, {
|
|
36
|
-
stdout: {
|
|
37
|
-
save: true,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
if (typeof checkSSEOptionResult === "boolean")
|
|
41
|
-
return checkSSEOptionResult;
|
|
42
|
-
return (checkSSEOptionResult = result.stdout.includes(" -sse"));
|
|
43
|
-
}
|
|
44
|
-
exports.checkSSEOption = checkSSEOption;
|
|
45
|
-
const listZipLineEqChar = " = ";
|
|
46
|
-
function parseListZipLine(line, buffer) {
|
|
47
|
-
if (buffer.started) {
|
|
48
|
-
if (line === "") {
|
|
49
|
-
if (buffer.opened) {
|
|
50
|
-
const { stream } = buffer;
|
|
51
|
-
buffer.stream = {};
|
|
52
|
-
buffer.opened = false;
|
|
53
|
-
return stream;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const separator = line.indexOf(listZipLineEqChar);
|
|
58
|
-
const key = line.slice(0, separator);
|
|
59
|
-
const value = line.slice(separator + listZipLineEqChar.length);
|
|
60
|
-
buffer.opened = true;
|
|
61
|
-
buffer.stream[key] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (line.startsWith("----------")) {
|
|
65
|
-
buffer.started = true;
|
|
66
|
-
buffer.stream = {};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function listZip(data) {
|
|
70
|
-
const buffer = {};
|
|
71
|
-
await (0, process_1.exec)(data.command ?? "7z", ["l", data.path, "-slt"], {}, {
|
|
72
|
-
log: {
|
|
73
|
-
exec: data.verbose ?? false,
|
|
74
|
-
stderr: data.verbose ?? false,
|
|
75
|
-
stdout: false,
|
|
76
|
-
},
|
|
77
|
-
onExitCodeError: (data, error) => (data.exitCode > 2 ? error : false),
|
|
78
|
-
stdout: {
|
|
79
|
-
parseLines: true,
|
|
80
|
-
onData: async (line) => {
|
|
81
|
-
const stream = parseListZipLine(line, buffer);
|
|
82
|
-
if (stream) {
|
|
83
|
-
await data.onStream?.(stream);
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
exports.listZip = listZip;
|
|
90
|
-
function parseZipLine(line) {
|
|
91
|
-
let matches = null;
|
|
92
|
-
line = line.trim();
|
|
93
|
-
if (!line.length)
|
|
94
|
-
return;
|
|
95
|
-
if ((matches = /^(\d+)% (\d+ )?\+/.exec(line))) {
|
|
96
|
-
const path = line.slice(line.indexOf("+") + 1).trim();
|
|
97
|
-
const progress = Number(matches[1]);
|
|
98
|
-
const files = matches[2] ? Number(matches[2]) : 1;
|
|
99
|
-
return {
|
|
100
|
-
type: "progress",
|
|
101
|
-
data: { progress, path, files },
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else if (line.startsWith("Add new data to archive:")) {
|
|
105
|
-
const [, folders] = /(\d+) folders?/i.exec(line) || [, 0];
|
|
106
|
-
const [, files] = /(\d+) files?/i.exec(line) || [, 0];
|
|
107
|
-
return {
|
|
108
|
-
type: "summary",
|
|
109
|
-
data: {
|
|
110
|
-
folders: Number(folders),
|
|
111
|
-
files: Number(files),
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function zip(data) {
|
|
117
|
-
let summary = {
|
|
118
|
-
folders: 0,
|
|
119
|
-
files: 0,
|
|
120
|
-
};
|
|
121
|
-
await data.onProgress?.({
|
|
122
|
-
current: 0,
|
|
123
|
-
percent: 0,
|
|
124
|
-
total: 0,
|
|
125
|
-
type: "start",
|
|
126
|
-
});
|
|
127
|
-
await (0, process_1.exec)(data.command ?? "7z", [
|
|
128
|
-
"a",
|
|
129
|
-
// https://sourceforge.net/p/sevenzip/bugs/2099/,
|
|
130
|
-
// https://github.com/mcmilk/7-Zip/commit/87ba6f01ba3c5b2ce3186bddfe3d7d880639193c#diff-779d6b1bfa6196b288478f78ca96c4d4c6d7ac6cf8be15a28a20dabc9137ca36L515
|
|
131
|
-
...((await checkSSEOption(data.command)) ? [] : ["-mmt1"]),
|
|
132
|
-
"-bsp1",
|
|
133
|
-
...(data.deleteOnZip ? ["-sdel"] : []),
|
|
134
|
-
(0, path_1.normalize)(data.output),
|
|
135
|
-
...buildArguments(data.filter ?? []),
|
|
136
|
-
...(data.includeList ? [`@${(0, path_1.normalize)(data.includeList)}`] : []),
|
|
137
|
-
...(data.excludeList ? [`-x@${(0, path_1.normalize)(data.excludeList)}`] : []),
|
|
138
|
-
], {
|
|
139
|
-
cwd: data.path,
|
|
140
|
-
}, {
|
|
141
|
-
log: data.verbose ?? false,
|
|
142
|
-
onExitCodeError: (data, error) => (data.exitCode > 2 ? error : false),
|
|
143
|
-
stdout: {
|
|
144
|
-
onData: async (lines) => {
|
|
145
|
-
for (const line of lines.replaceAll("\b", "").split(/\r?\n/)) {
|
|
146
|
-
const stream = parseZipLine(line);
|
|
147
|
-
if (stream) {
|
|
148
|
-
if (stream.type === "summary")
|
|
149
|
-
summary = stream.data;
|
|
150
|
-
if (stream.type === "progress") {
|
|
151
|
-
const current = Math.max(0, stream.data.files - 1);
|
|
152
|
-
await data.onProgress?.({
|
|
153
|
-
total: summary.files,
|
|
154
|
-
current,
|
|
155
|
-
path: stream.data.path,
|
|
156
|
-
percent: stream.data.progress,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
await data.onStream?.(stream);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
await data.onProgress?.({
|
|
166
|
-
total: summary.files,
|
|
167
|
-
current: summary.files,
|
|
168
|
-
percent: 100,
|
|
169
|
-
type: "end",
|
|
170
|
-
});
|
|
171
|
-
return summary;
|
|
172
|
-
}
|
|
173
|
-
exports.zip = zip;
|
|
174
|
-
function parseUnzipLine(line) {
|
|
175
|
-
let matches = null;
|
|
176
|
-
if ((matches = /^\s*(?<percent>\d+)%(?: (?<files>\d+))? \-/.exec(line))) {
|
|
177
|
-
const progress = Number(matches.groups["percent"]);
|
|
178
|
-
const files = matches.groups["files"] ? Number(matches[2]) : 1;
|
|
179
|
-
const path = line.slice(line.indexOf("-") + 1).trim();
|
|
180
|
-
return {
|
|
181
|
-
type: "progress",
|
|
182
|
-
data: { percent: progress, path, files },
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async function unzip(data) {
|
|
187
|
-
let summary = {
|
|
188
|
-
files: 0,
|
|
189
|
-
};
|
|
190
|
-
await data.onProgress?.({
|
|
191
|
-
current: summary.files,
|
|
192
|
-
percent: 0,
|
|
193
|
-
type: "start",
|
|
194
|
-
});
|
|
195
|
-
const result = await (0, process_1.exec)(data.command ?? "7z", [
|
|
196
|
-
"x",
|
|
197
|
-
"-bsp1",
|
|
198
|
-
(0, path_1.normalize)(data.input),
|
|
199
|
-
...buildArguments(data.files ?? []),
|
|
200
|
-
`-o${(0, path_1.normalize)(data.output)}`,
|
|
201
|
-
"-r",
|
|
202
|
-
], {}, {
|
|
203
|
-
log: data.verbose ?? false,
|
|
204
|
-
stderr: { toExitCode: true },
|
|
205
|
-
stdout: {
|
|
206
|
-
...((data.onStream || data.onProgress) && {
|
|
207
|
-
onData: async (chunk) => {
|
|
208
|
-
const lines = chunk.replaceAll("\b", "").split(/\r?\n/);
|
|
209
|
-
for (const line of lines) {
|
|
210
|
-
const stream = parseUnzipLine(line);
|
|
211
|
-
if (stream) {
|
|
212
|
-
if (stream.type === "progress") {
|
|
213
|
-
const current = Math.max(0, stream.data.files - 1);
|
|
214
|
-
summary.files = stream.data.files;
|
|
215
|
-
await data.onProgress?.({
|
|
216
|
-
current,
|
|
217
|
-
percent: stream.data.percent,
|
|
218
|
-
path: stream.data.path,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
await data.onStream?.(stream);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
}),
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
await data.onProgress?.({
|
|
229
|
-
current: summary.files,
|
|
230
|
-
percent: 100,
|
|
231
|
-
type: "end",
|
|
232
|
-
});
|
|
233
|
-
return {
|
|
234
|
-
...result,
|
|
235
|
-
...summary,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
exports.unzip = unzip;
|