@datatruck/cli 0.3.2 → 0.6.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.js +1 -0
- package/Action/ConfigAction.d.ts +6 -1
- package/Action/ConfigAction.js +17 -1
- package/Action/InitAction.js +3 -0
- package/Action/PruneAction.js +1 -1
- package/Action/RestoreAction.js +4 -1
- package/Action/SnapshotsAction.d.ts +2 -1
- package/Action/SnapshotsAction.js +6 -1
- package/CHANGELOG.md +28 -0
- package/Command/BackupCommand.js +1 -5
- package/Command/BackupSessionsCommand.js +1 -5
- package/Command/CommandAbstract.d.ts +2 -1
- package/Command/ConfigCommand.js +1 -5
- package/Command/InitCommand.js +1 -5
- package/Command/PruneCommand.js +1 -5
- package/Command/RestoreCommand.js +1 -5
- package/Command/RestoreSessionsCommand.js +1 -5
- package/Command/SnapshotsCommand.js +1 -5
- package/Config/Config.d.ts +1 -0
- package/Config/Config.js +1 -0
- package/Config/RepositoryConfig.d.ts +4 -0
- package/Config/RepositoryConfig.js +19 -0
- package/Repository/GitRepository.js +2 -3
- package/Repository/LocalRepository.d.ts +4 -0
- package/Repository/LocalRepository.js +38 -37
- package/Repository/RepositoryAbstract.d.ts +4 -4
- package/Repository/ResticRepository.d.ts +7 -3
- package/Repository/ResticRepository.js +33 -12
- package/SessionDriver/ConsoleSessionDriver.js +12 -11
- package/Task/GitTask.d.ts +4 -0
- package/Task/GitTask.js +28 -29
- package/Task/MariadbTask.js +26 -14
- package/Task/MssqlTask.js +1 -2
- package/Task/TaskAbstract.d.ts +4 -4
- package/cli.js +18 -1
- package/config.schema.json +61 -3
- package/globalData.d.ts +5 -0
- package/globalData.js +7 -0
- package/package.json +2 -2
- package/util/GitUtil.js +2 -2
- package/util/ResticUtil.js +1 -2
- package/util/datatruck/config-util.d.ts +4 -1
- package/util/datatruck/config-util.js +11 -1
- package/util/fs-util.d.ts +33 -0
- package/util/fs-util.js +78 -7
package/Action/BackupAction.js
CHANGED
|
@@ -23,6 +23,7 @@ class BackupAction {
|
|
|
23
23
|
packageNames: this.options.packageNames,
|
|
24
24
|
repositoryNames: this.options.repositoryNames,
|
|
25
25
|
repositoryTypes: this.options.repositoryTypes,
|
|
26
|
+
sourceAction: "backup",
|
|
26
27
|
});
|
|
27
28
|
packages = (0, config_util_1.resolvePackages)(packages, {
|
|
28
29
|
snapshotId: snapshot.id,
|
package/Action/ConfigAction.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GlobalOptionsType } from "../Command/CommandAbstract";
|
|
1
2
|
import type { ConfigType } from "../Config/Config";
|
|
2
3
|
import { IfRequireKeys } from "../util/ts-util";
|
|
3
4
|
export declare type ConfigActionOptionsType = {
|
|
@@ -10,5 +11,9 @@ export declare class ConfigAction<TRequired extends boolean = true> {
|
|
|
10
11
|
static validate(config: ConfigType): void;
|
|
11
12
|
static check(config: ConfigType): void;
|
|
12
13
|
static normalize(config: ConfigType): ConfigType;
|
|
13
|
-
|
|
14
|
+
static fromGlobalOptions(globalOptions: GlobalOptionsType<true>): Promise<ConfigType>;
|
|
15
|
+
exec(): Promise<{
|
|
16
|
+
path: string;
|
|
17
|
+
data: ConfigType;
|
|
18
|
+
}>;
|
|
14
19
|
}
|
package/Action/ConfigAction.js
CHANGED
|
@@ -53,12 +53,28 @@ class ConfigAction {
|
|
|
53
53
|
});
|
|
54
54
|
return config;
|
|
55
55
|
}
|
|
56
|
+
static async fromGlobalOptions(globalOptions) {
|
|
57
|
+
if (typeof globalOptions.config === "string") {
|
|
58
|
+
const configAction = new ConfigAction({
|
|
59
|
+
path: globalOptions.config,
|
|
60
|
+
verbose: !!globalOptions.verbose && globalOptions.verbose > 0,
|
|
61
|
+
});
|
|
62
|
+
const result = await configAction.exec();
|
|
63
|
+
return result.data;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return globalOptions.config;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
56
69
|
async exec() {
|
|
57
70
|
const path = await (0, fs_util_1.findFile)(this.options.path, "datatruck.config", fs_util_1.parseFileExtensions, "Config path not found");
|
|
58
71
|
const config = await (0, fs_util_1.parseFile)(path, "config");
|
|
59
72
|
ConfigAction.validate(config);
|
|
60
73
|
ConfigAction.check(config);
|
|
61
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
path,
|
|
76
|
+
data: ConfigAction.normalize(config),
|
|
77
|
+
};
|
|
62
78
|
}
|
|
63
79
|
}
|
|
64
80
|
exports.ConfigAction = ConfigAction;
|
package/Action/InitAction.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitAction = void 0;
|
|
4
4
|
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
|
+
const config_util_1 = require("../util/datatruck/config-util");
|
|
5
6
|
class InitAction {
|
|
6
7
|
constructor(config, options) {
|
|
7
8
|
this.config = config;
|
|
@@ -10,6 +11,8 @@ class InitAction {
|
|
|
10
11
|
async exec() {
|
|
11
12
|
const result = [];
|
|
12
13
|
for (const repo of this.config.repositories) {
|
|
14
|
+
if (!(0, config_util_1.filterRepository)(repo, "init"))
|
|
15
|
+
continue;
|
|
13
16
|
if (this.options.repositoryNames &&
|
|
14
17
|
!this.options.repositoryNames.includes(repo.name))
|
|
15
18
|
continue;
|
package/Action/PruneAction.js
CHANGED
|
@@ -24,7 +24,7 @@ class PruneAction {
|
|
|
24
24
|
}
|
|
25
25
|
async exec() {
|
|
26
26
|
const snapshotsAction = new SnapshotsAction_1.SnapshotsAction(this.config, this.options);
|
|
27
|
-
const snapshots = await snapshotsAction.exec();
|
|
27
|
+
const snapshots = await snapshotsAction.exec("prune");
|
|
28
28
|
const snapshotsDeleted = [];
|
|
29
29
|
const reasons = {};
|
|
30
30
|
const inputFilter = {
|
package/Action/RestoreAction.js
CHANGED
|
@@ -203,7 +203,10 @@ class RestoreAction {
|
|
|
203
203
|
const snapshots = this.groupSnapshots(await this.findSnapshots());
|
|
204
204
|
if (!snapshots.length)
|
|
205
205
|
throw new AppError_1.AppError("None snapshot found");
|
|
206
|
-
let packages = (0, config_util_1.filterPackages)(this.config,
|
|
206
|
+
let packages = (0, config_util_1.filterPackages)(this.config, {
|
|
207
|
+
...this.options,
|
|
208
|
+
sourceAction: "restore",
|
|
209
|
+
});
|
|
207
210
|
packages = (0, config_util_1.resolvePackages)(packages, {
|
|
208
211
|
snapshotId: this.options.snapshotId,
|
|
209
212
|
snapshotDate: snapshots[0].date,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ConfigType } from "../Config/Config";
|
|
2
|
+
import { RepositoryConfigEnabledActionType } from "../Config/RepositoryConfig";
|
|
2
3
|
import { SnapshotResultType } from "../Repository/RepositoryAbstract";
|
|
3
4
|
import { IfRequireKeys } from "../util/ts-util";
|
|
4
5
|
export declare type SnapshotGroupByType = keyof Pick<SnapshotExtendedType, "packageName" | "repositoryName" | "repositoryType">;
|
|
@@ -27,5 +28,5 @@ export declare class SnapshotsAction<TRequired extends boolean = true> {
|
|
|
27
28
|
readonly config: ConfigType;
|
|
28
29
|
readonly options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>;
|
|
29
30
|
constructor(config: ConfigType, options: IfRequireKeys<TRequired, SnapshotsActionOptionsType>);
|
|
30
|
-
exec(): Promise<SnapshotExtendedType[]>;
|
|
31
|
+
exec(sourceAction?: RepositoryConfigEnabledActionType): Promise<SnapshotExtendedType[]>;
|
|
31
32
|
}
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SnapshotsAction = void 0;
|
|
4
4
|
const RepositoryFactory_1 = require("../Factory/RepositoryFactory");
|
|
5
|
+
const config_util_1 = require("../util/datatruck/config-util");
|
|
5
6
|
const snapshot_util_1 = require("../util/datatruck/snapshot-util");
|
|
6
7
|
class SnapshotsAction {
|
|
7
8
|
constructor(config, options) {
|
|
8
9
|
this.config = config;
|
|
9
10
|
this.options = options;
|
|
10
11
|
}
|
|
11
|
-
async exec() {
|
|
12
|
+
async exec(sourceAction) {
|
|
13
|
+
if (!sourceAction)
|
|
14
|
+
sourceAction = "snapshots";
|
|
12
15
|
let result = [];
|
|
13
16
|
for (const repo of this.config.repositories) {
|
|
17
|
+
if (!(0, config_util_1.filterRepository)(repo, sourceAction))
|
|
18
|
+
continue;
|
|
14
19
|
if (this.options.repositoryNames &&
|
|
15
20
|
!this.options.repositoryNames.includes(repo.name))
|
|
16
21
|
continue;
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @datatruck/cli
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`0c6877d`](https://github.com/swordev/datatruck/commit/0c6877d189761e75dd434b0a8d72b71621d024de) Thanks [@juanrgm](https://github.com/juanrgm)! - Show more progress stats
|
|
8
|
+
|
|
9
|
+
* [`751e1f6`](https://github.com/swordev/datatruck/commit/751e1f6d6b33d3fa96eb40d998fdd140ce0e3875) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `fileCopyConcurrency` option
|
|
10
|
+
|
|
11
|
+
- [`05487e6`](https://github.com/swordev/datatruck/commit/05487e6a33f875a3afb7ff0815b16da6f2a41301) Thanks [@juanrgm](https://github.com/juanrgm)! - Parse InnoDB error in `MariadbTask` to avoid infinite wait
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`b62a6f8`](https://github.com/swordev/datatruck/commit/b62a6f8a82409339afd65d4f96476eb57bbfb5a2) Thanks [@juanrgm](https://github.com/juanrgm)! - Resolve target/restore path in local repository
|
|
16
|
+
|
|
17
|
+
## 0.5.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [`5aeb2af`](https://github.com/swordev/datatruck/commit/5aeb2afb96692e00bdba501b58df9cc0e02dceaa) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `enabled` option to repository config
|
|
22
|
+
|
|
23
|
+
* [`75de836`](https://github.com/swordev/datatruck/commit/75de8369356cf02ed3fd5c58b1f9bea66432cda8) Thanks [@juanrgm](https://github.com/juanrgm)! - Allow restic password without file
|
|
24
|
+
|
|
25
|
+
## 0.4.0
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- [`eeb00a6`](https://github.com/swordev/datatruck/commit/eeb00a69d75c91da40711ae79475612b1d5193b6) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `tempDir` config option
|
|
30
|
+
|
|
3
31
|
## 0.3.2
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/Command/BackupCommand.js
CHANGED
|
@@ -44,11 +44,7 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
44
44
|
}
|
|
45
45
|
async onExec() {
|
|
46
46
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
47
|
-
const
|
|
48
|
-
path: this.globalOptions.config,
|
|
49
|
-
verbose: verbose > 0,
|
|
50
|
-
});
|
|
51
|
-
const config = await configAction.exec();
|
|
47
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
52
48
|
const backup = new BackupAction_1.BackupAction(config, {
|
|
53
49
|
packageNames: this.options.package,
|
|
54
50
|
repositoryNames: this.options.repository,
|
|
@@ -37,11 +37,7 @@ class BackupSessionsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
37
37
|
}
|
|
38
38
|
async onExec() {
|
|
39
39
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
40
|
-
const
|
|
41
|
-
path: this.globalOptions.config,
|
|
42
|
-
verbose: verbose > 0,
|
|
43
|
-
});
|
|
44
|
-
const config = await configAction.exec();
|
|
40
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
45
41
|
const action = new BackupSessionsAction_1.BackupSessionsAction(config, {
|
|
46
42
|
packageNames: this.options.package,
|
|
47
43
|
repositoryNames: this.options.repository,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ConfigType } from "../Config/Config";
|
|
1
2
|
import { FormatType } from "../util/DataFormat";
|
|
2
3
|
import { OptionsType } from "../util/cli-util";
|
|
3
4
|
import { SimilarObject } from "../util/ts-util";
|
|
4
5
|
export declare type GlobalOptionsType<TResolved = false> = {
|
|
5
|
-
config: string;
|
|
6
|
+
config: string | ConfigType;
|
|
6
7
|
outputFormat?: FormatType;
|
|
7
8
|
verbose?: number;
|
|
8
9
|
};
|
package/Command/ConfigCommand.js
CHANGED
|
@@ -27,11 +27,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
async onExec() {
|
|
30
|
-
const
|
|
31
|
-
path: this.globalOptions.config,
|
|
32
|
-
verbose: !!this.globalOptions.verbose,
|
|
33
|
-
});
|
|
34
|
-
const config = await configAction.exec();
|
|
30
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
35
31
|
const packages = (0, config_util_1.filterPackages)(config, {
|
|
36
32
|
packageNames: this.options.package,
|
|
37
33
|
repositoryNames: this.options.repository,
|
package/Command/InitCommand.js
CHANGED
|
@@ -25,11 +25,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
25
25
|
}
|
|
26
26
|
async onExec() {
|
|
27
27
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
28
|
-
const
|
|
29
|
-
path: this.globalOptions.config,
|
|
30
|
-
verbose: verbose > 0,
|
|
31
|
-
});
|
|
32
|
-
const config = await configAction.exec();
|
|
28
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
33
29
|
const init = new InitAction_1.InitAction(config, {
|
|
34
30
|
repositoryNames: this.options.repository,
|
|
35
31
|
repositoryTypes: this.options.repositoryType,
|
package/Command/PruneCommand.js
CHANGED
|
@@ -101,11 +101,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
101
101
|
}
|
|
102
102
|
async onExec() {
|
|
103
103
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
104
|
-
const
|
|
105
|
-
path: this.globalOptions.config,
|
|
106
|
-
verbose: verbose > 0,
|
|
107
|
-
});
|
|
108
|
-
const config = await configAction.exec();
|
|
104
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
109
105
|
const prune = new PruneAction_1.PruneAction(config, {
|
|
110
106
|
ids: this.options.id,
|
|
111
107
|
packageNames: this.options.package,
|
|
@@ -40,11 +40,7 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
40
40
|
}
|
|
41
41
|
async onExec() {
|
|
42
42
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
43
|
-
const
|
|
44
|
-
path: this.globalOptions.config,
|
|
45
|
-
verbose: verbose > 0,
|
|
46
|
-
});
|
|
47
|
-
const config = await configAction.exec();
|
|
43
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
48
44
|
const restore = new RestoreAction_1.RestoreAction(config, {
|
|
49
45
|
snapshotId: this.options.id,
|
|
50
46
|
packageNames: this.options.package,
|
|
@@ -37,11 +37,7 @@ class RestoreSessionsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
37
37
|
}
|
|
38
38
|
async onExec() {
|
|
39
39
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
40
|
-
const
|
|
41
|
-
path: this.globalOptions.config,
|
|
42
|
-
verbose: verbose > 0,
|
|
43
|
-
});
|
|
44
|
-
const config = await configAction.exec();
|
|
40
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
45
41
|
const action = new RestoreSessionsAction_1.RestoreSessionsAction(config, {
|
|
46
42
|
packageNames: this.options.package,
|
|
47
43
|
repositoryNames: this.options.repository,
|
|
@@ -83,11 +83,7 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
|
|
|
83
83
|
}
|
|
84
84
|
async onExec() {
|
|
85
85
|
const verbose = this.globalOptions.verbose ?? 0;
|
|
86
|
-
const
|
|
87
|
-
path: this.globalOptions.config,
|
|
88
|
-
verbose: verbose > 0,
|
|
89
|
-
});
|
|
90
|
-
const config = await configAction.exec();
|
|
86
|
+
const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
|
|
91
87
|
const snapshots = new SnapshotsAction_1.SnapshotsAction(config, {
|
|
92
88
|
ids: this.options.id,
|
|
93
89
|
packageNames: this.options.package,
|
package/Config/Config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PackageConfigType } from "./PackageConfig";
|
|
|
2
2
|
import { RepositoryConfigType } from "./RepositoryConfig";
|
|
3
3
|
import type { JSONSchema7 } from "json-schema";
|
|
4
4
|
export declare type ConfigType = {
|
|
5
|
+
tempDir?: string;
|
|
5
6
|
repositories: RepositoryConfigType[];
|
|
6
7
|
packages: PackageConfigType[];
|
|
7
8
|
};
|
package/Config/Config.js
CHANGED
|
@@ -4,8 +4,12 @@ import { ResticRepositoryConfigType, resticRepositoryName } from "../Repository/
|
|
|
4
4
|
import type { JSONSchema7 } from "json-schema";
|
|
5
5
|
export declare const repositoryConfigDefinition: JSONSchema7;
|
|
6
6
|
export declare type RepositoryConfigTypeType = RepositoryConfigType["type"];
|
|
7
|
+
export declare type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
|
|
7
8
|
export declare type RepositoryConfigType = {
|
|
8
9
|
name: string;
|
|
10
|
+
enabled?: boolean | {
|
|
11
|
+
[K in "defaults" | RepositoryConfigEnabledActionType]?: boolean;
|
|
12
|
+
};
|
|
9
13
|
} & ({
|
|
10
14
|
type: typeof resticRepositoryName;
|
|
11
15
|
config: ResticRepositoryConfigType;
|
|
@@ -17,6 +17,25 @@ exports.repositoryConfigDefinition = {
|
|
|
17
17
|
properties: {
|
|
18
18
|
type: { type: "string" },
|
|
19
19
|
name: { type: "string" },
|
|
20
|
+
enabled: {
|
|
21
|
+
anyOf: [
|
|
22
|
+
{
|
|
23
|
+
type: "boolean",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: "object",
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
properties: {
|
|
29
|
+
defaults: { type: "boolean" },
|
|
30
|
+
backup: { type: "boolean" },
|
|
31
|
+
init: { type: "boolean" },
|
|
32
|
+
prune: { type: "boolean" },
|
|
33
|
+
restore: { type: "boolean" },
|
|
34
|
+
snapshots: { type: "boolean" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
20
39
|
config: {},
|
|
21
40
|
},
|
|
22
41
|
anyOf: Object.keys(types).map((type) => ({
|
|
@@ -13,7 +13,6 @@ const string_util_1 = require("../util/string-util");
|
|
|
13
13
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
14
14
|
const assert_1 = require("assert");
|
|
15
15
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
16
|
-
const fs_extra_1 = require("fs-extra");
|
|
17
16
|
const promises_1 = require("fs/promises");
|
|
18
17
|
const micromatch_1 = require("micromatch");
|
|
19
18
|
const path_1 = require("path");
|
|
@@ -62,7 +61,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
62
61
|
log: data.options.verbose,
|
|
63
62
|
});
|
|
64
63
|
if (await git.canBeInit(this.config.repo)) {
|
|
65
|
-
await (0,
|
|
64
|
+
await (0, promises_1.mkdir)(git.options.dir);
|
|
66
65
|
await git.exec(["init", "--bare", this.config.repo]);
|
|
67
66
|
}
|
|
68
67
|
const branchName = this.config.branch ?? "master";
|
|
@@ -182,7 +181,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
182
181
|
const target = (0, path_1.join)(tmpPath, entry);
|
|
183
182
|
const dir = (0, path_1.dirname)(target);
|
|
184
183
|
if (!createdPaths.includes(dir)) {
|
|
185
|
-
await (0,
|
|
184
|
+
await (0, promises_1.mkdir)(dir, {
|
|
186
185
|
recursive: true,
|
|
187
186
|
});
|
|
188
187
|
createdPaths.push(dir);
|
|
@@ -16,11 +16,9 @@ const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
|
16
16
|
const assert_1 = require("assert");
|
|
17
17
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
18
18
|
const fs_1 = require("fs");
|
|
19
|
-
const fs_extra_1 = require("fs-extra");
|
|
20
19
|
const promises_1 = require("fs/promises");
|
|
21
20
|
const micromatch_1 = require("micromatch");
|
|
22
21
|
const path_1 = require("path");
|
|
23
|
-
const path_2 = require("path");
|
|
24
22
|
const readline_1 = require("readline");
|
|
25
23
|
exports.localRepositoryName = "local";
|
|
26
24
|
exports.localRepositoryDefinition = {
|
|
@@ -62,6 +60,10 @@ exports.localPackageRepositoryDefinition = {
|
|
|
62
60
|
},
|
|
63
61
|
],
|
|
64
62
|
},
|
|
63
|
+
fileCopyConcurrency: {
|
|
64
|
+
type: "integer",
|
|
65
|
+
minimum: 1,
|
|
66
|
+
},
|
|
65
67
|
},
|
|
66
68
|
};
|
|
67
69
|
class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
@@ -111,11 +113,11 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
111
113
|
if (data.options.verbose)
|
|
112
114
|
(0, cli_util_1.logExec)(`Deleting ${snapshotPath}`);
|
|
113
115
|
if (await (0, fs_util_1.checkDir)(snapshotPath))
|
|
114
|
-
await (0,
|
|
116
|
+
await (0, promises_1.rm)(snapshotPath, {
|
|
115
117
|
recursive: true,
|
|
116
118
|
});
|
|
117
119
|
if (await (0, fs_util_1.checkFile)(metaPath))
|
|
118
|
-
await (0,
|
|
120
|
+
await (0, promises_1.rm)(metaPath);
|
|
119
121
|
}
|
|
120
122
|
async onSnapshots(data) {
|
|
121
123
|
if (!(await (0, fs_util_1.checkDir)(this.config.outPath)))
|
|
@@ -173,8 +175,7 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
173
175
|
snapshotDate: data.snapshot.date,
|
|
174
176
|
packageName: data.package.name,
|
|
175
177
|
});
|
|
176
|
-
const outPath = (0, path_1.join)(this.config.outPath, snapshotName);
|
|
177
|
-
const createdPaths = [];
|
|
178
|
+
const outPath = (0, path_1.resolve)((0, path_1.join)(this.config.outPath, snapshotName));
|
|
178
179
|
const pkg = data.package;
|
|
179
180
|
await (0, promises_1.mkdir)(outPath, {
|
|
180
181
|
recursive: true,
|
|
@@ -260,35 +261,26 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
260
261
|
}
|
|
261
262
|
if (data.options.verbose)
|
|
262
263
|
(0, cli_util_1.logExec)(`Copying files to ${outPath}`);
|
|
263
|
-
|
|
264
|
-
input:
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
else {
|
|
264
|
+
await (0, fs_util_1.cpy)({
|
|
265
|
+
input: {
|
|
266
|
+
type: "pathList",
|
|
267
|
+
path: pathLists.path,
|
|
268
|
+
basePath: sourcePath,
|
|
269
|
+
},
|
|
270
|
+
targetPath: outPath,
|
|
271
|
+
concurrency: this.config.fileCopyConcurrency,
|
|
272
|
+
async onPath({ isDir, entryPath }) {
|
|
273
|
+
if (isDir)
|
|
274
|
+
return;
|
|
275
275
|
currentFiles++;
|
|
276
276
|
await data.onProgress({
|
|
277
277
|
total: pathLists.total.all,
|
|
278
278
|
current: currentFiles,
|
|
279
279
|
percent: (0, math_util_1.progressPercent)(pathLists.total.all, currentFiles),
|
|
280
|
-
step:
|
|
280
|
+
step: entryPath,
|
|
281
281
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
await (0, promises_1.mkdir)(dir, {
|
|
285
|
-
recursive: true,
|
|
286
|
-
});
|
|
287
|
-
createdPaths.push(dir);
|
|
288
|
-
}
|
|
289
|
-
await (0, promises_1.copyFile)(source, target);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
282
|
+
},
|
|
283
|
+
});
|
|
292
284
|
const metaPath = `${outPath}.json`;
|
|
293
285
|
const nodePkg = (0, fs_util_1.parsePackageFile)();
|
|
294
286
|
const meta = {
|
|
@@ -303,8 +295,9 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
303
295
|
await (0, promises_1.writeFile)(metaPath, LocalRepository.stringifyMetaData(meta));
|
|
304
296
|
}
|
|
305
297
|
async onRestore(data) {
|
|
306
|
-
const
|
|
307
|
-
(0, assert_1.ok)(
|
|
298
|
+
const relRestorePath = data.targetPath ?? data.package.restorePath;
|
|
299
|
+
(0, assert_1.ok)(relRestorePath);
|
|
300
|
+
const restorePath = (0, path_1.resolve)(relRestorePath);
|
|
308
301
|
const [snapshot] = await this.onSnapshots({
|
|
309
302
|
options: {
|
|
310
303
|
ids: [data.options.snapshotId],
|
|
@@ -325,19 +318,27 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
325
318
|
}, true);
|
|
326
319
|
if (data.options.verbose)
|
|
327
320
|
(0, cli_util_1.logExec)(`Copying files to ${restorePath}`);
|
|
328
|
-
await (0,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
321
|
+
await (0, fs_util_1.cpy)({
|
|
322
|
+
input: {
|
|
323
|
+
type: "glob",
|
|
324
|
+
sourcePath,
|
|
325
|
+
},
|
|
326
|
+
targetPath: restorePath,
|
|
327
|
+
concurrency: this.config.fileCopyConcurrency,
|
|
328
|
+
onPath: async ({ entryPath, entrySourcePath }) => {
|
|
329
|
+
const isRootFile = (0, path_1.basename)(entryPath) === entryPath;
|
|
330
|
+
const isZipFile = isRootFile &&
|
|
331
|
+
entryPath.startsWith(".") &&
|
|
332
|
+
entryPath.endsWith(".dd.zip");
|
|
332
333
|
await data.onProgress({
|
|
333
334
|
total: totalFiles,
|
|
334
335
|
current: Math.max(currentFiles, 0),
|
|
335
336
|
percent: (0, math_util_1.progressPercent)(totalFiles, Math.max(currentFiles, 0)),
|
|
336
|
-
step:
|
|
337
|
+
step: entryPath,
|
|
337
338
|
});
|
|
338
339
|
if (isZipFile) {
|
|
339
340
|
await (0, zip_util_1.unzip)({
|
|
340
|
-
input:
|
|
341
|
+
input: entrySourcePath,
|
|
341
342
|
output: restorePath,
|
|
342
343
|
verbose: data.options.verbose,
|
|
343
344
|
onStream: async (stream) => await data.onProgress({
|
|
@@ -14,10 +14,10 @@ export declare type SnapshotResultType = SnapshotType & {
|
|
|
14
14
|
tags: string[];
|
|
15
15
|
};
|
|
16
16
|
export declare type ProgressDataType = {
|
|
17
|
-
total
|
|
18
|
-
current
|
|
19
|
-
percent
|
|
20
|
-
step
|
|
17
|
+
total?: number;
|
|
18
|
+
current?: number;
|
|
19
|
+
percent?: number;
|
|
20
|
+
step?: string;
|
|
21
21
|
stepPercent?: number | null;
|
|
22
22
|
};
|
|
23
23
|
export declare type InitDataType = {
|
|
@@ -2,7 +2,9 @@ import { RepositoryType } from "../util/ResticUtil";
|
|
|
2
2
|
import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType } from "./RepositoryAbstract";
|
|
3
3
|
import { JSONSchema7 } from "json-schema";
|
|
4
4
|
export declare type ResticRepositoryConfigType = {
|
|
5
|
-
|
|
5
|
+
password: string | {
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
6
8
|
repository: RepositoryType;
|
|
7
9
|
};
|
|
8
10
|
export declare type ResticPackageRepositoryConfigType = {};
|
|
@@ -12,11 +14,13 @@ export declare const resticPackageRepositoryDefinition: JSONSchema7;
|
|
|
12
14
|
export declare class ResticRepository extends RepositoryAbstract<ResticRepositoryConfigType> {
|
|
13
15
|
static refPrefix: string;
|
|
14
16
|
protected env: {
|
|
15
|
-
|
|
17
|
+
RESTIC_PASSWORD?: string;
|
|
18
|
+
RESTIC_PASSWORD_FILE?: string;
|
|
16
19
|
RESTIC_REPOSITORY: string;
|
|
17
20
|
};
|
|
18
21
|
buildEnv(): Promise<{
|
|
19
|
-
|
|
22
|
+
RESTIC_PASSWORD?: string | undefined;
|
|
23
|
+
RESTIC_PASSWORD_FILE?: string | undefined;
|
|
20
24
|
RESTIC_REPOSITORY: string;
|
|
21
25
|
}>;
|
|
22
26
|
static buildSnapshotTag(name: SnapshotTagEnum, value: string): string;
|