@datatruck/cli 0.14.0 → 0.15.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 +3 -15
- package/Action/RestoreAction.js +2 -10
- package/Command/BackupCommand.js +2 -1
- package/Command/BackupSessionsCommand.js +1 -0
- package/Command/RestoreCommand.js +1 -1
- package/Command/RestoreSessionsCommand.js +1 -0
- package/Entity/StateEntityAbstract.d.ts +2 -1
- package/Repository/DatatruckRepository.d.ts +1 -0
- package/Repository/DatatruckRepository.js +116 -96
- package/Repository/RepositoryAbstract.d.ts +10 -5
- package/Repository/ResticRepository.js +34 -17
- package/SessionDriver/ConsoleSessionDriver.d.ts +2 -3
- package/SessionDriver/ConsoleSessionDriver.js +11 -10
- package/SessionManager/BackupSessionManager.d.ts +10 -11
- package/SessionManager/BackupSessionManager.js +24 -5
- package/SessionManager/RestoreSessionManager.d.ts +12 -11
- package/SessionManager/RestoreSessionManager.js +24 -5
- package/SessionManager/SessionManagerAbstract.d.ts +14 -0
- package/SessionManager/SessionManagerAbstract.js +21 -0
- package/Task/GitTask.js +22 -14
- package/Task/MariadbTask.js +9 -4
- package/Task/SqlDumpTaskAbstract.js +30 -10
- package/Task/TaskAbstract.d.ts +10 -5
- package/cli.js +1 -1
- package/migrations/001-initial.sql +12 -6
- package/package.json +1 -1
- package/util/fs-util.d.ts +10 -1
- package/util/fs-util.js +9 -0
- package/util/zip-util.d.ts +23 -5
- package/util/zip-util.js +70 -19
package/util/zip-util.js
CHANGED
|
@@ -73,10 +73,10 @@ async function listZip(data) {
|
|
|
73
73
|
onExitCodeError: (data, error) => (data.exitCode > 2 ? error : false),
|
|
74
74
|
stdout: {
|
|
75
75
|
parseLines: true,
|
|
76
|
-
onData: (line) => {
|
|
76
|
+
onData: async (line) => {
|
|
77
77
|
const stream = parseListZipLine(line, buffer);
|
|
78
78
|
if (stream) {
|
|
79
|
-
data.onStream?.(stream);
|
|
79
|
+
await data.onStream?.(stream);
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
},
|
|
@@ -85,12 +85,13 @@ async function listZip(data) {
|
|
|
85
85
|
exports.listZip = listZip;
|
|
86
86
|
function parseZipLine(line) {
|
|
87
87
|
let matches = null;
|
|
88
|
-
|
|
88
|
+
line = line.trim();
|
|
89
|
+
if (!line.length)
|
|
89
90
|
return;
|
|
90
|
-
if ((matches =
|
|
91
|
+
if ((matches = /^(\d+)% (\d+ )?\+/.exec(line))) {
|
|
91
92
|
const path = line.slice(line.indexOf("+") + 1).trim();
|
|
92
93
|
const progress = Number(matches[1]);
|
|
93
|
-
const files = Number(matches[2]);
|
|
94
|
+
const files = matches[2] ? Number(matches[2]) : 1;
|
|
94
95
|
return {
|
|
95
96
|
type: "progress",
|
|
96
97
|
data: { progress, path, files },
|
|
@@ -109,10 +110,16 @@ function parseZipLine(line) {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
async function zip(data) {
|
|
112
|
-
let
|
|
113
|
+
let summary = {
|
|
113
114
|
folders: 0,
|
|
114
115
|
files: 0,
|
|
115
116
|
};
|
|
117
|
+
await data.onProgress?.({
|
|
118
|
+
current: 0,
|
|
119
|
+
percent: 0,
|
|
120
|
+
total: 0,
|
|
121
|
+
type: "start",
|
|
122
|
+
});
|
|
116
123
|
await (0, process_util_1.exec)(data.command ?? "7z", [
|
|
117
124
|
"a",
|
|
118
125
|
// https://sourceforge.net/p/sevenzip/bugs/2099/,
|
|
@@ -130,17 +137,34 @@ async function zip(data) {
|
|
|
130
137
|
log: data.verbose ?? false,
|
|
131
138
|
onExitCodeError: (data, error) => (data.exitCode > 2 ? error : false),
|
|
132
139
|
stdout: {
|
|
133
|
-
onData: (
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
onData: async (lines) => {
|
|
141
|
+
for (const line of lines.split(/\r?\n/)) {
|
|
142
|
+
const stream = parseZipLine(line);
|
|
143
|
+
if (stream) {
|
|
144
|
+
if (stream.type === "summary")
|
|
145
|
+
summary = stream.data;
|
|
146
|
+
if (stream.type === "progress") {
|
|
147
|
+
const current = Math.max(0, stream.data.files - 1);
|
|
148
|
+
await data.onProgress?.({
|
|
149
|
+
total: summary.files,
|
|
150
|
+
current,
|
|
151
|
+
path: stream.data.path,
|
|
152
|
+
percent: stream.data.progress,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
await data.onStream?.(stream);
|
|
156
|
+
}
|
|
139
157
|
}
|
|
140
158
|
},
|
|
141
159
|
},
|
|
142
160
|
});
|
|
143
|
-
|
|
161
|
+
await data.onProgress?.({
|
|
162
|
+
total: summary.files,
|
|
163
|
+
current: summary.files,
|
|
164
|
+
percent: 100,
|
|
165
|
+
type: "end",
|
|
166
|
+
});
|
|
167
|
+
return summary;
|
|
144
168
|
}
|
|
145
169
|
exports.zip = zip;
|
|
146
170
|
function parseUnzipLine(line) {
|
|
@@ -151,12 +175,20 @@ function parseUnzipLine(line) {
|
|
|
151
175
|
const path = line.slice(line.indexOf("-") + 1).trim();
|
|
152
176
|
return {
|
|
153
177
|
type: "progress",
|
|
154
|
-
data: { progress, path, files },
|
|
178
|
+
data: { percent: progress, path, files },
|
|
155
179
|
};
|
|
156
180
|
}
|
|
157
181
|
}
|
|
158
182
|
async function unzip(data) {
|
|
159
|
-
|
|
183
|
+
let summary = {
|
|
184
|
+
files: 0,
|
|
185
|
+
};
|
|
186
|
+
await data.onProgress?.({
|
|
187
|
+
current: summary.files,
|
|
188
|
+
percent: 0,
|
|
189
|
+
type: "start",
|
|
190
|
+
});
|
|
191
|
+
const result = await (0, process_util_1.exec)(data.command ?? "7z", [
|
|
160
192
|
"x",
|
|
161
193
|
"-bsp1",
|
|
162
194
|
(0, path_1.normalize)(data.input),
|
|
@@ -167,15 +199,34 @@ async function unzip(data) {
|
|
|
167
199
|
log: data.verbose ?? false,
|
|
168
200
|
stderr: { toExitCode: true },
|
|
169
201
|
stdout: {
|
|
170
|
-
...(data.onStream && {
|
|
202
|
+
...((data.onStream || data.onProgress) && {
|
|
171
203
|
parseLines: true,
|
|
172
|
-
onData: (line) => {
|
|
204
|
+
onData: async (line) => {
|
|
173
205
|
const stream = parseUnzipLine(line);
|
|
174
|
-
if (stream)
|
|
175
|
-
|
|
206
|
+
if (stream) {
|
|
207
|
+
if (stream.type === "progress") {
|
|
208
|
+
const current = Math.max(0, stream.data.files - 1);
|
|
209
|
+
summary.files = stream.data.files;
|
|
210
|
+
await data.onProgress?.({
|
|
211
|
+
current,
|
|
212
|
+
percent: stream.data.percent,
|
|
213
|
+
path: stream.data.path,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
await data.onStream?.(stream);
|
|
217
|
+
}
|
|
176
218
|
},
|
|
177
219
|
}),
|
|
178
220
|
},
|
|
179
221
|
});
|
|
222
|
+
await data.onProgress?.({
|
|
223
|
+
current: summary.files,
|
|
224
|
+
percent: 100,
|
|
225
|
+
type: "end",
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
...result,
|
|
229
|
+
...summary,
|
|
230
|
+
};
|
|
180
231
|
}
|
|
181
232
|
exports.unzip = unzip;
|