@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
|
@@ -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;
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ConsoleSessionDriver = void 0;
|
|
7
7
|
const AppError_1 = require("../Error/AppError");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const cli_1 = require("../utils/cli");
|
|
9
|
+
const date_1 = require("../utils/date");
|
|
10
10
|
const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
|
|
11
11
|
const chalk_1 = require("chalk");
|
|
12
12
|
const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
|
|
@@ -17,7 +17,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
17
17
|
constructor() {
|
|
18
18
|
super(...arguments);
|
|
19
19
|
this.prints = 0;
|
|
20
|
-
this.chron = (0,
|
|
20
|
+
this.chron = (0, date_1.createChron)();
|
|
21
21
|
}
|
|
22
22
|
async onInit() {
|
|
23
23
|
this.tty = this.options.verbose
|
|
@@ -34,8 +34,8 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
34
34
|
async onEnd(data) {
|
|
35
35
|
clearInterval(this.renderInterval);
|
|
36
36
|
if (this.tty)
|
|
37
|
-
process.stdout.write(
|
|
38
|
-
(0,
|
|
37
|
+
process.stdout.write(cli_1.showCursorCommand);
|
|
38
|
+
(0, cli_1.logVars)({
|
|
39
39
|
...data,
|
|
40
40
|
elapsed: this.chron.elapsed(true),
|
|
41
41
|
});
|
|
@@ -56,10 +56,10 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
56
56
|
const line = this.renderSpinner(text);
|
|
57
57
|
const [truncatedLine, truncated] = endMessage
|
|
58
58
|
? [line, false]
|
|
59
|
-
: (0,
|
|
59
|
+
: (0, cli_1.truncate)(line, columns);
|
|
60
60
|
if (this.lastColumns && columns !== this.lastColumns && truncated)
|
|
61
|
-
process.stdout.write(`${
|
|
62
|
-
process.stdout.write(`${
|
|
61
|
+
process.stdout.write(`${cli_1.clearCommand}\n`);
|
|
62
|
+
process.stdout.write(`${cli_1.clearCommand}${truncatedLine}${cli_1.hideCursorCommand}`);
|
|
63
63
|
this.lastColumns = columns;
|
|
64
64
|
}
|
|
65
65
|
this.prints++;
|
|
@@ -67,7 +67,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
67
67
|
this.lastMessageText = text;
|
|
68
68
|
}
|
|
69
69
|
renderSpinner(text) {
|
|
70
|
-
return text.replace("{spinner}", (0, chalk_1.grey)(this.tty ? (0,
|
|
70
|
+
return text.replace("{spinner}", (0, chalk_1.grey)(this.tty ? (0, cli_1.renderSpinner)(this.prints) : "?"));
|
|
71
71
|
}
|
|
72
72
|
renderMessage(message) {
|
|
73
73
|
const badges = renderBadges([
|
|
@@ -85,7 +85,7 @@ class ConsoleSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
85
85
|
const relative = progress?.relative || {};
|
|
86
86
|
if (typeof absolute.percent === "number" ||
|
|
87
87
|
typeof relative.percent === "number") {
|
|
88
|
-
parts.push((0,
|
|
88
|
+
parts.push((0, cli_1.renderProgressBar)(absolute.percent ?? 0, 10, relative.percent ?? undefined));
|
|
89
89
|
}
|
|
90
90
|
const createProgressParts = (p) => {
|
|
91
91
|
const result = [];
|
|
@@ -9,14 +9,14 @@ const BackupSessionEntity_1 = require("../Entity/BackupSessionEntity");
|
|
|
9
9
|
const BackupSessionRepositoryEntity_1 = require("../Entity/BackupSessionRepositoryEntity");
|
|
10
10
|
const RestoreSessionEntity_1 = require("../Entity/RestoreSessionEntity");
|
|
11
11
|
const RestoreSessionRepositoryEntity_1 = require("../Entity/RestoreSessionRepositoryEntity");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
const cli_1 = require("../utils/cli");
|
|
13
|
+
const entity_1 = require("../utils/entity");
|
|
14
|
+
const path_1 = require("../utils/path");
|
|
15
|
+
const process_1 = require("../utils/process");
|
|
16
16
|
const SessionDriverAbstract_1 = require("./SessionDriverAbstract");
|
|
17
17
|
const assert_1 = require("assert");
|
|
18
18
|
const os_1 = require("os");
|
|
19
|
-
const
|
|
19
|
+
const path_2 = require("path");
|
|
20
20
|
const sqlite_1 = require("sqlite");
|
|
21
21
|
const sqlite3_1 = __importDefault(require("sqlite3"));
|
|
22
22
|
class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract {
|
|
@@ -27,11 +27,11 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
27
27
|
async onInit() {
|
|
28
28
|
this.db = await (0, sqlite_1.open)({
|
|
29
29
|
filename: process.env["DATATRUCK_SQLITE_DB"] ??
|
|
30
|
-
(0,
|
|
30
|
+
(0, path_2.join)((0, os_1.homedir)(), "datatruck.sqlite"),
|
|
31
31
|
driver: sqlite3_1.default.Database,
|
|
32
32
|
});
|
|
33
33
|
await this.db.migrate({
|
|
34
|
-
migrationsPath: (0,
|
|
34
|
+
migrationsPath: (0, path_2.join)(path_1.rootPath, "migrations"),
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
buildInsertStm(tableName, values) {
|
|
@@ -49,12 +49,12 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
49
49
|
}
|
|
50
50
|
async exec(query, cb) {
|
|
51
51
|
if (this.options.verbose) {
|
|
52
|
-
(0,
|
|
53
|
-
(0,
|
|
52
|
+
(0, cli_1.logExec)("query");
|
|
53
|
+
(0, process_1.logExecStdout)({ data: query, lineSalt: true });
|
|
54
54
|
}
|
|
55
55
|
const result = await cb();
|
|
56
56
|
if (this.options.verbose)
|
|
57
|
-
(0,
|
|
57
|
+
(0, process_1.logExecStdout)({ data: JSON.stringify(result, null, 2), lineSalt: true });
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
60
|
async onRead(data, type) {
|
|
@@ -64,8 +64,8 @@ class SqliteSessionDriver extends SessionDriverAbstract_1.SessionDriverAbstract
|
|
|
64
64
|
const sessionRepositoryMeta = (0, EntityDecorator_1.EntityDecoratorHandler)(type === SessionDriverAbstract_1.EntityEnum.BackupSession
|
|
65
65
|
? BackupSessionRepositoryEntity_1.BackupSessionRepositoryEntity
|
|
66
66
|
: RestoreSessionRepositoryEntity_1.RestoreSessionRepositoryEntity);
|
|
67
|
-
const sessionTable = (0,
|
|
68
|
-
const repoTable = (0,
|
|
67
|
+
const sessionTable = (0, entity_1.makeTableSelector)(sessionMeta.get().tableName);
|
|
68
|
+
const repoTable = (0, entity_1.makeTableSelector)(sessionRepositoryMeta.get().tableName);
|
|
69
69
|
const where = {};
|
|
70
70
|
if (data.packageNames)
|
|
71
71
|
where[sessionTable("packageName")] = data.packageNames;
|
|
@@ -3,8 +3,8 @@ import { BackupSessionEntity } from "../Entity/BackupSessionEntity";
|
|
|
3
3
|
import { BackupSessionRepositoryEntity } from "../Entity/BackupSessionRepositoryEntity";
|
|
4
4
|
import { BackupSessionTaskEntity } from "../Entity/BackupSessionTaskEntity";
|
|
5
5
|
import { WriteDataType } from "../SessionDriver/SessionDriverAbstract";
|
|
6
|
-
import { ObjectVault } from "../
|
|
7
|
-
import { Progress } from "../
|
|
6
|
+
import { ObjectVault } from "../utils/ObjectVault";
|
|
7
|
+
import { Progress } from "../utils/progress";
|
|
8
8
|
import SessionManagerAbstract from "./SessionManagerAbstract";
|
|
9
9
|
export declare class BackupSessionManager extends SessionManagerAbstract {
|
|
10
10
|
sessionVault: ObjectVault<BackupSessionEntity>;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BackupSessionManager = void 0;
|
|
7
7
|
const SessionDriverAbstract_1 = require("../SessionDriver/SessionDriverAbstract");
|
|
8
|
-
const ObjectVault_1 = require("../
|
|
8
|
+
const ObjectVault_1 = require("../utils/ObjectVault");
|
|
9
9
|
const SessionManagerAbstract_1 = __importDefault(require("./SessionManagerAbstract"));
|
|
10
10
|
class BackupSessionManager extends SessionManagerAbstract_1.default {
|
|
11
11
|
constructor() {
|
|
@@ -3,8 +3,8 @@ import { RestoreSessionEntity } from "../Entity/RestoreSessionEntity";
|
|
|
3
3
|
import { RestoreSessionRepositoryEntity } from "../Entity/RestoreSessionRepositoryEntity";
|
|
4
4
|
import { RestoreSessionTaskEntity } from "../Entity/RestoreSessionTaskEntity";
|
|
5
5
|
import { WriteDataType } from "../SessionDriver/SessionDriverAbstract";
|
|
6
|
-
import { ObjectVault } from "../
|
|
7
|
-
import { Progress } from "../
|
|
6
|
+
import { ObjectVault } from "../utils/ObjectVault";
|
|
7
|
+
import { Progress } from "../utils/progress";
|
|
8
8
|
import SessionManagerAbstract from "./SessionManagerAbstract";
|
|
9
9
|
export declare class RestoreSessionManager extends SessionManagerAbstract {
|
|
10
10
|
sessionVault: ObjectVault<RestoreSessionEntity>;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RestoreSessionManager = void 0;
|
|
7
7
|
const SessionDriverAbstract_1 = require("../SessionDriver/SessionDriverAbstract");
|
|
8
|
-
const ObjectVault_1 = require("../
|
|
8
|
+
const ObjectVault_1 = require("../utils/ObjectVault");
|
|
9
9
|
const SessionManagerAbstract_1 = __importDefault(require("./SessionManagerAbstract"));
|
|
10
10
|
class RestoreSessionManager extends SessionManagerAbstract_1.default {
|
|
11
11
|
constructor() {
|
package/Task/GitTask.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GitTask = exports.gitTaskDefinition = exports.gitTaskName = void 0;
|
|
4
4
|
const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const cli_1 = require("../utils/cli");
|
|
6
|
+
const fs_1 = require("../utils/fs");
|
|
7
|
+
const math_1 = require("../utils/math");
|
|
8
|
+
const process_1 = require("../utils/process");
|
|
9
9
|
const TaskAbstract_1 = require("./TaskAbstract");
|
|
10
10
|
const assert_1 = require("assert");
|
|
11
|
-
const
|
|
11
|
+
const fs_2 = require("fs");
|
|
12
12
|
const promises_1 = require("fs/promises");
|
|
13
13
|
const micromatch_1 = require("micromatch");
|
|
14
14
|
const path_1 = require("path");
|
|
@@ -77,7 +77,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
77
77
|
description: "Creating bundle",
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
|
-
await (0,
|
|
80
|
+
await (0, process_1.exec)(this.command, ["bundle", "create", bundlePath, "--all"], {
|
|
81
81
|
cwd: path,
|
|
82
82
|
}, {
|
|
83
83
|
log: this.verbose,
|
|
@@ -112,11 +112,11 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
112
112
|
if (!option.include)
|
|
113
113
|
continue;
|
|
114
114
|
option.pathsPath = (0, path_1.join)(targetPath, `repo.${option.name}-paths.txt`);
|
|
115
|
-
const stream = (0,
|
|
115
|
+
const stream = (0, fs_2.createWriteStream)(option.pathsPath);
|
|
116
116
|
let streamError;
|
|
117
117
|
stream.on("error", (e) => (streamError = e));
|
|
118
118
|
try {
|
|
119
|
-
await (0,
|
|
119
|
+
await (0, process_1.exec)(this.command, [
|
|
120
120
|
"-c",
|
|
121
121
|
"core.quotepath=off",
|
|
122
122
|
"ls-files",
|
|
@@ -161,10 +161,10 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
161
161
|
if (!option.include)
|
|
162
162
|
continue;
|
|
163
163
|
const outPath = (0, path_1.join)(targetPath, `repo.${option.name}`);
|
|
164
|
-
await (0,
|
|
164
|
+
await (0, fs_1.mkdirIfNotExists)(outPath);
|
|
165
165
|
if (data.options.verbose)
|
|
166
|
-
(0,
|
|
167
|
-
await (0,
|
|
166
|
+
(0, cli_1.logExec)(`Copying ${option.name} files to ${outPath}`);
|
|
167
|
+
await (0, fs_1.cpy)({
|
|
168
168
|
input: {
|
|
169
169
|
type: "pathList",
|
|
170
170
|
path: option.pathsPath,
|
|
@@ -183,7 +183,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
183
183
|
absolute: {
|
|
184
184
|
total,
|
|
185
185
|
current: currentFiles,
|
|
186
|
-
percent: (0,
|
|
186
|
+
percent: (0, math_1.progressPercent)(total, currentFiles),
|
|
187
187
|
},
|
|
188
188
|
});
|
|
189
189
|
},
|
|
@@ -202,18 +202,18 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
202
202
|
const targetPath = data.targetPath;
|
|
203
203
|
(0, assert_1.ok)(typeof restorePath === "string");
|
|
204
204
|
(0, assert_1.ok)(typeof targetPath === "string");
|
|
205
|
-
await (0,
|
|
206
|
-
await (0,
|
|
205
|
+
await (0, fs_1.mkdirIfNotExists)(restorePath);
|
|
206
|
+
await (0, fs_1.ensureEmptyDir)(restorePath);
|
|
207
207
|
// Stats
|
|
208
208
|
let totalFiles = 0;
|
|
209
209
|
let currentFiles = 0;
|
|
210
|
-
await (0,
|
|
210
|
+
await (0, fs_1.forEachFile)(targetPath, () => totalFiles++, true);
|
|
211
211
|
const incrementProgress = async (description, item, count = true) => {
|
|
212
212
|
await data.onProgress({
|
|
213
213
|
absolute: {
|
|
214
214
|
total: totalFiles,
|
|
215
215
|
current: Math.max(currentFiles, 0),
|
|
216
|
-
percent: (0,
|
|
216
|
+
percent: (0, math_1.progressPercent)(totalFiles, Math.max(currentFiles, 0)),
|
|
217
217
|
},
|
|
218
218
|
relative: { description, payload: item },
|
|
219
219
|
});
|
|
@@ -222,7 +222,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
222
222
|
};
|
|
223
223
|
// Bundle
|
|
224
224
|
const bundlePath = (0, path_1.join)(targetPath, "repo.bundle");
|
|
225
|
-
await (0,
|
|
225
|
+
await (0, process_1.exec)(this.command, ["clone", bundlePath, "."], {
|
|
226
226
|
cwd: restorePath,
|
|
227
227
|
}, {
|
|
228
228
|
log: this.verbose,
|
|
@@ -230,17 +230,17 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
230
230
|
await incrementProgress();
|
|
231
231
|
// Config
|
|
232
232
|
const configPath = (0, path_1.join)(targetPath, "repo.config");
|
|
233
|
-
if (await (0,
|
|
233
|
+
if (await (0, fs_1.checkFile)(configPath)) {
|
|
234
234
|
await (0, promises_1.copyFile)(configPath, (0, path_1.join)(restorePath, ".git", "config"));
|
|
235
235
|
await incrementProgress();
|
|
236
236
|
}
|
|
237
237
|
// ls-files
|
|
238
238
|
for (const name of ["untracked", "modified", "ignored"]) {
|
|
239
239
|
const sourcePath = (0, path_1.join)(targetPath, `repo.${name}`);
|
|
240
|
-
if (await (0,
|
|
240
|
+
if (await (0, fs_1.checkDir)(sourcePath)) {
|
|
241
241
|
if (data.options.verbose)
|
|
242
|
-
(0,
|
|
243
|
-
await (0,
|
|
242
|
+
(0, cli_1.logExec)(`Copying ${name} files to ${restorePath}`);
|
|
243
|
+
await (0, fs_1.cpy)({
|
|
244
244
|
input: {
|
|
245
245
|
type: "glob",
|
|
246
246
|
sourcePath,
|
package/Task/MariadbTask.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ export type MariadbTaskConfigType = {
|
|
|
11
11
|
excludeTables?: string[];
|
|
12
12
|
includeDatabases?: string[];
|
|
13
13
|
excludeDatabases?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* @default "auto"
|
|
16
|
+
*/
|
|
17
|
+
parallel?: number | "auto";
|
|
18
|
+
compress?: {
|
|
19
|
+
command: string;
|
|
20
|
+
args?: string[];
|
|
21
|
+
} | {
|
|
22
|
+
type: "gzip" | "pigz";
|
|
23
|
+
args?: string[];
|
|
24
|
+
};
|
|
14
25
|
};
|
|
15
26
|
export declare const mariadbTaskName = "mariadb";
|
|
16
27
|
export declare const mariadbTaskDefinition: JSONSchema7;
|