@datatruck/cli 0.17.1 → 0.17.2
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 -1
- package/Repository/DatatruckRepository.js +56 -52
- 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.js +11 -11
- 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/package.json +1 -1
- 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} +0 -0
- 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} +0 -0
- package/{util/fs-util.js → utils/fs.js} +17 -17
- 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/{util/process-util.d.ts → utils/process.d.ts} +0 -0
- package/{util/process-util.js → utils/process.js} +13 -13
- 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
|
@@ -6,16 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DatatruckRepository = exports.datatruckPackageRepositoryDefinition = exports.datatruckRepositoryDefinition = exports.datatruckRepositoryName = void 0;
|
|
7
7
|
const AppError_1 = require("../Error/AppError");
|
|
8
8
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
9
|
+
const cli_1 = require("../utils/cli");
|
|
10
|
+
const paths_1 = require("../utils/datatruck/paths");
|
|
11
|
+
const fs_1 = require("../utils/fs");
|
|
12
|
+
const math_1 = require("../utils/math");
|
|
13
|
+
const string_1 = require("../utils/string");
|
|
14
|
+
const zip_1 = require("../utils/zip");
|
|
15
15
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
16
16
|
const assert_1 = require("assert");
|
|
17
17
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
18
|
-
const
|
|
18
|
+
const fs_2 = require("fs");
|
|
19
19
|
const promises_1 = require("fs/promises");
|
|
20
20
|
const micromatch_1 = require("micromatch");
|
|
21
21
|
const path_1 = require("path");
|
|
@@ -90,7 +90,15 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
90
90
|
return (0, path_1.join)(this.config.outPath, snapshotName, packageName) + ".meta.json";
|
|
91
91
|
}
|
|
92
92
|
static async parseMetaData(path) {
|
|
93
|
-
|
|
93
|
+
let contents;
|
|
94
|
+
try {
|
|
95
|
+
contents = await (0, promises_1.readFile)(path);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if ((0, fs_1.isNotFoundError)(error))
|
|
99
|
+
return;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
94
102
|
return JSON.parse(contents.toString());
|
|
95
103
|
}
|
|
96
104
|
static stringifyMetaData(data) {
|
|
@@ -100,7 +108,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
100
108
|
return this.config.outPath;
|
|
101
109
|
}
|
|
102
110
|
async onInit(data) {
|
|
103
|
-
await (0,
|
|
111
|
+
await (0, fs_1.mkdirIfNotExists)(this.config.outPath);
|
|
104
112
|
}
|
|
105
113
|
async createFileScanner(options) {
|
|
106
114
|
const object = {
|
|
@@ -116,7 +124,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
116
124
|
absolute: {
|
|
117
125
|
total: object.total,
|
|
118
126
|
current: object.current + data.current,
|
|
119
|
-
percent: (0,
|
|
127
|
+
percent: (0, math_1.progressPercent)(object.total, object.current + data.current),
|
|
120
128
|
},
|
|
121
129
|
});
|
|
122
130
|
if (data.type === "end") {
|
|
@@ -137,7 +145,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
137
145
|
}
|
|
138
146
|
},
|
|
139
147
|
start: async (cb) => {
|
|
140
|
-
for await (const entry of (0,
|
|
148
|
+
for await (const entry of (0, fs_1.pathIterator)(stream)) {
|
|
141
149
|
if (!options.disableCounting)
|
|
142
150
|
object.total++;
|
|
143
151
|
await object.updateProgress();
|
|
@@ -170,19 +178,19 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
170
178
|
});
|
|
171
179
|
const snapshotPath = (0, path_1.join)(this.config.outPath, snapshotName);
|
|
172
180
|
if (data.options.verbose)
|
|
173
|
-
(0,
|
|
174
|
-
if (await (0,
|
|
181
|
+
(0, cli_1.logExec)(`Deleting ${snapshotPath}`);
|
|
182
|
+
if (await (0, fs_1.checkDir)(snapshotPath))
|
|
175
183
|
await (0, promises_1.rm)(snapshotPath, {
|
|
176
184
|
recursive: true,
|
|
177
185
|
});
|
|
178
186
|
}
|
|
179
187
|
async onSnapshots(data) {
|
|
180
|
-
if (!(await (0,
|
|
188
|
+
if (!(await (0, fs_1.checkDir)(this.config.outPath)))
|
|
181
189
|
throw new Error(`Repository (${this.repository.name}) out path does not exist: ${this.config.outPath}`);
|
|
182
|
-
const snapshotNames = await (0,
|
|
190
|
+
const snapshotNames = await (0, fs_1.readDir)(this.config.outPath);
|
|
183
191
|
const snapshots = [];
|
|
184
|
-
const packagePatterns = (0,
|
|
185
|
-
const taskPatterns = (0,
|
|
192
|
+
const packagePatterns = (0, string_1.makePathPatterns)(data.options.packageNames);
|
|
193
|
+
const taskPatterns = (0, string_1.makePathPatterns)(data.options.packageTaskNames);
|
|
186
194
|
for (const snapshotName of snapshotNames) {
|
|
187
195
|
const snapshotNameData = DatatruckRepository.parseSnapshotName(snapshotName);
|
|
188
196
|
if (!snapshotNameData)
|
|
@@ -195,7 +203,9 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
195
203
|
continue;
|
|
196
204
|
const metaPath = (0, path_1.join)(this.config.outPath, snapshotName, "meta.json");
|
|
197
205
|
const meta = await DatatruckRepository.parseMetaData(metaPath);
|
|
198
|
-
if (
|
|
206
|
+
if (!meta)
|
|
207
|
+
continue;
|
|
208
|
+
if (taskPatterns && !(0, string_1.checkMatch)(meta.task, taskPatterns))
|
|
199
209
|
continue;
|
|
200
210
|
if (data.options.ids &&
|
|
201
211
|
!data.options.ids.some((id) => meta.id.startsWith(id)))
|
|
@@ -245,24 +255,24 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
245
255
|
const sourcePath = data.targetPath ?? pkg.path;
|
|
246
256
|
(0, assert_1.ok)(sourcePath);
|
|
247
257
|
const compress = this.normalizeCompressConfig(data.packageConfig);
|
|
248
|
-
const include = await (0,
|
|
258
|
+
const include = await (0, paths_1.parsePaths)(pkg.include ?? ["**"], {
|
|
249
259
|
cwd: sourcePath,
|
|
250
260
|
verbose: data.options.verbose,
|
|
251
261
|
});
|
|
252
262
|
const exclude = pkg.exclude
|
|
253
|
-
? await (0,
|
|
263
|
+
? await (0, paths_1.parsePaths)(pkg.exclude, {
|
|
254
264
|
cwd: sourcePath,
|
|
255
265
|
verbose: data.options.verbose,
|
|
256
266
|
})
|
|
257
267
|
: undefined;
|
|
258
268
|
const packs = compress?.packs || [];
|
|
259
269
|
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,
|
|
270
|
+
const unpackedStream = (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, "unpacked.txt"));
|
|
271
|
+
const singlePackStream = (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, "single-pack.txt"));
|
|
272
|
+
const packStreams = Array.from({ length: packs.length }).map((v, i) => (0, fs_2.createWriteStream)((0, path_1.join)(tmpDir, `pack-${i}.txt`)));
|
|
263
273
|
const streams = [unpackedStream, singlePackStream, ...packStreams];
|
|
264
274
|
if (data.options.verbose)
|
|
265
|
-
(0,
|
|
275
|
+
(0, cli_1.logExec)(`Writing file lists in ${tmpDir}`);
|
|
266
276
|
const scanner = await this.createFileScanner({
|
|
267
277
|
glob: {
|
|
268
278
|
include,
|
|
@@ -274,7 +284,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
274
284
|
disableCounting: true,
|
|
275
285
|
});
|
|
276
286
|
await Promise.all([
|
|
277
|
-
...streams.map((p) => (0,
|
|
287
|
+
...streams.map((p) => (0, fs_1.waitForClose)(p)),
|
|
278
288
|
(async () => {
|
|
279
289
|
await scanner.start(async (entry) => {
|
|
280
290
|
const pathSubject = entry.stats.isDirectory()
|
|
@@ -283,7 +293,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
283
293
|
let stream = unpackedStream;
|
|
284
294
|
let successPackIndex;
|
|
285
295
|
for (const [packIndex, pack] of packs.entries()) {
|
|
286
|
-
if ((0,
|
|
296
|
+
if ((0, string_1.checkPath)(pathSubject, pack.include, pack.exclude)) {
|
|
287
297
|
stream = pack.onePackByResult
|
|
288
298
|
? singlePackStream
|
|
289
299
|
: packStreams[packIndex];
|
|
@@ -296,7 +306,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
296
306
|
const isSinglePackStream = stream === singlePackStream;
|
|
297
307
|
const include = isPackStream
|
|
298
308
|
? entry.stats.isDirectory()
|
|
299
|
-
? await (0,
|
|
309
|
+
? await (0, fs_1.isEmptyDir)((0, path_1.join)(sourcePath, entry.path))
|
|
300
310
|
: true
|
|
301
311
|
: true;
|
|
302
312
|
if (include) {
|
|
@@ -322,8 +332,8 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
322
332
|
await (0, promises_1.copyFile)(unpackedStream.path, (0, path_1.join)(outPath, "permissions.txt"));
|
|
323
333
|
// Non pack
|
|
324
334
|
if (data.options.verbose)
|
|
325
|
-
(0,
|
|
326
|
-
await (0,
|
|
335
|
+
(0, cli_1.logExec)(`Copying files from ${unpackedStream.path.toString()} to ${unpackedPath}`);
|
|
336
|
+
await (0, fs_1.cpy)({
|
|
327
337
|
input: {
|
|
328
338
|
type: "pathList",
|
|
329
339
|
path: unpackedStream.path.toString(),
|
|
@@ -336,7 +346,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
336
346
|
});
|
|
337
347
|
// Single pack
|
|
338
348
|
const singleReader = (0, readline_1.createInterface)({
|
|
339
|
-
input: (0,
|
|
349
|
+
input: (0, fs_2.createReadStream)(singlePackStream.path),
|
|
340
350
|
});
|
|
341
351
|
for await (const line of singleReader) {
|
|
342
352
|
let [packPath, packIndex] = line.split(":");
|
|
@@ -347,33 +357,29 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
347
357
|
`-${encodeURIComponent(packPath.replace(/[\\/]/g, "-"))}` +
|
|
348
358
|
`.zip`).slice(0, 255);
|
|
349
359
|
const target = (0, path_1.join)(outPath, outBasename);
|
|
350
|
-
await (0,
|
|
360
|
+
await (0, zip_1.zip)({
|
|
351
361
|
path: pkg.path,
|
|
352
362
|
output: target,
|
|
353
363
|
filter: [{ patterns: [packPath] }],
|
|
354
364
|
verbose: data.options.verbose,
|
|
355
|
-
onProgress: async (progress) => await scanner.progress(
|
|
356
|
-
? "Starting compressing"
|
|
357
|
-
: "Compressing file", progress),
|
|
365
|
+
onProgress: async (progress) => await scanner.progress("Compressing file", progress),
|
|
358
366
|
});
|
|
359
367
|
}
|
|
360
368
|
// Packs
|
|
361
369
|
for (const [packIndex, packStream] of packStreams.entries()) {
|
|
362
370
|
const pack = packs[packIndex];
|
|
363
371
|
const target = (0, path_1.join)(outPath, `pack-${packIndex}${pack.name ? `-${pack.name}` : ""}.zip`);
|
|
364
|
-
await (0,
|
|
372
|
+
await (0, zip_1.zip)({
|
|
365
373
|
path: sourcePath,
|
|
366
374
|
output: target,
|
|
367
375
|
includeList: packStream.path.toString(),
|
|
368
376
|
verbose: data.options.verbose,
|
|
369
|
-
onProgress: async (progress) => await scanner.progress(
|
|
370
|
-
? "Starting compressing"
|
|
371
|
-
: "Compressing file", progress),
|
|
377
|
+
onProgress: async (progress) => await scanner.progress("Compressing file", progress),
|
|
372
378
|
});
|
|
373
379
|
}
|
|
374
380
|
// Meta
|
|
375
381
|
const metaPath = `${outPath}/meta.json`;
|
|
376
|
-
const nodePkg = (0,
|
|
382
|
+
const nodePkg = (0, fs_1.parsePackageFile)();
|
|
377
383
|
const meta = {
|
|
378
384
|
id: data.snapshot.id,
|
|
379
385
|
date: data.snapshot.date,
|
|
@@ -381,10 +387,10 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
381
387
|
package: data.package.name,
|
|
382
388
|
task: data.package.task?.name,
|
|
383
389
|
version: nodePkg.version,
|
|
384
|
-
size: await (0,
|
|
390
|
+
size: await (0, fs_1.fastFolderSizeAsync)(outPath),
|
|
385
391
|
};
|
|
386
392
|
if (data.options.verbose)
|
|
387
|
-
(0,
|
|
393
|
+
(0, cli_1.logExec)(`Writing metadata into ${metaPath}`);
|
|
388
394
|
await (0, promises_1.writeFile)(metaPath, DatatruckRepository.stringifyMetaData(meta));
|
|
389
395
|
}
|
|
390
396
|
async onCopyBackup(data) {
|
|
@@ -396,7 +402,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
396
402
|
const sourcePath = (0, path_1.resolve)((0, path_1.join)(this.config.outPath, snapshotName));
|
|
397
403
|
const targetPath = (0, path_1.resolve)((0, path_1.join)(data.mirrorRepositoryConfig.outPath, snapshotName));
|
|
398
404
|
if (data.options.verbose)
|
|
399
|
-
(0,
|
|
405
|
+
(0, cli_1.logExec)(`Copying backup files to ${targetPath}`);
|
|
400
406
|
await (0, promises_1.mkdir)(targetPath);
|
|
401
407
|
const scanner = await this.createFileScanner({
|
|
402
408
|
glob: {
|
|
@@ -406,7 +412,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
406
412
|
onProgress: data.onProgress,
|
|
407
413
|
});
|
|
408
414
|
await scanner.start();
|
|
409
|
-
await (0,
|
|
415
|
+
await (0, fs_1.cpy)({
|
|
410
416
|
input: {
|
|
411
417
|
type: "glob",
|
|
412
418
|
sourcePath,
|
|
@@ -449,7 +455,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
449
455
|
await scanner.updateProgress();
|
|
450
456
|
}
|
|
451
457
|
else if (dirent.name.endsWith(".zip")) {
|
|
452
|
-
await (0,
|
|
458
|
+
await (0, zip_1.listZip)({
|
|
453
459
|
path,
|
|
454
460
|
verbose: data.options.verbose,
|
|
455
461
|
onStream: async (item) => {
|
|
@@ -463,8 +469,8 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
463
469
|
}
|
|
464
470
|
await scanner.updateProgress(true);
|
|
465
471
|
if (data.options.verbose)
|
|
466
|
-
(0,
|
|
467
|
-
await (0,
|
|
472
|
+
(0, cli_1.logExec)(`Copying files to ${restorePath}`);
|
|
473
|
+
await (0, fs_1.cpy)({
|
|
468
474
|
input: {
|
|
469
475
|
type: "glob",
|
|
470
476
|
sourcePath: (0, path_1.join)(sourcePath, "unpacked"),
|
|
@@ -478,24 +484,22 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
478
484
|
const path = (0, path_1.join)(sourcePath, dirent.name);
|
|
479
485
|
if (dirent.name === "permissions.txt") {
|
|
480
486
|
if (data.options.verbose)
|
|
481
|
-
(0,
|
|
487
|
+
(0, cli_1.logExec)(`Applying permissions (${path})`);
|
|
482
488
|
await scanner.progress("Applying permissions", {
|
|
483
489
|
current: 0,
|
|
484
490
|
});
|
|
485
|
-
await (0,
|
|
491
|
+
await (0, fs_1.applyPermissions)(restorePath, path);
|
|
486
492
|
await scanner.progress("Permissions applied", {
|
|
487
493
|
current: 1,
|
|
488
494
|
type: "end",
|
|
489
495
|
});
|
|
490
496
|
}
|
|
491
497
|
else if (dirent.name.endsWith(".zip")) {
|
|
492
|
-
await (0,
|
|
498
|
+
await (0, zip_1.unzip)({
|
|
493
499
|
input: path,
|
|
494
500
|
output: restorePath,
|
|
495
501
|
verbose: data.options.verbose,
|
|
496
|
-
onProgress: async (progress) => await scanner.progress(
|
|
497
|
-
? "Starting extracting"
|
|
498
|
-
: "Extracting file", progress),
|
|
502
|
+
onProgress: async (progress) => await scanner.progress("Extracting file", progress),
|
|
499
503
|
});
|
|
500
504
|
}
|
|
501
505
|
}
|
|
@@ -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 = {
|
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ResticRepository = exports.resticPackageRepositoryDefinition = exports.resticRepositoryDefinition = exports.resticRepositoryName = void 0;
|
|
7
7
|
const AppError_1 = require("../Error/AppError");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const Restic_1 = require("../utils/Restic");
|
|
9
|
+
const cli_1 = require("../utils/cli");
|
|
10
|
+
const paths_1 = require("../utils/datatruck/paths");
|
|
11
|
+
const fs_1 = require("../utils/fs");
|
|
12
|
+
const math_1 = require("../utils/math");
|
|
13
|
+
const string_1 = require("../utils/string");
|
|
14
14
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
15
15
|
const assert_1 = require("assert");
|
|
16
16
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
@@ -88,7 +88,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
88
88
|
...(typeof this.config.password === "string"
|
|
89
89
|
? { RESTIC_PASSWORD: this.config.password }
|
|
90
90
|
: { RESTIC_PASSWORD_FILE: (0, path_1.resolve)(this.config.password.path) }),
|
|
91
|
-
RESTIC_REPOSITORY: await
|
|
91
|
+
RESTIC_REPOSITORY: await Restic_1.Restic.formatRepository(this.config.repository),
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
static buildSnapshotTag(name, value) {
|
|
@@ -122,25 +122,25 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
122
122
|
return result;
|
|
123
123
|
}
|
|
124
124
|
onGetSource() {
|
|
125
|
-
return (0,
|
|
125
|
+
return (0, string_1.formatUri)({ ...this.config.repository, password: undefined });
|
|
126
126
|
}
|
|
127
127
|
async onInit(data) {
|
|
128
|
-
const restic = new
|
|
128
|
+
const restic = new Restic_1.Restic({
|
|
129
129
|
env: await this.buildEnv(),
|
|
130
130
|
log: data.options.verbose,
|
|
131
131
|
});
|
|
132
132
|
if (this.config.repository.backend === "local")
|
|
133
|
-
await (0,
|
|
133
|
+
await (0, fs_1.mkdirIfNotExists)(this.env.RESTIC_REPOSITORY);
|
|
134
134
|
if (!(await restic.checkRepository()))
|
|
135
135
|
await restic.exec(["init"]);
|
|
136
136
|
}
|
|
137
137
|
async onSnapshots(data) {
|
|
138
|
-
const restic = new
|
|
138
|
+
const restic = new Restic_1.Restic({
|
|
139
139
|
env: await this.buildEnv(),
|
|
140
140
|
log: data.options.verbose,
|
|
141
141
|
});
|
|
142
|
-
const packagePatterns = (0,
|
|
143
|
-
const taskNamePatterns = (0,
|
|
142
|
+
const packagePatterns = (0, string_1.makePathPatterns)(data.options.packageNames);
|
|
143
|
+
const taskNamePatterns = (0, string_1.makePathPatterns)(data.options.packageTaskNames);
|
|
144
144
|
const result = await restic.snapshots({
|
|
145
145
|
json: true,
|
|
146
146
|
tags: [
|
|
@@ -153,7 +153,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
153
153
|
return items;
|
|
154
154
|
if (packagePatterns && !(0, micromatch_1.isMatch)(tag.package, packagePatterns))
|
|
155
155
|
return items;
|
|
156
|
-
if (taskNamePatterns && !(0,
|
|
156
|
+
if (taskNamePatterns && !(0, string_1.checkMatch)(tag.task, taskNamePatterns))
|
|
157
157
|
return items;
|
|
158
158
|
const itemTags = tag.tags ?? [];
|
|
159
159
|
if (data.options.tags && !itemTags.some((t) => itemTags.includes(t)))
|
|
@@ -171,7 +171,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
171
171
|
}, []);
|
|
172
172
|
}
|
|
173
173
|
async onPrune(data) {
|
|
174
|
-
const restic = new
|
|
174
|
+
const restic = new Restic_1.Restic({
|
|
175
175
|
env: await this.buildEnv(),
|
|
176
176
|
log: data.options.verbose,
|
|
177
177
|
});
|
|
@@ -181,7 +181,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
async onBackup(data) {
|
|
184
|
-
const restic = new
|
|
184
|
+
const restic = new Restic_1.Restic({
|
|
185
185
|
env: await this.buildEnv(),
|
|
186
186
|
log: data.options.verbose,
|
|
187
187
|
});
|
|
@@ -190,7 +190,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
190
190
|
(0, assert_1.ok)(sourcePath);
|
|
191
191
|
let gitignorePath;
|
|
192
192
|
if (!pkg.include && pkg.exclude) {
|
|
193
|
-
const exclude = await (0,
|
|
193
|
+
const exclude = await (0, paths_1.parsePaths)(pkg.exclude, {
|
|
194
194
|
cwd: sourcePath,
|
|
195
195
|
verbose: data.options.verbose,
|
|
196
196
|
});
|
|
@@ -200,17 +200,17 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
202
|
const tmpDir = await this.mkTmpDir("restic-exclude");
|
|
203
|
-
const ignoredContents = (0,
|
|
203
|
+
const ignoredContents = (0, fs_1.fastglobToGitIgnore)(exclude, sourcePath).join("\n");
|
|
204
204
|
gitignorePath = (0, path_1.join)(tmpDir, "ignored.txt");
|
|
205
205
|
await (0, promises_1.writeFile)(gitignorePath, ignoredContents);
|
|
206
206
|
}
|
|
207
207
|
else if (pkg.include || pkg.exclude) {
|
|
208
|
-
const include = await (0,
|
|
208
|
+
const include = await (0, paths_1.parsePaths)(pkg.include ?? ["**"], {
|
|
209
209
|
cwd: sourcePath,
|
|
210
210
|
verbose: data.options.verbose,
|
|
211
211
|
});
|
|
212
212
|
const exclude = pkg.exclude
|
|
213
|
-
? await (0,
|
|
213
|
+
? await (0, paths_1.parsePaths)(pkg.exclude, {
|
|
214
214
|
cwd: sourcePath,
|
|
215
215
|
verbose: data.options.verbose,
|
|
216
216
|
})
|
|
@@ -223,13 +223,13 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
223
223
|
markDirectories: true,
|
|
224
224
|
});
|
|
225
225
|
if (data.options.verbose)
|
|
226
|
-
(0,
|
|
226
|
+
(0, cli_1.logExec)(`Writing paths lists`);
|
|
227
227
|
await data.onProgress({
|
|
228
228
|
relative: {
|
|
229
229
|
description: "Writing excluded paths list",
|
|
230
230
|
},
|
|
231
231
|
});
|
|
232
|
-
gitignorePath = await (0,
|
|
232
|
+
gitignorePath = await (0, fs_1.writeGitIgnoreList)({
|
|
233
233
|
paths: stream,
|
|
234
234
|
outDir: await this.mkTmpDir("gitignore-list"),
|
|
235
235
|
});
|
|
@@ -247,7 +247,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
247
247
|
tags: [packageTag],
|
|
248
248
|
latest: 1,
|
|
249
249
|
});
|
|
250
|
-
const nodePkg = (0,
|
|
250
|
+
const nodePkg = (0, fs_1.parsePackageFile)();
|
|
251
251
|
let lastProgress;
|
|
252
252
|
let totalFilesChanges = 0;
|
|
253
253
|
const totalFilesChangesLimit = 10;
|
|
@@ -338,13 +338,13 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
338
338
|
});
|
|
339
339
|
if (!snapshot)
|
|
340
340
|
throw new AppError_1.AppError(`Snapshot not found`);
|
|
341
|
-
const restic = new
|
|
341
|
+
const restic = new Restic_1.Restic({
|
|
342
342
|
env: {
|
|
343
343
|
...(await this.buildEnv()),
|
|
344
344
|
...(typeof config.password === "string"
|
|
345
345
|
? { RESTIC_PASSWORD2: config.password }
|
|
346
346
|
: { RESTIC_PASSWORD_FILE2: (0, path_1.resolve)(config.password.path) }),
|
|
347
|
-
RESTIC_REPOSITORY2: await
|
|
347
|
+
RESTIC_REPOSITORY2: await Restic_1.Restic.formatRepository(config.repository),
|
|
348
348
|
},
|
|
349
349
|
log: data.options.verbose,
|
|
350
350
|
});
|
|
@@ -355,7 +355,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
355
355
|
async onRestore(data) {
|
|
356
356
|
const restorePath = data.targetPath ?? data.package.restorePath;
|
|
357
357
|
(0, assert_1.ok)(restorePath);
|
|
358
|
-
const restic = new
|
|
358
|
+
const restic = new Restic_1.Restic({
|
|
359
359
|
env: await this.buildEnv(),
|
|
360
360
|
log: data.options.verbose,
|
|
361
361
|
});
|
|
@@ -377,7 +377,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
377
377
|
absolute: {
|
|
378
378
|
total: snapshot.size,
|
|
379
379
|
current,
|
|
380
|
-
percent: (0,
|
|
380
|
+
percent: (0, math_1.progressPercent)(snapshot.size, current),
|
|
381
381
|
},
|
|
382
382
|
});
|
|
383
383
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Progress } from "../
|
|
2
|
+
import { Progress } from "../utils/progress";
|
|
3
3
|
import { WriteDataType, ReadResultType, SessionDriverAbstract, SessionDriverOptions } from "./SessionDriverAbstract";
|
|
4
4
|
type BadgeType = {
|
|
5
5
|
name: string;
|