@datatruck/cli 0.16.1 → 0.17.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 +14 -5
- package/Action/BackupAction.js +34 -11
- package/Action/BackupSessionsAction.d.ts +1 -1
- package/Action/CleanCacheAction.d.ts +1 -1
- package/Action/ConfigAction.d.ts +1 -1
- package/Action/InitAction.d.ts +1 -1
- package/Action/PruneAction.d.ts +2 -2
- package/Action/RestoreAction.d.ts +12 -6
- package/Action/RestoreAction.js +24 -10
- package/Action/RestoreSessionsAction.d.ts +1 -1
- package/Action/SnapshotsAction.d.ts +3 -3
- package/Command/BackupCommand.d.ts +1 -1
- package/Command/BackupSessionsCommand.d.ts +1 -1
- package/Command/CleanCacheCommand.d.ts +1 -1
- package/Command/CommandAbstract.d.ts +2 -2
- package/Command/ConfigCommand.d.ts +2 -2
- package/Command/InitCommand.d.ts +2 -2
- package/Command/PruneCommand.d.ts +1 -1
- package/Command/RestoreCommand.d.ts +1 -1
- package/Command/RestoreSessionsCommand.d.ts +1 -1
- package/Command/SnapshotsCommand.d.ts +2 -2
- package/Command/SnapshotsCommand.js +6 -1
- package/Config/Config.d.ts +1 -1
- package/Config/PackageConfig.d.ts +2 -2
- package/Config/PackageRepositoryConfig.d.ts +1 -1
- package/Config/PrunePolicyConfig.d.ts +1 -1
- package/Config/RepositoryConfig.d.ts +3 -3
- package/Config/TaskConfig.d.ts +1 -1
- package/Decorator/EntityDecorator.d.ts +1 -1
- package/Factory/CommandFactory.d.ts +2 -2
- package/Repository/DatatruckRepository.d.ts +4 -4
- package/Repository/DatatruckRepository.js +1 -1
- package/Repository/GitRepository.d.ts +2 -2
- package/Repository/GitRepository.js +3 -3
- package/Repository/RepositoryAbstract.d.ts +11 -9
- package/Repository/RepositoryAbstract.js +7 -0
- package/Repository/ResticRepository.d.ts +2 -2
- package/Repository/ResticRepository.js +3 -1
- package/SessionDriver/ConsoleSessionDriver.d.ts +3 -3
- package/SessionDriver/SessionDriverAbstract.d.ts +4 -4
- package/SessionManager/SessionManagerAbstract.d.ts +1 -1
- package/Task/GitTask.d.ts +1 -1
- package/Task/GitTask.js +2 -2
- package/Task/MariadbTask.d.ts +1 -1
- package/Task/MariadbTask.js +1 -1
- package/Task/MssqlTask.d.ts +1 -1
- package/Task/MysqlDumpTask.d.ts +1 -1
- package/Task/PostgresqlDumpTask.d.ts +1 -1
- package/Task/ScriptTask.d.ts +5 -5
- package/Task/ScriptTask.js +6 -6
- package/Task/SqlDumpTaskAbstract.d.ts +2 -2
- package/Task/SqlDumpTaskAbstract.js +2 -2
- package/Task/TaskAbstract.d.ts +4 -2
- package/Task/TaskAbstract.js +7 -0
- package/package.json +8 -8
- package/util/DataFormat.d.ts +1 -1
- package/util/ObjectVault.d.ts +1 -1
- package/util/ResticUtil.d.ts +3 -2
- package/util/ResticUtil.js +12 -10
- package/util/cli-util.d.ts +1 -1
- package/util/datatruck/config-util.d.ts +9 -9
- package/util/datatruck/config-util.js +1 -1
- package/util/date-util.d.ts +1 -1
- package/util/fs-util.d.ts +4 -1
- package/util/fs-util.js +21 -3
- package/util/object-util.d.ts +1 -1
- package/util/process-util.d.ts +3 -3
- package/util/progress.d.ts +2 -2
- package/util/string-util.d.ts +1 -1
- package/util/zip-util.d.ts +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
|
|
2
2
|
import type { JSONSchema7 } from "json-schema";
|
|
3
|
-
export
|
|
3
|
+
export type MetaDataType = {
|
|
4
4
|
id: string;
|
|
5
5
|
date: string;
|
|
6
6
|
package: string;
|
|
@@ -9,7 +9,7 @@ export declare type MetaDataType = {
|
|
|
9
9
|
version: string;
|
|
10
10
|
size: number;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type DatatruckRepositoryConfigType = {
|
|
13
13
|
outPath: string;
|
|
14
14
|
compress?: boolean;
|
|
15
15
|
/**
|
|
@@ -17,7 +17,7 @@ export declare type DatatruckRepositoryConfigType = {
|
|
|
17
17
|
*/
|
|
18
18
|
fileCopyConcurrency?: number;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type CompressObjectType = {
|
|
21
21
|
packs?: {
|
|
22
22
|
name?: string;
|
|
23
23
|
include: string[];
|
|
@@ -25,7 +25,7 @@ declare type CompressObjectType = {
|
|
|
25
25
|
onePackByResult?: boolean;
|
|
26
26
|
}[];
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type DatatruckPackageRepositoryConfigType = {
|
|
29
29
|
compress?: CompressObjectType | boolean;
|
|
30
30
|
};
|
|
31
31
|
export declare const datatruckRepositoryName = "datatruck";
|
|
@@ -256,7 +256,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
256
256
|
})
|
|
257
257
|
: undefined;
|
|
258
258
|
const packs = compress?.packs || [];
|
|
259
|
-
const tmpDir = await
|
|
259
|
+
const tmpDir = await this.mkTmpDir("path-lists");
|
|
260
260
|
const unpackedStream = (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, "unpacked.txt"));
|
|
261
261
|
const singlePackStream = (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, "single-pack.txt"));
|
|
262
262
|
const packStreams = Array.from({ length: packs.length }).map((v, i) => (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, `pack-${i}.txt`)));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
|
-
export
|
|
3
|
+
export type GitRepositoryConfigType = {
|
|
4
4
|
repo: string;
|
|
5
5
|
branch?: string;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type GitPackageRepositoryConfigType = {};
|
|
8
8
|
export declare const gitRepositoryName = "git";
|
|
9
9
|
export declare const gitRepositoryDefinition: JSONSchema7;
|
|
10
10
|
export declare const gitPackageRepositoryDefinition: JSONSchema7;
|
|
@@ -84,7 +84,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
84
84
|
}
|
|
85
85
|
async onPrune(data) {
|
|
86
86
|
const git = new GitUtil_1.GitUtil({
|
|
87
|
-
dir: await
|
|
87
|
+
dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
|
|
88
88
|
log: data.options.verbose,
|
|
89
89
|
});
|
|
90
90
|
const branchName = GitRepository.buildBranchName(data.snapshot.packageName);
|
|
@@ -107,7 +107,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
107
107
|
}
|
|
108
108
|
async onSnapshots(data) {
|
|
109
109
|
const git = new GitUtil_1.GitUtil({
|
|
110
|
-
dir: await
|
|
110
|
+
dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
|
|
111
111
|
log: data.options.verbose,
|
|
112
112
|
});
|
|
113
113
|
const pkgPatterns = (0, string_util_1.makePathPatterns)(data.options.packageNames);
|
|
@@ -148,7 +148,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
148
148
|
(0, assert_1.ok)(typeof sourcePath === "string");
|
|
149
149
|
if (!(await (0, fs_util_1.existsDir)(sourcePath)))
|
|
150
150
|
throw new AppError_1.AppError(`Package path not exists: ${sourcePath}`);
|
|
151
|
-
const tmpPath = await
|
|
151
|
+
const tmpPath = await this.mkTmpDir(GitRepository.name + "-backup");
|
|
152
152
|
const branchName = GitRepository.buildBranchName(data.package.name);
|
|
153
153
|
const git = new GitUtil_1.GitUtil({
|
|
154
154
|
dir: tmpPath,
|
|
@@ -5,31 +5,31 @@ import type { SnapshotExtendedType, SnapshotsActionOptionsType } from "../Action
|
|
|
5
5
|
import type { PackageConfigType } from "../Config/PackageConfig";
|
|
6
6
|
import type { RepositoryConfigType } from "../Config/RepositoryConfig";
|
|
7
7
|
import { Progress } from "../util/progress";
|
|
8
|
-
export
|
|
8
|
+
export type SnapshotType = {
|
|
9
9
|
id: string;
|
|
10
10
|
date: string;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type SnapshotResultType = SnapshotType & {
|
|
13
13
|
originalId: string;
|
|
14
14
|
packageName: string;
|
|
15
15
|
packageTaskName: string | undefined;
|
|
16
16
|
tags: string[];
|
|
17
17
|
size: number;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type InitDataType = {
|
|
20
20
|
options: InitActionOptionsType;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type SnapshotsDataType = {
|
|
23
23
|
options: Pick<SnapshotsActionOptionsType, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
25
|
+
export type CopyBackupType<TRepositoryConfig> = {
|
|
26
26
|
options: BackupActionOptionsType;
|
|
27
27
|
snapshot: SnapshotType;
|
|
28
28
|
package: PackageConfigType;
|
|
29
29
|
mirrorRepositoryConfig: TRepositoryConfig;
|
|
30
30
|
onProgress: (data: Progress) => Promise<void>;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
32
|
+
export type BackupDataType<TPackageConfig> = {
|
|
33
33
|
options: BackupActionOptionsType;
|
|
34
34
|
snapshot: SnapshotType;
|
|
35
35
|
package: PackageConfigType;
|
|
@@ -37,7 +37,7 @@ export declare type BackupDataType<TPackageConfig> = {
|
|
|
37
37
|
packageConfig: TPackageConfig | undefined;
|
|
38
38
|
onProgress: (data: Progress) => Promise<void>;
|
|
39
39
|
};
|
|
40
|
-
export
|
|
40
|
+
export type RestoreDataType<TPackageConfig> = {
|
|
41
41
|
options: RestoreActionOptionsType;
|
|
42
42
|
snapshot: SnapshotType;
|
|
43
43
|
package: PackageConfigType;
|
|
@@ -45,7 +45,7 @@ export declare type RestoreDataType<TPackageConfig> = {
|
|
|
45
45
|
packageConfig: TPackageConfig;
|
|
46
46
|
onProgress: (data: Progress) => Promise<void>;
|
|
47
47
|
};
|
|
48
|
-
export
|
|
48
|
+
export type PruneDataType = {
|
|
49
49
|
snapshot: SnapshotExtendedType;
|
|
50
50
|
options: {
|
|
51
51
|
verbose?: boolean;
|
|
@@ -61,7 +61,7 @@ export declare enum SnapshotTagEnum {
|
|
|
61
61
|
VERSION = "version",
|
|
62
62
|
SIZE = "size"
|
|
63
63
|
}
|
|
64
|
-
export
|
|
64
|
+
export type SnapshotTagObjectType = {
|
|
65
65
|
[SnapshotTagEnum.ID]: string;
|
|
66
66
|
[SnapshotTagEnum.SHORT_ID]: string;
|
|
67
67
|
[SnapshotTagEnum.DATE]: string;
|
|
@@ -74,7 +74,9 @@ export declare type SnapshotTagObjectType = {
|
|
|
74
74
|
export declare abstract class RepositoryAbstract<TConfig> {
|
|
75
75
|
readonly repository: RepositoryConfigType;
|
|
76
76
|
readonly config: TConfig;
|
|
77
|
+
readonly tmpDirs: string[];
|
|
77
78
|
constructor(repository: RepositoryConfigType);
|
|
79
|
+
mkTmpDir(prefix: string, id?: string): Promise<string>;
|
|
78
80
|
abstract onGetSource(): string;
|
|
79
81
|
abstract onInit(data: InitDataType): Promise<void>;
|
|
80
82
|
abstract onPrune(data: PruneDataType): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RepositoryAbstract = exports.SnapshotTagEnum = void 0;
|
|
4
|
+
const fs_util_1 = require("../util/fs-util");
|
|
4
5
|
var SnapshotTagEnum;
|
|
5
6
|
(function (SnapshotTagEnum) {
|
|
6
7
|
SnapshotTagEnum["ID"] = "id";
|
|
@@ -15,7 +16,13 @@ var SnapshotTagEnum;
|
|
|
15
16
|
class RepositoryAbstract {
|
|
16
17
|
constructor(repository) {
|
|
17
18
|
this.repository = repository;
|
|
19
|
+
this.tmpDirs = [];
|
|
18
20
|
this.config = repository.config;
|
|
19
21
|
}
|
|
22
|
+
async mkTmpDir(prefix, id) {
|
|
23
|
+
const dir = await (0, fs_util_1.mkTmpDir)(prefix, id);
|
|
24
|
+
this.tmpDirs.push(dir);
|
|
25
|
+
return dir;
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
exports.RepositoryAbstract = RepositoryAbstract;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RepositoryType } from "../util/ResticUtil";
|
|
2
2
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
|
-
export
|
|
4
|
+
export type ResticRepositoryConfigType = {
|
|
5
5
|
password: string | {
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
8
|
repository: RepositoryType;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type ResticPackageRepositoryConfigType = {};
|
|
11
11
|
export declare const resticRepositoryName = "restic";
|
|
12
12
|
export declare const resticRepositoryDefinition: JSONSchema7;
|
|
13
13
|
export declare const resticPackageRepositoryDefinition: JSONSchema7;
|
|
@@ -199,7 +199,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
199
199
|
description: "Writing excluded paths list",
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
|
-
const tmpDir = await
|
|
202
|
+
const tmpDir = await this.mkTmpDir("restic-exclude");
|
|
203
203
|
const ignoredContents = (0, fs_util_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);
|
|
@@ -231,6 +231,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
231
231
|
});
|
|
232
232
|
gitignorePath = await (0, fs_util_1.writeGitIgnoreList)({
|
|
233
233
|
paths: stream,
|
|
234
|
+
outDir: await this.mkTmpDir("gitignore-list"),
|
|
234
235
|
});
|
|
235
236
|
}
|
|
236
237
|
if (data.options.tags?.some((tag) => tag.startsWith(ResticRepository.refPrefix)))
|
|
@@ -280,6 +281,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
280
281
|
: []),
|
|
281
282
|
...(data.options.tags ?? []),
|
|
282
283
|
],
|
|
284
|
+
createEmptyDir: async () => await this.mkTmpDir("empty"),
|
|
283
285
|
onStream: async (streamData) => {
|
|
284
286
|
if (streamData.message_type === "status") {
|
|
285
287
|
let showProgressBar = false;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Progress } from "../util/progress";
|
|
3
3
|
import { WriteDataType, ReadResultType, SessionDriverAbstract, SessionDriverOptions } from "./SessionDriverAbstract";
|
|
4
|
-
|
|
4
|
+
type BadgeType = {
|
|
5
5
|
name: string;
|
|
6
6
|
value: string;
|
|
7
7
|
color: (input: string) => string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type MessageType = {
|
|
10
10
|
sessionId: number;
|
|
11
11
|
level?: number;
|
|
12
12
|
textPrefix?: string;
|
|
@@ -15,7 +15,7 @@ declare type MessageType = {
|
|
|
15
15
|
errorBadge?: BadgeType;
|
|
16
16
|
progress?: Progress;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type ConsoleSessionDriverOptions = SessionDriverOptions & {
|
|
19
19
|
progress?: "auto" | "tty" | "plain";
|
|
20
20
|
};
|
|
21
21
|
export declare class ConsoleSessionDriver extends SessionDriverAbstract<ConsoleSessionDriverOptions> {
|
|
@@ -18,7 +18,7 @@ export declare enum EntityEnum {
|
|
|
18
18
|
RestoreSessionTask = 4,
|
|
19
19
|
RestoreSessionRepository = 5
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type WriteDataType = {
|
|
22
22
|
action: ActionEnum;
|
|
23
23
|
entity: EntityEnum.BackupSession;
|
|
24
24
|
data: BackupSessionEntity;
|
|
@@ -47,14 +47,14 @@ export declare type WriteDataType = {
|
|
|
47
47
|
data: RestoreSessionRepositoryEntity;
|
|
48
48
|
sessionData: RestoreSessionEntity;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type ReadDataType = {
|
|
51
51
|
repositoryNames?: string[];
|
|
52
52
|
packageNames?: string[];
|
|
53
53
|
tags?: string[];
|
|
54
54
|
limit?: number | null;
|
|
55
55
|
verbose?: boolean;
|
|
56
56
|
};
|
|
57
|
-
export
|
|
57
|
+
export type ReadResultType = {
|
|
58
58
|
id: number;
|
|
59
59
|
snapshotId: string;
|
|
60
60
|
creationDate: string;
|
|
@@ -64,7 +64,7 @@ export declare type ReadResultType = {
|
|
|
64
64
|
repositoryType: string;
|
|
65
65
|
error: string | null;
|
|
66
66
|
};
|
|
67
|
-
export
|
|
67
|
+
export type SessionDriverOptions = {
|
|
68
68
|
verbose?: boolean;
|
|
69
69
|
};
|
|
70
70
|
export declare abstract class SessionDriverAbstract<TOptions extends SessionDriverOptions = SessionDriverOptions> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { SessionDriverAbstract } from "../SessionDriver/SessionDriverAbstract";
|
|
3
|
-
export
|
|
3
|
+
export type OptionsType = {
|
|
4
4
|
driver: SessionDriverAbstract;
|
|
5
5
|
altDrivers?: SessionDriverAbstract[];
|
|
6
6
|
progressInterval?: number;
|
package/Task/GitTask.d.ts
CHANGED
package/Task/GitTask.js
CHANGED
|
@@ -60,7 +60,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
60
60
|
}
|
|
61
61
|
async onBeforeBackup() {
|
|
62
62
|
return {
|
|
63
|
-
targetPath: await
|
|
63
|
+
targetPath: await this.mkTmpDir(GitTask.name),
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
async onBackup(data) {
|
|
@@ -193,7 +193,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
|
|
|
193
193
|
}
|
|
194
194
|
async onBeforeRestore() {
|
|
195
195
|
return {
|
|
196
|
-
targetPath: await
|
|
196
|
+
targetPath: await this.mkTmpDir(GitTask.name),
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
async onRestore(data) {
|
package/Task/MariadbTask.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
|
-
export
|
|
3
|
+
export type MariadbTaskConfigType = {
|
|
4
4
|
command?: string;
|
|
5
5
|
hostname: string;
|
|
6
6
|
username: string;
|
package/Task/MariadbTask.js
CHANGED
package/Task/MssqlTask.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
|
-
export
|
|
3
|
+
export type MssqlTaskConfigType = {
|
|
4
4
|
command?: string;
|
|
5
5
|
hostname?: string;
|
|
6
6
|
username?: string;
|
package/Task/MysqlDumpTask.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SqlDumpTaskAbstract, SqlDumpTaskConfigType, TargetDatabaseType } from "./SqlDumpTaskAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
3
|
export declare const mysqlDumpTaskName = "mysql-dump";
|
|
4
|
-
export
|
|
4
|
+
export type MysqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
|
|
5
5
|
export declare const mysqlDumpTaskDefinition: JSONSchema7;
|
|
6
6
|
export declare class MysqlDumpTask extends SqlDumpTaskAbstract<MysqlDumpTaskConfigType> {
|
|
7
7
|
buildConnectionArgs(database?: boolean): Promise<string[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SqlDumpTaskAbstract, SqlDumpTaskConfigType, TargetDatabaseType } from "./SqlDumpTaskAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
3
|
export declare const postgresqlDumpTaskName = "postgresql-dump";
|
|
4
|
-
export
|
|
4
|
+
export type PostgresqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
|
|
5
5
|
export declare const postgresqlDumpTaskDefinition: JSONSchema7;
|
|
6
6
|
export declare class PostgresqlDumpTask extends SqlDumpTaskAbstract<PostgresqlDumpTaskConfigType> {
|
|
7
7
|
buildConnectionArgs(database?: string): Promise<string[]>;
|
package/Task/ScriptTask.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
|
|
2
2
|
import { JSONSchema7 } from "json-schema";
|
|
3
|
-
export
|
|
3
|
+
export type ProcessStepConfig = {
|
|
4
4
|
command: string;
|
|
5
5
|
env?: Record<string, string>;
|
|
6
6
|
args?: string[];
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type NodeStepConfig = {
|
|
9
9
|
env?: Record<string, string>;
|
|
10
10
|
code: string | string[];
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type Step = {
|
|
13
13
|
type: "process";
|
|
14
14
|
config: ProcessStepConfig;
|
|
15
15
|
} | {
|
|
16
16
|
type: "node";
|
|
17
17
|
config: NodeStepConfig;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type ScriptTaskConfigType = {
|
|
20
20
|
env?: Record<string, string | undefined>;
|
|
21
21
|
backupSteps: Step[];
|
|
22
22
|
restoreSteps: Step[];
|
|
@@ -29,7 +29,7 @@ export declare class ScriptTask extends TaskAbstract<ScriptTaskConfigType> {
|
|
|
29
29
|
targetPath: string;
|
|
30
30
|
}>;
|
|
31
31
|
protected getVars(data: BackupDataType | RestoreDataType): Record<string, string | undefined>;
|
|
32
|
-
|
|
32
|
+
protected processSteps(input: Step[] | Step, options: {
|
|
33
33
|
env?: Record<string, string | undefined>;
|
|
34
34
|
vars: Record<string, string | undefined>;
|
|
35
35
|
verbose?: boolean;
|
package/Task/ScriptTask.js
CHANGED
|
@@ -94,7 +94,7 @@ exports.scriptTaskDefinition = {
|
|
|
94
94
|
class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
95
95
|
async onBeforeBackup() {
|
|
96
96
|
return {
|
|
97
|
-
targetPath: await
|
|
97
|
+
targetPath: await this.mkTmpDir(ScriptTask.name),
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
getVars(data) {
|
|
@@ -106,7 +106,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
106
106
|
DTT_TARGET_PATH: data.targetPath,
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
async processSteps(input, options) {
|
|
110
110
|
const steps = Array.isArray(input) ? input : [input];
|
|
111
111
|
for (const step of steps) {
|
|
112
112
|
if (step.type === "process") {
|
|
@@ -122,7 +122,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
else if (step.type === "node") {
|
|
125
|
-
const tempDir = await
|
|
125
|
+
const tempDir = await this.mkTmpDir("script-task-node-step");
|
|
126
126
|
const scriptPath = (0, path_1.join)(tempDir, "script.js");
|
|
127
127
|
await (0, promises_1.writeFile)(scriptPath, Array.isArray(step.config.code)
|
|
128
128
|
? step.config.code.join("\n")
|
|
@@ -150,7 +150,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
150
150
|
const targetPath = data.targetPath;
|
|
151
151
|
(0, assert_1.ok)(typeof path === "string");
|
|
152
152
|
(0, assert_1.ok)(typeof targetPath === "string");
|
|
153
|
-
await
|
|
153
|
+
await this.processSteps(config.backupSteps, {
|
|
154
154
|
env: config.env,
|
|
155
155
|
vars: this.getVars(data),
|
|
156
156
|
verbose: this.verbose,
|
|
@@ -158,7 +158,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
158
158
|
}
|
|
159
159
|
async onBeforeRestore() {
|
|
160
160
|
return {
|
|
161
|
-
targetPath: await
|
|
161
|
+
targetPath: await this.mkTmpDir(ScriptTask.name),
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
async onRestore(data) {
|
|
@@ -170,7 +170,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
|
|
|
170
170
|
(0, assert_1.ok)(typeof targetPath === "string");
|
|
171
171
|
await (0, fs_util_1.mkdirIfNotExists)(restorePath);
|
|
172
172
|
await (0, fs_util_1.ensureEmptyDir)(restorePath);
|
|
173
|
-
await
|
|
173
|
+
await this.processSteps(config.restoreSteps, {
|
|
174
174
|
env: config.env,
|
|
175
175
|
vars: this.getVars(data),
|
|
176
176
|
verbose: this.verbose,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { exec } from "../util/process-util";
|
|
2
2
|
import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
|
-
export
|
|
4
|
+
export type TargetDatabaseType = {
|
|
5
5
|
name: string;
|
|
6
6
|
charset?: string;
|
|
7
7
|
collate?: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type SqlDumpTaskConfigType = {
|
|
10
10
|
password: string | {
|
|
11
11
|
path: string;
|
|
12
12
|
};
|
|
@@ -118,7 +118,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
118
118
|
await (0, promises_1.mkdir)(outputPath, { recursive: true });
|
|
119
119
|
if (!this.config.oneFileByTable) {
|
|
120
120
|
const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ database: this.config.database }));
|
|
121
|
-
data.onProgress({
|
|
121
|
+
await data.onProgress({
|
|
122
122
|
relative: {
|
|
123
123
|
description: "Exporting",
|
|
124
124
|
},
|
|
@@ -168,7 +168,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
|
|
|
168
168
|
}
|
|
169
169
|
if (this.config.storedPrograms) {
|
|
170
170
|
const outPath = (0, path_1.join)(outputPath, "stored-programs.sql");
|
|
171
|
-
data.onProgress({
|
|
171
|
+
await data.onProgress({
|
|
172
172
|
relative: {
|
|
173
173
|
description: "Exporting storaged programs",
|
|
174
174
|
},
|
package/Task/TaskAbstract.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { RestoreActionOptionsType } from "../Action/RestoreAction";
|
|
|
3
3
|
import { PackageConfigType } from "../Config/PackageConfig";
|
|
4
4
|
import { SnapshotType } from "../Repository/RepositoryAbstract";
|
|
5
5
|
import { Progress } from "../util/progress";
|
|
6
|
-
export
|
|
6
|
+
export type BackupDataType = {
|
|
7
7
|
onProgress: (data: Progress) => Promise<void>;
|
|
8
8
|
options: BackupActionOptionsType;
|
|
9
9
|
package: PackageConfigType;
|
|
10
10
|
targetPath: string | undefined;
|
|
11
11
|
snapshot: SnapshotType;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type RestoreDataType = {
|
|
14
14
|
onProgress: (data: Progress) => Promise<void>;
|
|
15
15
|
options: RestoreActionOptionsType;
|
|
16
16
|
package: PackageConfigType;
|
|
@@ -19,7 +19,9 @@ export declare type RestoreDataType = {
|
|
|
19
19
|
};
|
|
20
20
|
export declare abstract class TaskAbstract<TConfig = any> {
|
|
21
21
|
readonly config: TConfig;
|
|
22
|
+
readonly tmpDirs: string[];
|
|
22
23
|
constructor(config: TConfig);
|
|
24
|
+
mkTmpDir(prefix: string, id?: string): Promise<string>;
|
|
23
25
|
onBeforeBackup(data: Omit<BackupDataType, "onProgress" | "targetPath">): Promise<{
|
|
24
26
|
targetPath?: string;
|
|
25
27
|
} | undefined>;
|
package/Task/TaskAbstract.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TaskAbstract = void 0;
|
|
4
|
+
const fs_util_1 = require("../util/fs-util");
|
|
4
5
|
class TaskAbstract {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.config = config;
|
|
8
|
+
this.tmpDirs = [];
|
|
9
|
+
}
|
|
10
|
+
async mkTmpDir(prefix, id) {
|
|
11
|
+
const dir = await (0, fs_util_1.mkTmpDir)(prefix, id);
|
|
12
|
+
this.tmpDirs.push(dir);
|
|
13
|
+
return dir;
|
|
7
14
|
}
|
|
8
15
|
async onBeforeBackup(data) {
|
|
9
16
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datatruck/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"ajv": "^8.11.
|
|
5
|
+
"ajv": "^8.11.2",
|
|
6
6
|
"async": "^3.2.4",
|
|
7
7
|
"chalk": "^4.1.2",
|
|
8
|
-
"cli-table3": "^0.6.
|
|
9
|
-
"commander": "^9.4.
|
|
10
|
-
"dayjs": "^1.11.
|
|
8
|
+
"cli-table3": "^0.6.3",
|
|
9
|
+
"commander": "^9.4.1",
|
|
10
|
+
"dayjs": "^1.11.7",
|
|
11
11
|
"fast-folder-size": "^1.7.1",
|
|
12
|
-
"fast-glob": "^3.2.
|
|
12
|
+
"fast-glob": "^3.2.12",
|
|
13
13
|
"micromatch": "^4.0.5",
|
|
14
14
|
"pretty-bytes": "^5.6.0",
|
|
15
15
|
"sqlite": "^4.1.2",
|
|
16
|
-
"sqlite3": "^5.
|
|
16
|
+
"sqlite3": "^5.1.4"
|
|
17
17
|
},
|
|
18
18
|
"optionalDependencies": {
|
|
19
19
|
"ts-node": "^10.9.1",
|
|
20
|
-
"yaml": "^2.
|
|
20
|
+
"yaml": "^2.2.0"
|
|
21
21
|
},
|
|
22
22
|
"engine": {
|
|
23
23
|
"node": ">=16.0.0"
|
package/util/DataFormat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type FormatType = "json" | "pjson" | "table" | "yaml" | "custom" | "tpl";
|
|
2
2
|
export declare class DataFormat<TItem extends Record<string, unknown>> {
|
|
3
3
|
readonly options: {
|
|
4
4
|
items: TItem[];
|
package/util/ObjectVault.d.ts
CHANGED
package/util/ResticUtil.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExecResultType, ExecSettingsInterface } from "./process-util";
|
|
2
2
|
import { UriType } from "./string-util";
|
|
3
|
-
export
|
|
3
|
+
export type RepositoryType = {
|
|
4
4
|
name?: string;
|
|
5
5
|
env?: Record<string, string>;
|
|
6
6
|
password?: string | {
|
|
@@ -8,7 +8,7 @@ export declare type RepositoryType = {
|
|
|
8
8
|
};
|
|
9
9
|
backend: "local" | "rest" | "sftp" | "s3" | "azure" | "gs" | "rclone";
|
|
10
10
|
} & Omit<UriType, "password">;
|
|
11
|
-
export
|
|
11
|
+
export type BackupStreamType = {
|
|
12
12
|
message_type: "status";
|
|
13
13
|
seconds_elapsed?: number;
|
|
14
14
|
percent_done: number;
|
|
@@ -90,6 +90,7 @@ export declare class ResticUtil {
|
|
|
90
90
|
parent?: string;
|
|
91
91
|
allowEmptySnapshot?: boolean;
|
|
92
92
|
onStream?: (data: BackupStreamType) => void;
|
|
93
|
+
createEmptyDir?: () => Promise<string>;
|
|
93
94
|
}): Promise<ExecResultType>;
|
|
94
95
|
copy(options: {
|
|
95
96
|
id: string;
|
package/util/ResticUtil.js
CHANGED
|
@@ -148,16 +148,18 @@ class ResticUtil {
|
|
|
148
148
|
catch (error) {
|
|
149
149
|
if (options.allowEmptySnapshot &&
|
|
150
150
|
error.message.includes("unable to save snapshot: snapshot is empty")) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
151
|
+
if (options.createEmptyDir) {
|
|
152
|
+
const emptyPath = await options.createEmptyDir();
|
|
153
|
+
await (0, promises_1.writeFile)(`${emptyPath}/.empty`, "");
|
|
154
|
+
return await this.backup({
|
|
155
|
+
...options,
|
|
156
|
+
cwd: emptyPath,
|
|
157
|
+
allowEmptySnapshot: false,
|
|
158
|
+
paths: ["."],
|
|
159
|
+
exclude: [],
|
|
160
|
+
excludeFile: [],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
161
163
|
}
|
|
162
164
|
throw error;
|
|
163
165
|
}
|