@datatruck/cli 0.32.2 → 0.33.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/config.schema.json +374 -31
- package/lib/{Action → actions}/BackupAction.d.ts +5 -17
- package/lib/{Action → actions}/BackupAction.js +32 -85
- package/lib/{Action → actions}/ConfigAction.d.ts +4 -2
- package/lib/{Action → actions}/ConfigAction.js +16 -8
- package/lib/{Action → actions}/CopyAction.d.ts +17 -13
- package/lib/actions/CopyAction.js +285 -0
- package/lib/{Action → actions}/InitAction.d.ts +1 -1
- package/lib/{Action → actions}/InitAction.js +3 -3
- package/lib/{Action → actions}/PruneAction.d.ts +1 -2
- package/lib/{Action → actions}/PruneAction.js +2 -2
- package/lib/{Action → actions}/RestoreAction.d.ts +4 -13
- package/lib/{Action → actions}/RestoreAction.js +17 -17
- package/lib/{Action → actions}/SnapshotsAction.d.ts +2 -3
- package/lib/{Action → actions}/SnapshotsAction.js +3 -3
- package/lib/cli.d.ts +3 -3
- package/lib/cli.js +18 -17
- package/lib/commands/BackupCommand.d.ts +43 -0
- package/lib/{Command → commands}/BackupCommand.js +7 -6
- package/lib/{Command → commands}/CleanCacheCommand.d.ts +4 -2
- package/lib/{Command → commands}/CleanCacheCommand.js +6 -5
- package/lib/{Command → commands}/CommandAbstract.d.ts +10 -6
- package/lib/{Command → commands}/CommandAbstract.js +5 -3
- package/lib/commands/ConfigCommand.d.ts +22 -0
- package/lib/{Command → commands}/ConfigCommand.js +5 -5
- package/lib/commands/CopyCommand.d.ts +17 -0
- package/lib/{Command → commands}/CopyCommand.js +7 -6
- package/lib/commands/InitCommand.d.ts +19 -0
- package/lib/{Command → commands}/InitCommand.js +9 -9
- package/lib/{Command → commands}/PruneCommand.d.ts +7 -4
- package/lib/{Command → commands}/PruneCommand.js +11 -11
- package/lib/commands/RestoreCommand.d.ts +38 -0
- package/lib/{Command → commands}/RestoreCommand.js +7 -6
- package/lib/{Command → commands}/SnapshotsCommand.d.ts +8 -6
- package/lib/{Command → commands}/SnapshotsCommand.js +12 -12
- package/lib/{Command → commands}/StartServerCommand.d.ts +4 -2
- package/lib/{Command → commands}/StartServerCommand.js +5 -5
- package/lib/index.d.ts +20 -23
- package/lib/index.js +8 -8
- package/lib/{Repository → repositories}/DatatruckRepository.js +2 -2
- package/lib/{Repository → repositories}/RepositoryAbstract.d.ts +7 -7
- package/lib/{Repository → repositories}/ResticRepository.js +7 -6
- package/lib/{Task → tasks}/MssqlTask.js +2 -2
- package/lib/{Task → tasks}/MysqlDumpTask.js +4 -4
- package/lib/{Task → tasks}/ScriptTask.d.ts +2 -2
- package/lib/{Task → tasks}/SqlDumpTaskAbstract.js +4 -4
- package/lib/{Task → tasks}/TaskAbstract.d.ts +4 -4
- package/lib/utils/DataFormat.js +3 -3
- package/lib/utils/Restic.d.ts +1 -0
- package/lib/utils/Restic.js +12 -2
- package/lib/utils/cli.d.ts +9 -3
- package/lib/utils/cli.js +17 -1
- package/lib/utils/cron.d.ts +11 -0
- package/lib/utils/cron.js +27 -0
- package/lib/utils/datatruck/command.d.ts +29 -0
- package/lib/utils/datatruck/command.js +61 -0
- package/lib/{Config/RepositoryConfig.d.ts → utils/datatruck/config-repository-type.d.ts} +19 -8
- package/lib/{Config/TaskConfig.d.ts → utils/datatruck/config-task-type.d.ts} +6 -6
- package/lib/utils/datatruck/config-type.d.ts +50 -0
- package/lib/utils/datatruck/config.d.ts +19 -10
- package/lib/utils/datatruck/config.js +43 -7
- package/lib/utils/datatruck/cron-server.d.ts +27 -6
- package/lib/utils/datatruck/cron-server.js +38 -20
- package/lib/utils/datatruck/paths.d.ts +2 -2
- package/lib/utils/datatruck/report-list.d.ts +12 -0
- package/lib/utils/datatruck/report-list.js +57 -0
- package/lib/utils/datatruck/repository-server.js +3 -2
- package/lib/utils/datatruck/repository.d.ts +16 -0
- package/lib/utils/datatruck/repository.js +30 -0
- package/lib/utils/datatruck/snapshot.d.ts +2 -2
- package/lib/utils/datatruck/task.d.ts +3 -0
- package/lib/{Factory/TaskFactory.js → utils/datatruck/task.js} +8 -8
- package/lib/utils/date.js +6 -2
- package/lib/utils/fs.d.ts +3 -0
- package/lib/utils/fs.js +24 -4
- package/lib/utils/list.d.ts +5 -5
- package/lib/utils/mysql.js +5 -5
- package/lib/utils/object.d.ts +13 -0
- package/lib/utils/object.js +32 -1
- package/lib/utils/process.js +4 -1
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +7 -3
- package/lib/utils/ts.d.ts +16 -0
- package/lib/utils/watcher.d.ts +10 -0
- package/lib/utils/watcher.js +34 -0
- package/package.json +3 -3
- package/lib/Action/CopyAction.js +0 -164
- package/lib/Command/BackupCommand.d.ts +0 -19
- package/lib/Command/ConfigCommand.d.ts +0 -15
- package/lib/Command/CopyCommand.d.ts +0 -16
- package/lib/Command/InitCommand.d.ts +0 -13
- package/lib/Command/RestoreCommand.d.ts +0 -17
- package/lib/Config/Config.d.ts +0 -28
- package/lib/Config/PackageConfig.d.ts +0 -24
- package/lib/Config/PackageRepositoryConfig.d.ts +0 -15
- package/lib/Config/PrunePolicyConfig.d.ts +0 -2
- package/lib/Config/RepositoryConfig.js +0 -2
- package/lib/Config/TaskConfig.js +0 -2
- package/lib/Factory/CommandFactory.d.ts +0 -45
- package/lib/Factory/CommandFactory.js +0 -96
- package/lib/Factory/RepositoryFactory.d.ts +0 -3
- package/lib/Factory/RepositoryFactory.js +0 -23
- package/lib/Factory/TaskFactory.d.ts +0 -3
- /package/lib/{Action → actions}/CleanCacheAction.d.ts +0 -0
- /package/lib/{Action → actions}/CleanCacheAction.js +0 -0
- /package/lib/{Repository → repositories}/DatatruckRepository.d.ts +0 -0
- /package/lib/{Repository → repositories}/GitRepository.d.ts +0 -0
- /package/lib/{Repository → repositories}/GitRepository.js +0 -0
- /package/lib/{Repository → repositories}/RepositoryAbstract.js +0 -0
- /package/lib/{Repository → repositories}/ResticRepository.d.ts +0 -0
- /package/lib/{Task → tasks}/GitTask.d.ts +0 -0
- /package/lib/{Task → tasks}/GitTask.js +0 -0
- /package/lib/{Task → tasks}/MariadbTask.d.ts +0 -0
- /package/lib/{Task → tasks}/MariadbTask.js +0 -0
- /package/lib/{Task → tasks}/MssqlTask.d.ts +0 -0
- /package/lib/{Task → tasks}/MysqlDumpTask.d.ts +0 -0
- /package/lib/{Task → tasks}/PostgresqlDumpTask.d.ts +0 -0
- /package/lib/{Task → tasks}/PostgresqlDumpTask.js +0 -0
- /package/lib/{Task → tasks}/ScriptTask.js +0 -0
- /package/lib/{Task → tasks}/SqlDumpTaskAbstract.d.ts +0 -0
- /package/lib/{Task → tasks}/TaskAbstract.js +0 -0
- /package/lib/{Config/Config.js → utils/datatruck/config-repository-type.js} +0 -0
- /package/lib/{Config/PackageConfig.js → utils/datatruck/config-task-type.js} +0 -0
- /package/lib/{Config/PackageRepositoryConfig.js → utils/datatruck/config-type.js} +0 -0
- /package/lib/{Error/AppError.d.ts → utils/datatruck/error.d.ts} +0 -0
- /package/lib/{Error/AppError.js → utils/datatruck/error.js} +0 -0
- /package/lib/{Config/PrunePolicyConfig.js → utils/ts.js} +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PruneCommand = void 0;
|
|
4
|
-
const ConfigAction_1 = require("../
|
|
5
|
-
const PruneAction_1 = require("../
|
|
4
|
+
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
|
+
const PruneAction_1 = require("../actions/PruneAction");
|
|
6
6
|
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
7
|
const cli_1 = require("../utils/cli");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
10
10
|
class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
11
|
-
|
|
12
|
-
return this.
|
|
11
|
+
optionsConfig() {
|
|
12
|
+
return this.castOptionsConfig({
|
|
13
13
|
dryRun: {
|
|
14
14
|
description: "",
|
|
15
15
|
option: "--dry-run",
|
|
@@ -99,7 +99,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
99
99
|
},
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
async
|
|
102
|
+
async exec() {
|
|
103
103
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
104
104
|
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
105
105
|
const prune = new PruneAction_1.PruneAction(config, {
|
|
@@ -121,10 +121,10 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
121
121
|
longId: this.options.longId,
|
|
122
122
|
returnsAll: this.options.showAll,
|
|
123
123
|
});
|
|
124
|
-
const
|
|
124
|
+
const result = await prune.exec();
|
|
125
125
|
const dataFormat = new DataFormat_1.DataFormat({
|
|
126
126
|
streams: this.streams,
|
|
127
|
-
json:
|
|
127
|
+
json: result,
|
|
128
128
|
table: {
|
|
129
129
|
headers: [
|
|
130
130
|
{ value: "Id.", width: (this.options.longId ? 32 : 8) + 2 },
|
|
@@ -134,7 +134,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
134
134
|
{ value: "Repository type" },
|
|
135
135
|
{ value: "Exclusion reasons" },
|
|
136
136
|
],
|
|
137
|
-
rows: () =>
|
|
137
|
+
rows: () => result.snapshots.map((item) => [
|
|
138
138
|
this.options.longId ? item.id : item.id.slice(0, 8),
|
|
139
139
|
item.date.replace("T", " ").replace("Z", ""),
|
|
140
140
|
item.packageName,
|
|
@@ -147,11 +147,11 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
147
147
|
if (this.globalOptions.outputFormat)
|
|
148
148
|
dataFormat.log(this.globalOptions.outputFormat);
|
|
149
149
|
if (!this.options.confirm && !this.options.dryRun) {
|
|
150
|
-
const answer = await (0, cli_1.confirm)(`Delete ${
|
|
150
|
+
const answer = await (0, cli_1.confirm)(`Delete ${result.prune}/${result.total} snapshots?`);
|
|
151
151
|
if (answer)
|
|
152
|
-
await prune.confirm(
|
|
152
|
+
await prune.confirm(result.snapshots);
|
|
153
153
|
}
|
|
154
|
-
return 0;
|
|
154
|
+
return { result, exitCode: 0 };
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
exports.PruneCommand = PruneCommand;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RepositoryConfig } from "../utils/datatruck/config-type";
|
|
2
|
+
import { If } from "../utils/ts";
|
|
3
|
+
import { CommandAbstract } from "./CommandAbstract";
|
|
4
|
+
export type RestoreCommandOptions<TResolved = false> = {
|
|
5
|
+
id: string;
|
|
6
|
+
package?: If<TResolved, string[]>;
|
|
7
|
+
packageTask?: If<TResolved, string[]>;
|
|
8
|
+
packageConfig?: boolean;
|
|
9
|
+
repository?: If<TResolved, string[]>;
|
|
10
|
+
repositoryType?: If<TResolved, RepositoryConfig["type"][]>;
|
|
11
|
+
tag?: If<TResolved, string[]>;
|
|
12
|
+
initial?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare class RestoreCommand extends CommandAbstract<RestoreCommandOptions<false>, RestoreCommandOptions<true>> {
|
|
15
|
+
optionsConfig(): import("../utils/cli").OptionsConfig<RestoreCommandOptions<false>, RestoreCommandOptions<true>>;
|
|
16
|
+
exec(): Promise<{
|
|
17
|
+
result: (import("../utils/list").List3SummaryResult | import("../utils/list").Listr3TaskResult<{
|
|
18
|
+
snapshots: {
|
|
19
|
+
id: string;
|
|
20
|
+
packages: number;
|
|
21
|
+
};
|
|
22
|
+
task: {
|
|
23
|
+
taskName: string;
|
|
24
|
+
packageName: string;
|
|
25
|
+
};
|
|
26
|
+
restore: import("../repositories/RepositoryAbstract").PreSnapshot & {
|
|
27
|
+
originalId: string;
|
|
28
|
+
packageName: string;
|
|
29
|
+
packageTaskName: string | undefined;
|
|
30
|
+
tags: string[];
|
|
31
|
+
size: number;
|
|
32
|
+
} & {
|
|
33
|
+
repositoryName: string;
|
|
34
|
+
};
|
|
35
|
+
}>)[];
|
|
36
|
+
exitCode: number;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RestoreCommand = void 0;
|
|
4
|
-
const ConfigAction_1 = require("../
|
|
5
|
-
const RestoreAction_1 = require("../
|
|
4
|
+
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
|
+
const RestoreAction_1 = require("../actions/RestoreAction");
|
|
6
6
|
const string_1 = require("../utils/string");
|
|
7
7
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
8
8
|
class RestoreCommand extends CommandAbstract_1.CommandAbstract {
|
|
9
|
-
|
|
10
|
-
return this.
|
|
9
|
+
optionsConfig() {
|
|
10
|
+
return this.castOptionsConfig({
|
|
11
11
|
id: {
|
|
12
12
|
description: "Filter by snapshot id",
|
|
13
13
|
option: "-i,--id <id>",
|
|
@@ -48,7 +48,7 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
async
|
|
51
|
+
async exec() {
|
|
52
52
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
53
53
|
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
54
54
|
const restore = new RestoreAction_1.RestoreAction(config, {
|
|
@@ -70,7 +70,8 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
70
70
|
restore
|
|
71
71
|
.dataFormat(result, { streams: this.streams, verbose })
|
|
72
72
|
.log(this.globalOptions.outputFormat);
|
|
73
|
-
|
|
73
|
+
const exitCode = result.some((item) => item.error) ? 1 : 0;
|
|
74
|
+
return { result, exitCode };
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
exports.RestoreCommand = RestoreCommand;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SnapshotsAction } from "../
|
|
2
|
-
import { RepositoryConfig } from "../
|
|
3
|
-
import { If
|
|
1
|
+
import { SnapshotsAction } from "../actions/SnapshotsAction";
|
|
2
|
+
import type { RepositoryConfig } from "../utils/datatruck/config-type";
|
|
3
|
+
import { If } from "../utils/ts";
|
|
4
4
|
import { CommandAbstract } from "./CommandAbstract";
|
|
5
5
|
export type SnapshotsCommandOptions<TResolved = false> = {
|
|
6
6
|
id?: If<TResolved, string[]>;
|
|
@@ -20,8 +20,10 @@ export type SnapshotsCommandOptions<TResolved = false> = {
|
|
|
20
20
|
groupBy?: If<TResolved, SnapshotsAction["options"]["groupBy"]>;
|
|
21
21
|
tag?: If<TResolved, string[]>;
|
|
22
22
|
};
|
|
23
|
-
export type SnapshotsCommandResult = Unwrap<SnapshotsAction["exec"]>;
|
|
24
23
|
export declare class SnapshotsCommand extends CommandAbstract<SnapshotsCommandOptions<false>, SnapshotsCommandOptions<true>> {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
optionsConfig(): import("../utils/cli").OptionsConfig<SnapshotsCommandOptions<false>, SnapshotsCommandOptions<true>>;
|
|
25
|
+
exec(): Promise<{
|
|
26
|
+
result: import("../actions/SnapshotsAction").ExtendedSnapshot[];
|
|
27
|
+
exitCode: number;
|
|
28
|
+
}>;
|
|
27
29
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SnapshotsCommand = void 0;
|
|
4
|
-
const ConfigAction_1 = require("../
|
|
5
|
-
const SnapshotsAction_1 = require("../
|
|
4
|
+
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
|
+
const SnapshotsAction_1 = require("../actions/SnapshotsAction");
|
|
6
6
|
const DataFormat_1 = require("../utils/DataFormat");
|
|
7
7
|
const bytes_1 = require("../utils/bytes");
|
|
8
8
|
const string_1 = require("../utils/string");
|
|
9
9
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
10
10
|
class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
11
|
-
|
|
11
|
+
optionsConfig() {
|
|
12
12
|
const groupByValues = [
|
|
13
13
|
"id",
|
|
14
14
|
"packageName",
|
|
15
15
|
"repositoryName",
|
|
16
16
|
"repositoryType",
|
|
17
17
|
];
|
|
18
|
-
return this.
|
|
18
|
+
return this.castOptionsConfig({
|
|
19
19
|
groupBy: {
|
|
20
20
|
option: "-g,--group-by <values>",
|
|
21
21
|
description: `Group by values (${groupByValues.join(", ")})`,
|
|
@@ -96,7 +96,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
async
|
|
99
|
+
async exec() {
|
|
100
100
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
101
101
|
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
102
102
|
const snapshots = new SnapshotsAction_1.SnapshotsAction(config, {
|
|
@@ -117,10 +117,10 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
117
117
|
verbose: verbose > 0,
|
|
118
118
|
tags: this.options.tag,
|
|
119
119
|
});
|
|
120
|
-
const
|
|
120
|
+
const result = await snapshots.exec();
|
|
121
121
|
const dataFormat = new DataFormat_1.DataFormat({
|
|
122
122
|
streams: this.streams,
|
|
123
|
-
json:
|
|
123
|
+
json: result,
|
|
124
124
|
table: {
|
|
125
125
|
headers: [
|
|
126
126
|
{ value: "Id.", width: (this.options.longId ? 32 : 8) + 2 },
|
|
@@ -131,7 +131,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
131
131
|
{ value: "Repository" },
|
|
132
132
|
{ value: "Repository type" },
|
|
133
133
|
],
|
|
134
|
-
rows: () =>
|
|
134
|
+
rows: () => result.map((item) => [
|
|
135
135
|
this.options.longId ? item.id : item.id.slice(0, 8),
|
|
136
136
|
item.date.replace("T", " ").replace("Z", ""),
|
|
137
137
|
item.packageName,
|
|
@@ -145,12 +145,12 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
145
145
|
if (this.globalOptions.outputFormat)
|
|
146
146
|
dataFormat.log(this.globalOptions.outputFormat, {
|
|
147
147
|
tpl: {
|
|
148
|
-
sids: () =>
|
|
149
|
-
ssids: () =>
|
|
150
|
-
pkgNames: () =>
|
|
148
|
+
sids: () => result.map((i) => i.id).join(),
|
|
149
|
+
ssids: () => result.map((i) => i.shortId).join(),
|
|
150
|
+
pkgNames: () => result.map((i) => i.packageName).join(),
|
|
151
151
|
},
|
|
152
152
|
});
|
|
153
|
-
return 0;
|
|
153
|
+
return { result, exitCode: 0 };
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
exports.SnapshotsCommand = SnapshotsCommand;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CommandAbstract } from "./CommandAbstract";
|
|
2
2
|
export type StartServerCommandOptions<TResolved = false> = {};
|
|
3
3
|
export declare class StartServerCommand extends CommandAbstract<StartServerCommandOptions<false>, StartServerCommandOptions<true>> {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
optionsConfig(): import("../utils/cli").OptionsConfig<StartServerCommandOptions<false>, StartServerCommandOptions<true>>;
|
|
5
|
+
exec(): Promise<{
|
|
6
|
+
exitCode: number;
|
|
7
|
+
}>;
|
|
6
8
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StartServerCommand = void 0;
|
|
4
|
-
const ConfigAction_1 = require("../
|
|
4
|
+
const ConfigAction_1 = require("../actions/ConfigAction");
|
|
5
5
|
const cron_server_1 = require("../utils/datatruck/cron-server");
|
|
6
6
|
const repository_server_1 = require("../utils/datatruck/repository-server");
|
|
7
7
|
const CommandAbstract_1 = require("./CommandAbstract");
|
|
8
8
|
class StartServerCommand extends CommandAbstract_1.CommandAbstract {
|
|
9
|
-
|
|
10
|
-
return this.
|
|
9
|
+
optionsConfig() {
|
|
10
|
+
return this.castOptionsConfig({});
|
|
11
11
|
}
|
|
12
|
-
async
|
|
12
|
+
async exec() {
|
|
13
13
|
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
14
14
|
const verbose = !!this.globalOptions.verbose;
|
|
15
15
|
const log = config.server?.log ?? true;
|
|
@@ -43,7 +43,7 @@ class StartServerCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
43
43
|
process.on("SIGINT", () => process.exit(1));
|
|
44
44
|
process.on("SIGTERM", () => process.exit(1));
|
|
45
45
|
await new Promise(() => setInterval(() => { }, 60000));
|
|
46
|
-
return 0;
|
|
46
|
+
return { exitCode: 0 };
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.StartServerCommand = StartServerCommand;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
export type { Config } from "./
|
|
2
|
-
export type {
|
|
3
|
-
export type {
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
export { type
|
|
7
|
-
export { type
|
|
8
|
-
export { type
|
|
9
|
-
export type
|
|
10
|
-
export { type
|
|
11
|
-
export { type
|
|
12
|
-
export { type
|
|
13
|
-
export { type
|
|
14
|
-
export { type
|
|
15
|
-
export { type
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export { PruneAction, type PruneActionsOptions } from "./Action/PruneAction";
|
|
22
|
-
export { RestoreAction, type RestoreActionOptions, } from "./Action/RestoreAction";
|
|
23
|
-
export { SnapshotsAction, type SnapshotsActionOptions, } from "./Action/SnapshotsAction";
|
|
1
|
+
export type { Config, PackageConfig, PackageConfigMeta, DatatruckPolicyConfig, DatatruckReportConfig, DatatruckServerOptions, } from "./utils/datatruck/config-type";
|
|
2
|
+
export type { PackageRepositoryConfig, RepositoryConfig, } from "./utils/datatruck/config-repository-type";
|
|
3
|
+
export type { TaskConfig } from "./utils/datatruck/config-task-type";
|
|
4
|
+
export { type ResticRepositoryConfig } from "./repositories/ResticRepository";
|
|
5
|
+
export { type DatatruckRepositoryConfig } from "./repositories/DatatruckRepository";
|
|
6
|
+
export { type GitRepositoryConfig } from "./repositories/GitRepository";
|
|
7
|
+
export { type GitTaskConfig } from "./tasks/GitTask";
|
|
8
|
+
export { type MariadbTaskConfig } from "./tasks/MariadbTask";
|
|
9
|
+
export { type MssqlTaskConfig } from "./tasks/MssqlTask";
|
|
10
|
+
export { type MysqlDumpTaskConfig } from "./tasks/MysqlDumpTask";
|
|
11
|
+
export { type PostgresqlDumpTaskConfig } from "./tasks/PostgresqlDumpTask";
|
|
12
|
+
export { type ScriptTaskConfig } from "./tasks/ScriptTask";
|
|
13
|
+
export { BackupAction, type BackupActionOptions } from "./actions/BackupAction";
|
|
14
|
+
export { CleanCacheAction, type CleanCacheActionOptions, } from "./actions/CleanCacheAction";
|
|
15
|
+
export { ConfigAction, type ConfigActionOptions } from "./actions/ConfigAction";
|
|
16
|
+
export { CopyAction, type CopyActionOptions } from "./actions/CopyAction";
|
|
17
|
+
export { InitAction, type InitActionOptions } from "./actions/InitAction";
|
|
18
|
+
export { PruneAction, type PruneActionsOptions } from "./actions/PruneAction";
|
|
19
|
+
export { RestoreAction, type RestoreActionOptions, } from "./actions/RestoreAction";
|
|
20
|
+
export { SnapshotsAction, type SnapshotsActionOptions, } from "./actions/SnapshotsAction";
|
|
24
21
|
export { parseArgs } from "./cli";
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseArgs = exports.SnapshotsAction = exports.RestoreAction = exports.PruneAction = exports.InitAction = exports.CopyAction = exports.ConfigAction = exports.CleanCacheAction = exports.BackupAction = void 0;
|
|
4
|
-
var BackupAction_1 = require("./
|
|
4
|
+
var BackupAction_1 = require("./actions/BackupAction");
|
|
5
5
|
Object.defineProperty(exports, "BackupAction", { enumerable: true, get: function () { return BackupAction_1.BackupAction; } });
|
|
6
|
-
var CleanCacheAction_1 = require("./
|
|
6
|
+
var CleanCacheAction_1 = require("./actions/CleanCacheAction");
|
|
7
7
|
Object.defineProperty(exports, "CleanCacheAction", { enumerable: true, get: function () { return CleanCacheAction_1.CleanCacheAction; } });
|
|
8
|
-
var ConfigAction_1 = require("./
|
|
8
|
+
var ConfigAction_1 = require("./actions/ConfigAction");
|
|
9
9
|
Object.defineProperty(exports, "ConfigAction", { enumerable: true, get: function () { return ConfigAction_1.ConfigAction; } });
|
|
10
|
-
var CopyAction_1 = require("./
|
|
10
|
+
var CopyAction_1 = require("./actions/CopyAction");
|
|
11
11
|
Object.defineProperty(exports, "CopyAction", { enumerable: true, get: function () { return CopyAction_1.CopyAction; } });
|
|
12
|
-
var InitAction_1 = require("./
|
|
12
|
+
var InitAction_1 = require("./actions/InitAction");
|
|
13
13
|
Object.defineProperty(exports, "InitAction", { enumerable: true, get: function () { return InitAction_1.InitAction; } });
|
|
14
|
-
var PruneAction_1 = require("./
|
|
14
|
+
var PruneAction_1 = require("./actions/PruneAction");
|
|
15
15
|
Object.defineProperty(exports, "PruneAction", { enumerable: true, get: function () { return PruneAction_1.PruneAction; } });
|
|
16
|
-
var RestoreAction_1 = require("./
|
|
16
|
+
var RestoreAction_1 = require("./actions/RestoreAction");
|
|
17
17
|
Object.defineProperty(exports, "RestoreAction", { enumerable: true, get: function () { return RestoreAction_1.RestoreAction; } });
|
|
18
|
-
var SnapshotsAction_1 = require("./
|
|
18
|
+
var SnapshotsAction_1 = require("./actions/SnapshotsAction");
|
|
19
19
|
Object.defineProperty(exports, "SnapshotsAction", { enumerable: true, get: function () { return SnapshotsAction_1.SnapshotsAction; } });
|
|
20
20
|
var cli_1 = require("./cli");
|
|
21
21
|
Object.defineProperty(exports, "parseArgs", { enumerable: true, get: function () { return cli_1.parseArgs; } });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DatatruckRepository = exports.datatruckRepositoryName = void 0;
|
|
4
|
-
const AppError_1 = require("../Error/AppError");
|
|
5
4
|
const cli_1 = require("../utils/cli");
|
|
6
5
|
const crypto_1 = require("../utils/crypto");
|
|
7
6
|
const client_1 = require("../utils/datatruck/client");
|
|
7
|
+
const error_1 = require("../utils/datatruck/error");
|
|
8
8
|
const paths_1 = require("../utils/datatruck/paths");
|
|
9
9
|
const fs_1 = require("../utils/fs");
|
|
10
10
|
const math_1 = require("../utils/math");
|
|
@@ -295,7 +295,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
295
295
|
},
|
|
296
296
|
});
|
|
297
297
|
if (!snapshot)
|
|
298
|
-
throw new
|
|
298
|
+
throw new error_1.AppError("Snapshot not found");
|
|
299
299
|
const snapshotName = DatatruckRepository.buildSnapshotName(snapshot, data.package);
|
|
300
300
|
const meta = await DatatruckRepository.parseMetaData(await fs.readFile(`${snapshotName}/meta.json`));
|
|
301
301
|
const progress = (0, fs_1.createProgress)({ onProgress: data.onProgress });
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { BackupActionOptions } from "../
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { PackageConfig } from "../Config/PackageConfig";
|
|
6
|
-
import type { RepositoryConfig } from "../Config/RepositoryConfig";
|
|
1
|
+
import type { BackupActionOptions } from "../actions/BackupAction";
|
|
2
|
+
import type { RestoreActionOptions } from "../actions/RestoreAction";
|
|
3
|
+
import type { ExtendedSnapshot, SnapshotsActionOptions } from "../actions/SnapshotsAction";
|
|
4
|
+
import type { PackageConfig, RepositoryConfig } from "../utils/datatruck/config-type";
|
|
7
5
|
import { type DiskStats } from "../utils/fs";
|
|
8
6
|
import type { Progress } from "../utils/progress";
|
|
9
7
|
export type PreSnapshot = {
|
|
@@ -18,7 +16,9 @@ export type Snapshot = PreSnapshot & {
|
|
|
18
16
|
size: number;
|
|
19
17
|
};
|
|
20
18
|
export type RepoInitData = {
|
|
21
|
-
options:
|
|
19
|
+
options: {
|
|
20
|
+
verbose?: boolean;
|
|
21
|
+
};
|
|
22
22
|
};
|
|
23
23
|
export type RepoFetchSnapshotsData = {
|
|
24
24
|
options: Pick<SnapshotsActionOptions, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ResticRepository = exports.resticRepositoryName = void 0;
|
|
7
|
-
const AppError_1 = require("../Error/AppError");
|
|
8
7
|
const Restic_1 = require("../utils/Restic");
|
|
9
8
|
const cli_1 = require("../utils/cli");
|
|
9
|
+
const error_1 = require("../utils/datatruck/error");
|
|
10
10
|
const paths_1 = require("../utils/datatruck/paths");
|
|
11
11
|
const fs_1 = require("../utils/fs");
|
|
12
12
|
const math_1 = require("../utils/math");
|
|
@@ -175,7 +175,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
if (data.options.tags?.some((tag) => tag.startsWith(ResticRepository.refPrefix)))
|
|
178
|
-
throw new
|
|
178
|
+
throw new error_1.AppError(`Tag prefix is not allowed`);
|
|
179
179
|
const packageTag = ResticRepository.buildSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.PACKAGE, data.package.name);
|
|
180
180
|
data.onProgress({
|
|
181
181
|
relative: {
|
|
@@ -255,9 +255,9 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
255
255
|
},
|
|
256
256
|
});
|
|
257
257
|
if (typeof resticSnapshotId !== "string")
|
|
258
|
-
throw new
|
|
258
|
+
throw new error_1.AppError(`Restic snapshot id is is not defined`);
|
|
259
259
|
if (typeof resticTotalBytes !== "number")
|
|
260
|
-
throw new
|
|
260
|
+
throw new error_1.AppError(`Restic snapshot total bytes is not defined`);
|
|
261
261
|
const sizeTag = ResticRepository.buildSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.SIZE, resticTotalBytes.toString());
|
|
262
262
|
await restic.exec(["tag", "--add", sizeTag, resticSnapshotId]);
|
|
263
263
|
data.onProgress({
|
|
@@ -274,10 +274,11 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
274
274
|
options: {
|
|
275
275
|
ids: [data.snapshot.id],
|
|
276
276
|
packageNames: [data.package.name],
|
|
277
|
+
verbose: data.options.verbose,
|
|
277
278
|
},
|
|
278
279
|
});
|
|
279
280
|
if (!snapshot)
|
|
280
|
-
throw new
|
|
281
|
+
throw new error_1.AppError(`Snapshot not found`);
|
|
281
282
|
const restic = new Restic_1.Restic({
|
|
282
283
|
env: {
|
|
283
284
|
...(await this.buildEnv()),
|
|
@@ -305,7 +306,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
305
306
|
},
|
|
306
307
|
});
|
|
307
308
|
if (!snapshot)
|
|
308
|
-
throw new
|
|
309
|
+
throw new error_1.AppError(`Snapshot not found`);
|
|
309
310
|
await restic.restore({
|
|
310
311
|
id: snapshot.originalId,
|
|
311
312
|
target: restorePath,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MssqlTask = exports.mssqlTaskName = void 0;
|
|
4
|
-
const AppError_1 = require("../Error/AppError");
|
|
5
4
|
const config_1 = require("../utils/datatruck/config");
|
|
5
|
+
const error_1 = require("../utils/datatruck/error");
|
|
6
6
|
const fs_1 = require("../utils/fs");
|
|
7
7
|
const process_1 = require("../utils/process");
|
|
8
8
|
const temp_1 = require("../utils/temp");
|
|
@@ -88,7 +88,7 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
|
|
|
88
88
|
const databasePath = (0, path_1.join)(snapshotPath, file);
|
|
89
89
|
const exists = await this.fetchDatabaseNames(databaseName);
|
|
90
90
|
if (exists.length)
|
|
91
|
-
throw new
|
|
91
|
+
throw new error_1.AppError(`Target database already exists: ${databaseName}`);
|
|
92
92
|
await this.exec(`RESTORE DATABASE [${databaseName}] FROM disk='${databasePath}'`);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlDumpTask = exports.mysqlDumpTaskName = void 0;
|
|
4
|
-
const AppError_1 = require("../Error/AppError");
|
|
5
4
|
const async_1 = require("../utils/async");
|
|
6
5
|
const cli_1 = require("../utils/cli");
|
|
7
6
|
const config_1 = require("../utils/datatruck/config");
|
|
7
|
+
const error_1 = require("../utils/datatruck/error");
|
|
8
8
|
const fs_1 = require("../utils/fs");
|
|
9
9
|
const math_1 = require("../utils/math");
|
|
10
10
|
const mysql_1 = require("../utils/mysql");
|
|
@@ -88,7 +88,7 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
|
88
88
|
const successCsvDump = files.length === 2 &&
|
|
89
89
|
files.every((file) => file === schemaFile || file === dataFile);
|
|
90
90
|
if (!successCsvDump)
|
|
91
|
-
throw new
|
|
91
|
+
throw new error_1.AppError(`Invalid csv dump files: ${files.join(", ")}`);
|
|
92
92
|
const schemaPath = (0, path_1.join)(snapshotPath, `${tableName}${suffix.tableSchema}`);
|
|
93
93
|
await (0, fs_1.safeRename)((0, path_1.join)(tableSharedPath, schemaFile), schemaPath);
|
|
94
94
|
await compressAndClean?.(schemaPath);
|
|
@@ -200,7 +200,7 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
|
200
200
|
// Database check
|
|
201
201
|
if (files.some((f) => f.endsWith(suffix.database)) &&
|
|
202
202
|
!(await sql.isDatabaseEmpty(database.name)))
|
|
203
|
-
throw new
|
|
203
|
+
throw new error_1.AppError(`Target database is not empty: ${database.name}`);
|
|
204
204
|
// Table check
|
|
205
205
|
const restoreTables = [
|
|
206
206
|
...new Set(...files
|
|
@@ -210,7 +210,7 @@ class MysqlDumpTask extends TaskAbstract_1.TaskAbstract {
|
|
|
210
210
|
const serverTables = await sql.fetchTableNames(database.name);
|
|
211
211
|
const errorTables = restoreTables.filter((v) => serverTables.includes(v));
|
|
212
212
|
if (errorTables.length)
|
|
213
|
-
throw new
|
|
213
|
+
throw new error_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
|
|
214
214
|
// Data check
|
|
215
215
|
const dataFiles = files.filter((f) => f.endsWith(suffix.tableData));
|
|
216
216
|
const sharedDir = dataFiles.length
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PreSnapshot } from "../repositories/RepositoryAbstract";
|
|
2
|
+
import type { PackageConfig } from "../utils/datatruck/config-type";
|
|
3
3
|
import { ProcessEnv } from "../utils/process";
|
|
4
4
|
import { SpawnStep } from "../utils/spawnSteps";
|
|
5
5
|
import { TaskBackupData, TaskPrepareRestoreData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqlDumpTaskAbstract = void 0;
|
|
4
|
-
const AppError_1 = require("../Error/AppError");
|
|
5
4
|
const cli_1 = require("../utils/cli");
|
|
6
5
|
const config_1 = require("../utils/datatruck/config");
|
|
6
|
+
const error_1 = require("../utils/datatruck/error");
|
|
7
7
|
const fs_1 = require("../utils/fs");
|
|
8
8
|
const math_1 = require("../utils/math");
|
|
9
9
|
const temp_1 = require("../utils/temp");
|
|
@@ -23,7 +23,7 @@ function serializeSqlFile(input) {
|
|
|
23
23
|
return `${input.table}.table.sql`;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
throw new
|
|
26
|
+
throw new error_1.AppError(`Invalid sql file input: ${JSON.stringify(input)}`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function parseSqlFile(fileName) {
|
|
@@ -177,7 +177,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
177
177
|
// Database check
|
|
178
178
|
const databaseItems = items.filter((v) => v.database);
|
|
179
179
|
if (databaseItems.length && !(await this.onDatabaseIsEmpty(database.name)))
|
|
180
|
-
throw new
|
|
180
|
+
throw new error_1.AppError(`Target database is not empty: ${database.name}`);
|
|
181
181
|
// Table check
|
|
182
182
|
const restoreTables = items
|
|
183
183
|
.filter((v) => v.table)
|
|
@@ -185,7 +185,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
185
185
|
const serverTables = await this.onFetchTableNames(database.name);
|
|
186
186
|
const errorTables = restoreTables.filter((v) => serverTables.includes(v));
|
|
187
187
|
if (errorTables.length) {
|
|
188
|
-
throw new
|
|
188
|
+
throw new error_1.AppError(`Target table already exists: ${errorTables.join(", ")}`);
|
|
189
189
|
}
|
|
190
190
|
await this.onCreateDatabase(database);
|
|
191
191
|
if (this.verbose)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BackupActionOptions } from "../
|
|
2
|
-
import { RestoreActionOptions } from "../
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { BackupActionOptions } from "../actions/BackupAction";
|
|
2
|
+
import { RestoreActionOptions } from "../actions/RestoreAction";
|
|
3
|
+
import { PreSnapshot } from "../repositories/RepositoryAbstract";
|
|
4
|
+
import type { PackageConfig } from "../utils/datatruck/config-type";
|
|
5
5
|
import { Progress } from "../utils/progress";
|
|
6
6
|
type TaskCommonData = {
|
|
7
7
|
package: PackageConfig;
|
package/lib/utils/DataFormat.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DataFormat = exports.dataFormats = void 0;
|
|
7
|
-
const
|
|
7
|
+
const error_1 = require("./datatruck/error");
|
|
8
8
|
const stream_1 = require("./stream");
|
|
9
9
|
const tty_table_1 = __importDefault(require("tty-table"));
|
|
10
10
|
const util_1 = require("util");
|
|
@@ -84,12 +84,12 @@ class DataFormat {
|
|
|
84
84
|
const tpl = options?.tpl || {};
|
|
85
85
|
if (!(name in tpl)) {
|
|
86
86
|
const tplNames = Object.keys(tpl).join(", ");
|
|
87
|
-
throw new
|
|
87
|
+
throw new error_1.AppError(`Template name not found: ${name} (valid names: ${tplNames})`);
|
|
88
88
|
}
|
|
89
89
|
return tpl[name]();
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
|
-
throw new
|
|
92
|
+
throw new error_1.AppError(`Invalid output format: ${format}`);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|