@datatruck/cli 0.17.1 → 0.18.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 +1 -1
- package/Action/BackupAction.js +14 -14
- package/Action/BackupSessionsAction.d.ts +1 -1
- package/Action/CleanCacheAction.d.ts +1 -1
- package/Action/CleanCacheAction.js +3 -3
- package/Action/ConfigAction.d.ts +1 -1
- package/Action/ConfigAction.js +5 -5
- package/Action/InitAction.d.ts +1 -1
- package/Action/InitAction.js +2 -2
- package/Action/PruneAction.d.ts +1 -1
- package/Action/PruneAction.js +4 -4
- package/Action/RestoreAction.d.ts +1 -1
- package/Action/RestoreAction.js +18 -18
- package/Action/RestoreSessionsAction.d.ts +1 -1
- package/Action/SnapshotsAction.d.ts +1 -1
- package/Action/SnapshotsAction.js +4 -4
- package/Command/BackupCommand.d.ts +2 -2
- package/Command/BackupCommand.js +6 -6
- package/Command/BackupSessionsCommand.d.ts +2 -2
- package/Command/BackupSessionsCommand.js +9 -9
- package/Command/CleanCacheCommand.d.ts +1 -1
- package/Command/CleanCacheCommand.js +2 -2
- package/Command/CommandAbstract.d.ts +3 -3
- package/Command/CommandAbstract.js +2 -2
- package/Command/ConfigCommand.d.ts +2 -2
- package/Command/ConfigCommand.js +8 -8
- package/Command/InitCommand.d.ts +2 -2
- package/Command/InitCommand.js +9 -9
- package/Command/PruneCommand.d.ts +2 -2
- package/Command/PruneCommand.js +10 -10
- package/Command/RestoreCommand.d.ts +2 -2
- package/Command/RestoreCommand.js +6 -6
- package/Command/RestoreSessionsCommand.d.ts +2 -2
- package/Command/RestoreSessionsCommand.js +9 -9
- package/Command/SnapshotsCommand.d.ts +2 -2
- package/Command/SnapshotsCommand.js +9 -9
- package/Entity/StateEntityAbstract.d.ts +1 -1
- package/Repository/DatatruckRepository.d.ts +1 -2
- package/Repository/DatatruckRepository.js +56 -118
- package/Repository/GitRepository.js +23 -23
- package/Repository/RepositoryAbstract.d.ts +1 -1
- package/Repository/RepositoryAbstract.js +2 -2
- package/Repository/ResticRepository.d.ts +1 -1
- package/Repository/ResticRepository.js +27 -27
- package/SessionDriver/ConsoleSessionDriver.d.ts +1 -1
- package/SessionDriver/ConsoleSessionDriver.js +10 -10
- package/SessionDriver/SqliteSessionDriver.js +12 -12
- package/SessionManager/BackupSessionManager.d.ts +2 -2
- package/SessionManager/BackupSessionManager.js +1 -1
- package/SessionManager/RestoreSessionManager.d.ts +2 -2
- package/SessionManager/RestoreSessionManager.js +1 -1
- package/Task/GitTask.js +21 -21
- package/Task/MariadbTask.d.ts +11 -0
- package/Task/MariadbTask.js +240 -58
- package/Task/MssqlTask.js +8 -8
- package/Task/MysqlDumpTask.d.ts +1 -1
- package/Task/MysqlDumpTask.js +13 -13
- package/Task/PostgresqlDumpTask.d.ts +1 -1
- package/Task/PostgresqlDumpTask.js +4 -4
- package/Task/ScriptTask.js +7 -7
- package/Task/SqlDumpTaskAbstract.d.ts +1 -1
- package/Task/SqlDumpTaskAbstract.js +12 -12
- package/Task/TaskAbstract.d.ts +1 -1
- package/Task/TaskAbstract.js +2 -2
- package/cli.js +10 -10
- package/config.schema.json +44 -0
- package/package.json +3 -3
- package/{util → utils}/DataFormat.d.ts +0 -0
- package/{util → utils}/DataFormat.js +0 -0
- package/{util/GitUtil.d.ts → utils/Git.d.ts} +8 -8
- package/{util/GitUtil.js → utils/Git.js} +8 -8
- package/{util → utils}/ObjectVault.d.ts +0 -0
- package/{util → utils}/ObjectVault.js +0 -0
- package/{util/ResticUtil.d.ts → utils/Restic.d.ts} +3 -3
- package/{util/ResticUtil.js → utils/Restic.js} +9 -9
- package/{util/cli-util.d.ts → utils/cli.d.ts} +0 -0
- package/{util/cli-util.js → utils/cli.js} +0 -0
- package/{util/datatruck/config-util.d.ts → utils/datatruck/config.d.ts} +1 -1
- package/{util/datatruck/config-util.js → utils/datatruck/config.js} +10 -10
- package/{util/datatruck/paths-util.d.ts → utils/datatruck/paths.d.ts} +0 -0
- package/{util/datatruck/paths-util.js → utils/datatruck/paths.js} +2 -2
- package/{util/datatruck/snapshot-util.d.ts → utils/datatruck/snapshot.d.ts} +1 -1
- package/{util/datatruck/snapshot-util.js → utils/datatruck/snapshot.js} +4 -4
- package/{util/date-util.d.ts → utils/date.d.ts} +0 -0
- package/{util/date-util.js → utils/date.js} +2 -2
- package/{util/entity-util.d.ts → utils/entity.d.ts} +0 -0
- package/{util/entity-util.js → utils/entity.js} +0 -0
- package/{util/fs-util.d.ts → utils/fs.d.ts} +23 -2
- package/{util/fs-util.js → utils/fs.js} +83 -24
- package/{util/math-util.d.ts → utils/math.d.ts} +0 -0
- package/{util/math-util.js → utils/math.js} +0 -0
- package/{util/object-util.d.ts → utils/object.d.ts} +0 -0
- package/{util/object-util.js → utils/object.js} +0 -0
- package/{util/path-util.d.ts → utils/path.d.ts} +0 -0
- package/{util/path-util.js → utils/path.js} +0 -0
- package/utils/process.d.ts +107 -0
- package/{util/process-util.js → utils/process.js} +168 -28
- package/{util → utils}/progress.d.ts +0 -0
- package/{util → utils}/progress.js +0 -0
- package/{util/string-util.d.ts → utils/string.d.ts} +0 -0
- package/{util/string-util.js → utils/string.js} +0 -0
- package/{util/zip-util.d.ts → utils/zip.d.ts} +0 -0
- package/{util/zip-util.js → utils/zip.js} +5 -5
- package/util/process-util.d.ts +0 -55
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.DatatruckRepository = exports.datatruckPackageRepositoryDefinition = exports.datatruckRepositoryDefinition = exports.datatruckRepositoryName = void 0;
|
|
7
4
|
const AppError_1 = require("../Error/AppError");
|
|
8
5
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const zip_util_1 = require("../util/zip-util");
|
|
6
|
+
const cli_1 = require("../utils/cli");
|
|
7
|
+
const paths_1 = require("../utils/datatruck/paths");
|
|
8
|
+
const fs_1 = require("../utils/fs");
|
|
9
|
+
const string_1 = require("../utils/string");
|
|
10
|
+
const zip_1 = require("../utils/zip");
|
|
15
11
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
16
12
|
const assert_1 = require("assert");
|
|
17
|
-
const
|
|
18
|
-
const fs_1 = require("fs");
|
|
13
|
+
const fs_2 = require("fs");
|
|
19
14
|
const promises_1 = require("fs/promises");
|
|
20
15
|
const micromatch_1 = require("micromatch");
|
|
21
16
|
const path_1 = require("path");
|
|
22
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
23
17
|
const readline_1 = require("readline");
|
|
24
18
|
exports.datatruckRepositoryName = "datatruck";
|
|
25
19
|
exports.datatruckRepositoryDefinition = {
|
|
@@ -90,7 +84,15 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
90
84
|
return (0, path_1.join)(this.config.outPath, snapshotName, packageName) + ".meta.json";
|
|
91
85
|
}
|
|
92
86
|
static async parseMetaData(path) {
|
|
93
|
-
|
|
87
|
+
let contents;
|
|
88
|
+
try {
|
|
89
|
+
contents = await (0, promises_1.readFile)(path);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if ((0, fs_1.isNotFoundError)(error))
|
|
93
|
+
return;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
94
96
|
return JSON.parse(contents.toString());
|
|
95
97
|
}
|
|
96
98
|
static stringifyMetaData(data) {
|
|
@@ -100,67 +102,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
100
102
|
return this.config.outPath;
|
|
101
103
|
}
|
|
102
104
|
async onInit(data) {
|
|
103
|
-
await (0,
|
|
104
|
-
}
|
|
105
|
-
async createFileScanner(options) {
|
|
106
|
-
const object = {
|
|
107
|
-
total: 0,
|
|
108
|
-
current: 0,
|
|
109
|
-
progress: async (description, data) => {
|
|
110
|
-
await options.onProgress({
|
|
111
|
-
relative: {
|
|
112
|
-
description,
|
|
113
|
-
payload: data.path,
|
|
114
|
-
percent: data.percent,
|
|
115
|
-
},
|
|
116
|
-
absolute: {
|
|
117
|
-
total: object.total,
|
|
118
|
-
current: object.current + data.current,
|
|
119
|
-
percent: (0, math_util_1.progressPercent)(object.total, object.current + data.current),
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
if (data.type === "end") {
|
|
123
|
-
object.current += data.current;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
updateProgress: async (end) => {
|
|
127
|
-
const currentTime = perf_hooks_1.performance.now();
|
|
128
|
-
const diff = currentTime - lastTime;
|
|
129
|
-
if (end || diff > 1000) {
|
|
130
|
-
await options.onProgress({
|
|
131
|
-
relative: {
|
|
132
|
-
description: end ? "Scanned files" : "Scanning files",
|
|
133
|
-
payload: object.total.toString(),
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
lastTime = currentTime;
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
start: async (cb) => {
|
|
140
|
-
for await (const entry of (0, fs_util_1.pathIterator)(stream)) {
|
|
141
|
-
if (!options.disableCounting)
|
|
142
|
-
object.total++;
|
|
143
|
-
await object.updateProgress();
|
|
144
|
-
if (cb)
|
|
145
|
-
await cb(entry);
|
|
146
|
-
}
|
|
147
|
-
if (!options.disableEndProgress)
|
|
148
|
-
await object.updateProgress(true);
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
await options.onProgress({
|
|
152
|
-
relative: {
|
|
153
|
-
description: "Scanning files",
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
const stream = fast_glob_1.default.stream(options.glob.include, {
|
|
157
|
-
dot: true,
|
|
158
|
-
markDirectories: true,
|
|
159
|
-
stats: true,
|
|
160
|
-
...options.glob,
|
|
161
|
-
});
|
|
162
|
-
let lastTime = perf_hooks_1.performance.now();
|
|
163
|
-
return object;
|
|
105
|
+
await (0, fs_1.mkdirIfNotExists)(this.config.outPath);
|
|
164
106
|
}
|
|
165
107
|
async onPrune(data) {
|
|
166
108
|
const snapshotName = DatatruckRepository.buildSnapshotName({
|
|
@@ -170,19 +112,19 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
170
112
|
});
|
|
171
113
|
const snapshotPath = (0, path_1.join)(this.config.outPath, snapshotName);
|
|
172
114
|
if (data.options.verbose)
|
|
173
|
-
(0,
|
|
174
|
-
if (await (0,
|
|
115
|
+
(0, cli_1.logExec)(`Deleting ${snapshotPath}`);
|
|
116
|
+
if (await (0, fs_1.checkDir)(snapshotPath))
|
|
175
117
|
await (0, promises_1.rm)(snapshotPath, {
|
|
176
118
|
recursive: true,
|
|
177
119
|
});
|
|
178
120
|
}
|
|
179
121
|
async onSnapshots(data) {
|
|
180
|
-
if (!(await (0,
|
|
122
|
+
if (!(await (0, fs_1.checkDir)(this.config.outPath)))
|
|
181
123
|
throw new Error(`Repository (${this.repository.name}) out path does not exist: ${this.config.outPath}`);
|
|
182
|
-
const snapshotNames = await (0,
|
|
124
|
+
const snapshotNames = await (0, fs_1.readDir)(this.config.outPath);
|
|
183
125
|
const snapshots = [];
|
|
184
|
-
const packagePatterns = (0,
|
|
185
|
-
const taskPatterns = (0,
|
|
126
|
+
const packagePatterns = (0, string_1.makePathPatterns)(data.options.packageNames);
|
|
127
|
+
const taskPatterns = (0, string_1.makePathPatterns)(data.options.packageTaskNames);
|
|
186
128
|
for (const snapshotName of snapshotNames) {
|
|
187
129
|
const snapshotNameData = DatatruckRepository.parseSnapshotName(snapshotName);
|
|
188
130
|
if (!snapshotNameData)
|
|
@@ -195,7 +137,9 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
195
137
|
continue;
|
|
196
138
|
const metaPath = (0, path_1.join)(this.config.outPath, snapshotName, "meta.json");
|
|
197
139
|
const meta = await DatatruckRepository.parseMetaData(metaPath);
|
|
198
|
-
if (
|
|
140
|
+
if (!meta)
|
|
141
|
+
continue;
|
|
142
|
+
if (taskPatterns && !(0, string_1.checkMatch)(meta.task, taskPatterns))
|
|
199
143
|
continue;
|
|
200
144
|
if (data.options.ids &&
|
|
201
145
|
!data.options.ids.some((id) => meta.id.startsWith(id)))
|
|
@@ -245,25 +189,25 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
245
189
|
const sourcePath = data.targetPath ?? pkg.path;
|
|
246
190
|
(0, assert_1.ok)(sourcePath);
|
|
247
191
|
const compress = this.normalizeCompressConfig(data.packageConfig);
|
|
248
|
-
const include = await (0,
|
|
192
|
+
const include = await (0, paths_1.parsePaths)(pkg.include ?? ["**"], {
|
|
249
193
|
cwd: sourcePath,
|
|
250
194
|
verbose: data.options.verbose,
|
|
251
195
|
});
|
|
252
196
|
const exclude = pkg.exclude
|
|
253
|
-
? await (0,
|
|
197
|
+
? await (0, paths_1.parsePaths)(pkg.exclude, {
|
|
254
198
|
cwd: sourcePath,
|
|
255
199
|
verbose: data.options.verbose,
|
|
256
200
|
})
|
|
257
201
|
: undefined;
|
|
258
202
|
const packs = compress?.packs || [];
|
|
259
203
|
const tmpDir = await this.mkTmpDir("path-lists");
|
|
260
|
-
const unpackedStream = (0,
|
|
261
|
-
const singlePackStream = (0,
|
|
262
|
-
const packStreams = Array.from({ length: packs.length }).map((v, i) => (0,
|
|
204
|
+
const unpackedStream = (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, "unpacked.txt"));
|
|
205
|
+
const singlePackStream = (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, "single-pack.txt"));
|
|
206
|
+
const packStreams = Array.from({ length: packs.length }).map((v, i) => (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, `pack-${i}.txt`)));
|
|
263
207
|
const streams = [unpackedStream, singlePackStream, ...packStreams];
|
|
264
208
|
if (data.options.verbose)
|
|
265
|
-
(0,
|
|
266
|
-
const scanner = await
|
|
209
|
+
(0, cli_1.logExec)(`Writing file lists in ${tmpDir}`);
|
|
210
|
+
const scanner = await (0, fs_1.createFileScanner)({
|
|
267
211
|
glob: {
|
|
268
212
|
include,
|
|
269
213
|
cwd: sourcePath,
|
|
@@ -274,7 +218,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
274
218
|
disableCounting: true,
|
|
275
219
|
});
|
|
276
220
|
await Promise.all([
|
|
277
|
-
...streams.map((p) => (0,
|
|
221
|
+
...streams.map((p) => (0, fs_1.waitForClose)(p)),
|
|
278
222
|
(async () => {
|
|
279
223
|
await scanner.start(async (entry) => {
|
|
280
224
|
const pathSubject = entry.stats.isDirectory()
|
|
@@ -283,7 +227,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
283
227
|
let stream = unpackedStream;
|
|
284
228
|
let successPackIndex;
|
|
285
229
|
for (const [packIndex, pack] of packs.entries()) {
|
|
286
|
-
if ((0,
|
|
230
|
+
if ((0, string_1.checkPath)(pathSubject, pack.include, pack.exclude)) {
|
|
287
231
|
stream = pack.onePackByResult
|
|
288
232
|
? singlePackStream
|
|
289
233
|
: packStreams[packIndex];
|
|
@@ -296,7 +240,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
296
240
|
const isSinglePackStream = stream === singlePackStream;
|
|
297
241
|
const include = isPackStream
|
|
298
242
|
? entry.stats.isDirectory()
|
|
299
|
-
? await (0,
|
|
243
|
+
? await (0, fs_1.isEmptyDir)((0, path_1.join)(sourcePath, entry.path))
|
|
300
244
|
: true
|
|
301
245
|
: true;
|
|
302
246
|
if (include) {
|
|
@@ -322,8 +266,8 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
322
266
|
await (0, promises_1.copyFile)(unpackedStream.path, (0, path_1.join)(outPath, "permissions.txt"));
|
|
323
267
|
// Non pack
|
|
324
268
|
if (data.options.verbose)
|
|
325
|
-
(0,
|
|
326
|
-
await (0,
|
|
269
|
+
(0, cli_1.logExec)(`Copying files from ${unpackedStream.path.toString()} to ${unpackedPath}`);
|
|
270
|
+
await (0, fs_1.cpy)({
|
|
327
271
|
input: {
|
|
328
272
|
type: "pathList",
|
|
329
273
|
path: unpackedStream.path.toString(),
|
|
@@ -336,7 +280,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
336
280
|
});
|
|
337
281
|
// Single pack
|
|
338
282
|
const singleReader = (0, readline_1.createInterface)({
|
|
339
|
-
input: (0,
|
|
283
|
+
input: (0, fs_2.createReadStream)(singlePackStream.path),
|
|
340
284
|
});
|
|
341
285
|
for await (const line of singleReader) {
|
|
342
286
|
let [packPath, packIndex] = line.split(":");
|
|
@@ -347,33 +291,29 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
347
291
|
`-${encodeURIComponent(packPath.replace(/[\\/]/g, "-"))}` +
|
|
348
292
|
`.zip`).slice(0, 255);
|
|
349
293
|
const target = (0, path_1.join)(outPath, outBasename);
|
|
350
|
-
await (0,
|
|
294
|
+
await (0, zip_1.zip)({
|
|
351
295
|
path: pkg.path,
|
|
352
296
|
output: target,
|
|
353
297
|
filter: [{ patterns: [packPath] }],
|
|
354
298
|
verbose: data.options.verbose,
|
|
355
|
-
onProgress: async (progress) => await scanner.progress(
|
|
356
|
-
? "Starting compressing"
|
|
357
|
-
: "Compressing file", progress),
|
|
299
|
+
onProgress: async (progress) => await scanner.progress("Compressing file", progress),
|
|
358
300
|
});
|
|
359
301
|
}
|
|
360
302
|
// Packs
|
|
361
303
|
for (const [packIndex, packStream] of packStreams.entries()) {
|
|
362
304
|
const pack = packs[packIndex];
|
|
363
305
|
const target = (0, path_1.join)(outPath, `pack-${packIndex}${pack.name ? `-${pack.name}` : ""}.zip`);
|
|
364
|
-
await (0,
|
|
306
|
+
await (0, zip_1.zip)({
|
|
365
307
|
path: sourcePath,
|
|
366
308
|
output: target,
|
|
367
309
|
includeList: packStream.path.toString(),
|
|
368
310
|
verbose: data.options.verbose,
|
|
369
|
-
onProgress: async (progress) => await scanner.progress(
|
|
370
|
-
? "Starting compressing"
|
|
371
|
-
: "Compressing file", progress),
|
|
311
|
+
onProgress: async (progress) => await scanner.progress("Compressing file", progress),
|
|
372
312
|
});
|
|
373
313
|
}
|
|
374
314
|
// Meta
|
|
375
315
|
const metaPath = `${outPath}/meta.json`;
|
|
376
|
-
const nodePkg = (0,
|
|
316
|
+
const nodePkg = (0, fs_1.parsePackageFile)();
|
|
377
317
|
const meta = {
|
|
378
318
|
id: data.snapshot.id,
|
|
379
319
|
date: data.snapshot.date,
|
|
@@ -381,10 +321,10 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
381
321
|
package: data.package.name,
|
|
382
322
|
task: data.package.task?.name,
|
|
383
323
|
version: nodePkg.version,
|
|
384
|
-
size: await (0,
|
|
324
|
+
size: await (0, fs_1.fastFolderSizeAsync)(outPath),
|
|
385
325
|
};
|
|
386
326
|
if (data.options.verbose)
|
|
387
|
-
(0,
|
|
327
|
+
(0, cli_1.logExec)(`Writing metadata into ${metaPath}`);
|
|
388
328
|
await (0, promises_1.writeFile)(metaPath, DatatruckRepository.stringifyMetaData(meta));
|
|
389
329
|
}
|
|
390
330
|
async onCopyBackup(data) {
|
|
@@ -396,9 +336,9 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
396
336
|
const sourcePath = (0, path_1.resolve)((0, path_1.join)(this.config.outPath, snapshotName));
|
|
397
337
|
const targetPath = (0, path_1.resolve)((0, path_1.join)(data.mirrorRepositoryConfig.outPath, snapshotName));
|
|
398
338
|
if (data.options.verbose)
|
|
399
|
-
(0,
|
|
339
|
+
(0, cli_1.logExec)(`Copying backup files to ${targetPath}`);
|
|
400
340
|
await (0, promises_1.mkdir)(targetPath);
|
|
401
|
-
const scanner = await
|
|
341
|
+
const scanner = await (0, fs_1.createFileScanner)({
|
|
402
342
|
glob: {
|
|
403
343
|
include: ["**/*"],
|
|
404
344
|
cwd: sourcePath,
|
|
@@ -406,7 +346,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
406
346
|
onProgress: data.onProgress,
|
|
407
347
|
});
|
|
408
348
|
await scanner.start();
|
|
409
|
-
await (0,
|
|
349
|
+
await (0, fs_1.cpy)({
|
|
410
350
|
input: {
|
|
411
351
|
type: "glob",
|
|
412
352
|
sourcePath,
|
|
@@ -432,7 +372,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
432
372
|
packageName: data.package.name,
|
|
433
373
|
});
|
|
434
374
|
const sourcePath = (0, path_1.join)(this.config.outPath, snapshotName);
|
|
435
|
-
const scanner = await
|
|
375
|
+
const scanner = await (0, fs_1.createFileScanner)({
|
|
436
376
|
glob: {
|
|
437
377
|
include: ["unpacked/**/*"],
|
|
438
378
|
cwd: sourcePath,
|
|
@@ -449,7 +389,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
449
389
|
await scanner.updateProgress();
|
|
450
390
|
}
|
|
451
391
|
else if (dirent.name.endsWith(".zip")) {
|
|
452
|
-
await (0,
|
|
392
|
+
await (0, zip_1.listZip)({
|
|
453
393
|
path,
|
|
454
394
|
verbose: data.options.verbose,
|
|
455
395
|
onStream: async (item) => {
|
|
@@ -463,8 +403,8 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
463
403
|
}
|
|
464
404
|
await scanner.updateProgress(true);
|
|
465
405
|
if (data.options.verbose)
|
|
466
|
-
(0,
|
|
467
|
-
await (0,
|
|
406
|
+
(0, cli_1.logExec)(`Copying files to ${restorePath}`);
|
|
407
|
+
await (0, fs_1.cpy)({
|
|
468
408
|
input: {
|
|
469
409
|
type: "glob",
|
|
470
410
|
sourcePath: (0, path_1.join)(sourcePath, "unpacked"),
|
|
@@ -478,24 +418,22 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
478
418
|
const path = (0, path_1.join)(sourcePath, dirent.name);
|
|
479
419
|
if (dirent.name === "permissions.txt") {
|
|
480
420
|
if (data.options.verbose)
|
|
481
|
-
(0,
|
|
421
|
+
(0, cli_1.logExec)(`Applying permissions (${path})`);
|
|
482
422
|
await scanner.progress("Applying permissions", {
|
|
483
423
|
current: 0,
|
|
484
424
|
});
|
|
485
|
-
await (0,
|
|
425
|
+
await (0, fs_1.applyPermissions)(restorePath, path);
|
|
486
426
|
await scanner.progress("Permissions applied", {
|
|
487
427
|
current: 1,
|
|
488
428
|
type: "end",
|
|
489
429
|
});
|
|
490
430
|
}
|
|
491
431
|
else if (dirent.name.endsWith(".zip")) {
|
|
492
|
-
await (0,
|
|
432
|
+
await (0, zip_1.unzip)({
|
|
493
433
|
input: path,
|
|
494
434
|
output: restorePath,
|
|
495
435
|
verbose: data.options.verbose,
|
|
496
|
-
onProgress: async (progress) => await scanner.progress(
|
|
497
|
-
? "Starting extracting"
|
|
498
|
-
: "Extracting file", progress),
|
|
436
|
+
onProgress: async (progress) => await scanner.progress("Extracting file", progress),
|
|
499
437
|
});
|
|
500
438
|
}
|
|
501
439
|
}
|
|
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GitRepository = exports.gitPackageRepositoryDefinition = exports.gitRepositoryDefinition = exports.gitRepositoryName = void 0;
|
|
7
7
|
const AppError_1 = require("../Error/AppError");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
8
|
+
const Git_1 = require("../utils/Git");
|
|
9
|
+
const cli_1 = require("../utils/cli");
|
|
10
|
+
const paths_1 = require("../utils/datatruck/paths");
|
|
11
|
+
const fs_1 = require("../utils/fs");
|
|
12
|
+
const string_1 = require("../utils/string");
|
|
13
13
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
14
14
|
const assert_1 = require("assert");
|
|
15
15
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
@@ -56,8 +56,8 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
56
56
|
return `${GitRepository.refPrefix}/${packageName}`;
|
|
57
57
|
}
|
|
58
58
|
async onInit(data) {
|
|
59
|
-
const git = new
|
|
60
|
-
dir: (0,
|
|
59
|
+
const git = new Git_1.Git({
|
|
60
|
+
dir: (0, fs_1.tmpDir)(GitRepository.name + "-snapshot"),
|
|
61
61
|
log: data.options.verbose,
|
|
62
62
|
});
|
|
63
63
|
if (await git.canBeInit(this.config.repo)) {
|
|
@@ -70,7 +70,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
70
70
|
repo: this.config.repo,
|
|
71
71
|
});
|
|
72
72
|
if (!existsBranch) {
|
|
73
|
-
await (0,
|
|
73
|
+
await (0, fs_1.mkdirIfNotExists)(git.options.dir);
|
|
74
74
|
await git.clone({
|
|
75
75
|
repo: this.config.repo,
|
|
76
76
|
});
|
|
@@ -83,7 +83,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
async onPrune(data) {
|
|
86
|
-
const git = new
|
|
86
|
+
const git = new Git_1.Git({
|
|
87
87
|
dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
|
|
88
88
|
log: data.options.verbose,
|
|
89
89
|
});
|
|
@@ -106,12 +106,12 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
106
106
|
await git.exec(["push", "--delete", "origin", data.snapshot.originalId]);
|
|
107
107
|
}
|
|
108
108
|
async onSnapshots(data) {
|
|
109
|
-
const git = new
|
|
109
|
+
const git = new Git_1.Git({
|
|
110
110
|
dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
|
|
111
111
|
log: data.options.verbose,
|
|
112
112
|
});
|
|
113
|
-
const pkgPatterns = (0,
|
|
114
|
-
const pkgTaskPatterns = (0,
|
|
113
|
+
const pkgPatterns = (0, string_1.makePathPatterns)(data.options.packageNames);
|
|
114
|
+
const pkgTaskPatterns = (0, string_1.makePathPatterns)(data.options.packageTaskNames);
|
|
115
115
|
await git.clone({ repo: this.config.repo });
|
|
116
116
|
const tagNames = data.options.ids?.map((id) => `${GitRepository.refPrefix}/*/${id}*`) || [`${GitRepository.refPrefix}/*`];
|
|
117
117
|
const tags = await git.getTags(tagNames);
|
|
@@ -124,7 +124,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
124
124
|
return result;
|
|
125
125
|
if (pkgPatterns && !(0, micromatch_1.isMatch)(parsedTag.package, pkgPatterns))
|
|
126
126
|
return result;
|
|
127
|
-
if (pkgTaskPatterns && !(0,
|
|
127
|
+
if (pkgTaskPatterns && !(0, string_1.checkMatch)(parsedTag.task, pkgTaskPatterns))
|
|
128
128
|
return result;
|
|
129
129
|
if (data.options.tags &&
|
|
130
130
|
!parsedTag.tags.some((value) => data.options.tags?.includes(value)))
|
|
@@ -146,16 +146,16 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
146
146
|
const pkg = data.package;
|
|
147
147
|
const sourcePath = data.targetPath ?? pkg.path;
|
|
148
148
|
(0, assert_1.ok)(typeof sourcePath === "string");
|
|
149
|
-
if (!(await (0,
|
|
149
|
+
if (!(await (0, fs_1.existsDir)(sourcePath)))
|
|
150
150
|
throw new AppError_1.AppError(`Package path not exists: ${sourcePath}`);
|
|
151
151
|
const tmpPath = await this.mkTmpDir(GitRepository.name + "-backup");
|
|
152
152
|
const branchName = GitRepository.buildBranchName(data.package.name);
|
|
153
|
-
const git = new
|
|
153
|
+
const git = new Git_1.Git({
|
|
154
154
|
dir: tmpPath,
|
|
155
155
|
log: data.options.verbose,
|
|
156
156
|
});
|
|
157
157
|
if (data.options.verbose)
|
|
158
|
-
(0,
|
|
158
|
+
(0, cli_1.logExec)("cd", [tmpPath]);
|
|
159
159
|
await git.clone({
|
|
160
160
|
repo: this.config.repo,
|
|
161
161
|
});
|
|
@@ -165,12 +165,12 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
165
165
|
});
|
|
166
166
|
await git.removeAll();
|
|
167
167
|
const createdPaths = [];
|
|
168
|
-
const include = await (0,
|
|
168
|
+
const include = await (0, paths_1.parsePaths)(pkg.include ?? ["**"], {
|
|
169
169
|
cwd: sourcePath,
|
|
170
170
|
verbose: data.options.verbose,
|
|
171
171
|
});
|
|
172
172
|
const exclude = pkg.exclude
|
|
173
|
-
? await (0,
|
|
173
|
+
? await (0, paths_1.parsePaths)(pkg.exclude, {
|
|
174
174
|
cwd: sourcePath,
|
|
175
175
|
verbose: data.options.verbose,
|
|
176
176
|
})
|
|
@@ -199,7 +199,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
199
199
|
await git.exec(["add", "--verbose", "."]);
|
|
200
200
|
if (await git.haveChanges())
|
|
201
201
|
await git.exec(["commit", "-m", data.snapshot.id]);
|
|
202
|
-
const nodePkg = (0,
|
|
202
|
+
const nodePkg = (0, fs_1.parsePackageFile)();
|
|
203
203
|
const meta = GitRepository.buildSnapshotTag({
|
|
204
204
|
id: data.snapshot.id,
|
|
205
205
|
shortId: data.snapshot.id.slice(0, 8),
|
|
@@ -208,8 +208,8 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
208
208
|
package: data.package.name,
|
|
209
209
|
task: data.package.task?.name,
|
|
210
210
|
version: nodePkg.version,
|
|
211
|
-
size: ((await (0,
|
|
212
|
-
(await (0,
|
|
211
|
+
size: ((await (0, fs_1.fastFolderSizeAsync)(tmpPath)) -
|
|
212
|
+
(await (0, fs_1.fastFolderSizeAsync)((0, path_1.join)(tmpPath, ".git")))).toString(),
|
|
213
213
|
});
|
|
214
214
|
await git.addTag(meta.name, meta.message);
|
|
215
215
|
await git.push({ branchName });
|
|
@@ -228,12 +228,12 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
228
228
|
id: data.snapshot.id,
|
|
229
229
|
package: data.package.name,
|
|
230
230
|
});
|
|
231
|
-
const git = new
|
|
231
|
+
const git = new Git_1.Git({
|
|
232
232
|
dir: restorePath,
|
|
233
233
|
log: data.options.verbose,
|
|
234
234
|
});
|
|
235
235
|
if (data.options.verbose)
|
|
236
|
-
(0,
|
|
236
|
+
(0, cli_1.logExec)("cd", [restorePath]);
|
|
237
237
|
await git.clone({
|
|
238
238
|
repo: this.config.repo,
|
|
239
239
|
branch: tagName,
|
|
@@ -4,7 +4,7 @@ import type { RestoreActionOptionsType } from "../Action/RestoreAction";
|
|
|
4
4
|
import type { SnapshotExtendedType, SnapshotsActionOptionsType } from "../Action/SnapshotsAction";
|
|
5
5
|
import type { PackageConfigType } from "../Config/PackageConfig";
|
|
6
6
|
import type { RepositoryConfigType } from "../Config/RepositoryConfig";
|
|
7
|
-
import { Progress } from "../
|
|
7
|
+
import { Progress } from "../utils/progress";
|
|
8
8
|
export type SnapshotType = {
|
|
9
9
|
id: string;
|
|
10
10
|
date: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RepositoryAbstract = exports.SnapshotTagEnum = void 0;
|
|
4
|
-
const
|
|
4
|
+
const fs_1 = require("../utils/fs");
|
|
5
5
|
var SnapshotTagEnum;
|
|
6
6
|
(function (SnapshotTagEnum) {
|
|
7
7
|
SnapshotTagEnum["ID"] = "id";
|
|
@@ -20,7 +20,7 @@ class RepositoryAbstract {
|
|
|
20
20
|
this.config = repository.config;
|
|
21
21
|
}
|
|
22
22
|
async mkTmpDir(prefix, id) {
|
|
23
|
-
const dir = await (0,
|
|
23
|
+
const dir = await (0, fs_1.mkTmpDir)(prefix, id);
|
|
24
24
|
this.tmpDirs.push(dir);
|
|
25
25
|
return dir;
|
|
26
26
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RepositoryType } from "../
|
|
1
|
+
import { RepositoryType } from "../utils/Restic";
|
|
2
2
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
4
|
export type ResticRepositoryConfigType = {
|