@datatruck/cli 0.27.0 → 0.28.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.
Files changed (147) hide show
  1. package/Action/BackupAction.d.ts +69 -34
  2. package/Action/BackupAction.js +284 -244
  3. package/Action/CleanCacheAction.d.ts +8 -4
  4. package/Action/CleanCacheAction.js +8 -5
  5. package/Action/ConfigAction.d.ts +12 -5
  6. package/Action/ConfigAction.js +14 -18
  7. package/Action/CopyAction.d.ts +49 -0
  8. package/Action/CopyAction.js +144 -0
  9. package/Action/InitAction.d.ts +3 -3
  10. package/Action/InitAction.js +9 -9
  11. package/Action/PruneAction.d.ts +9 -9
  12. package/Action/PruneAction.js +39 -23
  13. package/Action/RestoreAction.d.ts +48 -23
  14. package/Action/RestoreAction.js +158 -195
  15. package/Action/SnapshotsAction.d.ts +8 -8
  16. package/Action/SnapshotsAction.js +8 -8
  17. package/CHANGELOG.md +495 -0
  18. package/Command/BackupCommand.d.ts +6 -4
  19. package/Command/BackupCommand.js +9 -26
  20. package/Command/CleanCacheCommand.d.ts +4 -4
  21. package/Command/CleanCacheCommand.js +26 -5
  22. package/Command/CommandAbstract.d.ts +10 -7
  23. package/Command/CommandAbstract.js +4 -1
  24. package/Command/ConfigCommand.d.ts +6 -9
  25. package/Command/ConfigCommand.js +13 -8
  26. package/Command/CopyCommand.d.ts +15 -0
  27. package/Command/CopyCommand.js +61 -0
  28. package/Command/InitCommand.d.ts +4 -4
  29. package/Command/InitCommand.js +11 -15
  30. package/Command/PruneCommand.d.ts +3 -3
  31. package/Command/PruneCommand.js +13 -12
  32. package/Command/RestoreCommand.js +9 -17
  33. package/Command/SnapshotsCommand.d.ts +4 -4
  34. package/Command/SnapshotsCommand.js +16 -15
  35. package/Command/StartServerCommand.d.ts +3 -3
  36. package/Config/Config.d.ts +9 -0
  37. package/Config/Config.js +17 -0
  38. package/Config/PrunePolicyConfig.d.ts +2 -2
  39. package/Factory/CommandFactory.d.ts +27 -34
  40. package/Factory/CommandFactory.js +27 -54
  41. package/Factory/RepositoryFactory.d.ts +1 -1
  42. package/Factory/RepositoryFactory.js +3 -3
  43. package/Factory/TaskFactory.d.ts +1 -1
  44. package/Factory/TaskFactory.js +3 -3
  45. package/Repository/DatatruckRepository.d.ts +9 -8
  46. package/Repository/DatatruckRepository.js +42 -25
  47. package/Repository/GitRepository.d.ts +9 -8
  48. package/Repository/GitRepository.js +22 -25
  49. package/Repository/RepositoryAbstract.d.ts +39 -37
  50. package/Repository/RepositoryAbstract.js +4 -5
  51. package/Repository/ResticRepository.d.ts +9 -8
  52. package/Repository/ResticRepository.js +30 -28
  53. package/Task/GitTask.d.ts +6 -7
  54. package/Task/GitTask.js +24 -30
  55. package/Task/MariadbTask.d.ts +4 -5
  56. package/Task/MariadbTask.js +26 -32
  57. package/Task/MssqlTask.d.ts +5 -3
  58. package/Task/MssqlTask.js +11 -12
  59. package/Task/MysqlDumpTask.d.ts +10 -3
  60. package/Task/MysqlDumpTask.js +107 -31
  61. package/Task/ScriptTask.d.ts +23 -18
  62. package/Task/ScriptTask.js +34 -24
  63. package/Task/SqlDumpTaskAbstract.d.ts +8 -3
  64. package/Task/SqlDumpTaskAbstract.js +31 -19
  65. package/Task/TaskAbstract.d.ts +24 -25
  66. package/Task/TaskAbstract.js +6 -10
  67. package/cli.js +13 -5
  68. package/config.schema.json +86 -1
  69. package/package.json +4 -5
  70. package/utils/DataFormat.d.ts +23 -12
  71. package/utils/DataFormat.js +36 -14
  72. package/utils/cli.d.ts +2 -9
  73. package/utils/cli.js +9 -52
  74. package/utils/datatruck/client.d.ts +2 -0
  75. package/utils/datatruck/client.js +3 -0
  76. package/utils/datatruck/config.d.ts +2 -0
  77. package/utils/datatruck/config.js +18 -3
  78. package/utils/datatruck/paths.d.ts +5 -9
  79. package/utils/datatruck/paths.js +2 -2
  80. package/utils/datatruck/snapshot.d.ts +2 -2
  81. package/utils/date.d.ts +7 -3
  82. package/utils/date.js +22 -14
  83. package/utils/fs.d.ts +16 -11
  84. package/utils/fs.js +81 -48
  85. package/utils/list.d.ts +64 -0
  86. package/utils/list.js +145 -0
  87. package/utils/mysql.d.ts +2 -0
  88. package/utils/mysql.js +21 -2
  89. package/utils/process.d.ts +1 -0
  90. package/utils/process.js +24 -31
  91. package/utils/progress.d.ts +33 -0
  92. package/utils/progress.js +113 -0
  93. package/utils/steps.d.ts +11 -0
  94. package/utils/steps.js +22 -10
  95. package/utils/stream.d.ts +7 -0
  96. package/utils/stream.js +10 -0
  97. package/utils/string.d.ts +0 -1
  98. package/utils/string.js +1 -13
  99. package/utils/tar.d.ts +10 -3
  100. package/utils/tar.js +70 -44
  101. package/utils/temp.d.ts +26 -0
  102. package/utils/temp.js +133 -0
  103. package/utils/virtual-fs.d.ts +6 -2
  104. package/utils/virtual-fs.js +6 -0
  105. package/Action/BackupSessionsAction.d.ts +0 -13
  106. package/Action/BackupSessionsAction.js +0 -18
  107. package/Action/RestoreSessionsAction.d.ts +0 -13
  108. package/Action/RestoreSessionsAction.js +0 -18
  109. package/Command/BackupSessionsCommand.d.ts +0 -12
  110. package/Command/BackupSessionsCommand.js +0 -92
  111. package/Command/RestoreSessionsCommand.d.ts +0 -12
  112. package/Command/RestoreSessionsCommand.js +0 -91
  113. package/Decorator/EntityDecorator.d.ts +0 -11
  114. package/Decorator/EntityDecorator.js +0 -17
  115. package/Entity/BackupSessionEntity.d.ts +0 -6
  116. package/Entity/BackupSessionEntity.js +0 -25
  117. package/Entity/BackupSessionRepositoryEntity.d.ts +0 -6
  118. package/Entity/BackupSessionRepositoryEntity.js +0 -25
  119. package/Entity/BackupSessionTaskEntity.d.ts +0 -5
  120. package/Entity/BackupSessionTaskEntity.js +0 -24
  121. package/Entity/CrudEntityAbstract.d.ts +0 -5
  122. package/Entity/CrudEntityAbstract.js +0 -9
  123. package/Entity/RestoreSessionEntity.d.ts +0 -5
  124. package/Entity/RestoreSessionEntity.js +0 -24
  125. package/Entity/RestoreSessionRepositoryEntity.d.ts +0 -6
  126. package/Entity/RestoreSessionRepositoryEntity.js +0 -25
  127. package/Entity/RestoreSessionTaskEntity.d.ts +0 -5
  128. package/Entity/RestoreSessionTaskEntity.js +0 -24
  129. package/Entity/StateEntityAbstract.d.ts +0 -9
  130. package/Entity/StateEntityAbstract.js +0 -12
  131. package/Factory/EntityFactory.d.ts +0 -6
  132. package/Factory/EntityFactory.js +0 -40
  133. package/SessionDriver/ConsoleSessionDriver.d.ts +0 -42
  134. package/SessionDriver/ConsoleSessionDriver.js +0 -208
  135. package/SessionDriver/SessionDriverAbstract.d.ts +0 -77
  136. package/SessionDriver/SessionDriverAbstract.js +0 -28
  137. package/SessionDriver/SqliteSessionDriver.d.ts +0 -20
  138. package/SessionDriver/SqliteSessionDriver.js +0 -173
  139. package/SessionManager/BackupSessionManager.d.ts +0 -45
  140. package/SessionManager/BackupSessionManager.js +0 -218
  141. package/SessionManager/RestoreSessionManager.d.ts +0 -47
  142. package/SessionManager/RestoreSessionManager.js +0 -218
  143. package/SessionManager/SessionManagerAbstract.d.ts +0 -18
  144. package/SessionManager/SessionManagerAbstract.js +0 -36
  145. package/migrations/001-initial.sql +0 -98
  146. package/utils/entity.d.ts +0 -4
  147. package/utils/entity.js +0 -10
@@ -1,52 +1,54 @@
1
- import type { BackupActionOptionsType } from "../Action/BackupAction";
2
- import type { InitActionOptionsType } from "../Action/InitAction";
3
- import type { RestoreActionOptionsType } from "../Action/RestoreAction";
4
- import type { SnapshotExtendedType, SnapshotsActionOptionsType } from "../Action/SnapshotsAction";
1
+ import type { BackupActionOptions } from "../Action/BackupAction";
2
+ import type { InitActionOptions } from "../Action/InitAction";
3
+ import type { RestoreActionOptions } from "../Action/RestoreAction";
4
+ import type { ExtendedSnapshot, SnapshotsActionOptions } from "../Action/SnapshotsAction";
5
5
  import type { PackageConfigType } from "../Config/PackageConfig";
6
6
  import type { RepositoryConfigType } from "../Config/RepositoryConfig";
7
- import { Progress } from "../utils/progress";
8
- export type SnapshotType = {
7
+ import { type DiskStats } from "../utils/fs";
8
+ import type { Progress } from "../utils/progress";
9
+ export type PreSnapshot = {
9
10
  id: string;
10
11
  date: string;
11
12
  };
12
- export type SnapshotResultType = SnapshotType & {
13
+ export type Snapshot = PreSnapshot & {
13
14
  originalId: string;
14
15
  packageName: string;
15
16
  packageTaskName: string | undefined;
16
17
  tags: string[];
17
18
  size: number;
18
19
  };
19
- export type InitDataType = {
20
- options: InitActionOptionsType;
20
+ export type RepoInitData = {
21
+ options: InitActionOptions;
21
22
  };
22
- export type SnapshotsDataType = {
23
- options: Pick<SnapshotsActionOptionsType, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
23
+ export type RepoFetchSnapshotsData = {
24
+ options: Pick<SnapshotsActionOptions, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
24
25
  };
25
- export type CopyBackupType<TRepositoryConfig> = {
26
- options: BackupActionOptionsType;
27
- snapshot: SnapshotType;
26
+ export type RepoCopyData<TRepositoryConfig> = {
27
+ options: BackupActionOptions;
28
+ snapshot: PreSnapshot;
28
29
  package: PackageConfigType;
29
30
  mirrorRepositoryConfig: TRepositoryConfig;
30
- onProgress: (data: Progress) => Promise<void>;
31
+ onProgress: (data: Progress) => void;
31
32
  };
32
- export type BackupDataType<TPackageConfig> = {
33
- options: BackupActionOptionsType;
34
- snapshot: SnapshotType;
35
- package: PackageConfigType;
36
- targetPath: string | undefined;
33
+ export type RepoBackupData<TPackageConfig> = {
34
+ options: BackupActionOptions;
35
+ snapshot: PreSnapshot;
36
+ package: Omit<PackageConfigType, "path"> & {
37
+ path: string;
38
+ };
37
39
  packageConfig: TPackageConfig | undefined;
38
- onProgress: (data: Progress) => Promise<void>;
40
+ onProgress: (data: Progress) => void;
39
41
  };
40
- export type RestoreDataType<TPackageConfig> = {
41
- options: RestoreActionOptionsType;
42
- snapshot: SnapshotType;
42
+ export type RepoRestoreData<TPackageConfig> = {
43
+ options: RestoreActionOptions;
44
+ snapshot: PreSnapshot;
43
45
  package: PackageConfigType;
44
- targetPath: string | undefined;
46
+ snapshotPath: string;
45
47
  packageConfig: TPackageConfig;
46
- onProgress: (data: Progress) => Promise<void>;
48
+ onProgress: (data: Progress) => void;
47
49
  };
48
- export type PruneDataType = {
49
- snapshot: SnapshotExtendedType;
50
+ export type RepoPruneData = {
51
+ snapshot: ExtendedSnapshot;
50
52
  options: {
51
53
  verbose?: boolean;
52
54
  };
@@ -74,14 +76,14 @@ export type SnapshotTagObjectType = {
74
76
  export declare abstract class RepositoryAbstract<TConfig> {
75
77
  readonly repository: RepositoryConfigType;
76
78
  readonly config: TConfig;
77
- readonly tmpDirs: string[];
78
79
  constructor(repository: RepositoryConfigType);
79
- mkTmpDir(prefix: string, id?: string): Promise<string>;
80
- abstract onGetSource(): string;
81
- abstract onInit(data: InitDataType): Promise<void>;
82
- abstract onPrune(data: PruneDataType): Promise<void>;
83
- abstract onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
84
- abstract onCopyBackup(data: CopyBackupType<TConfig>): Promise<void>;
85
- abstract onBackup(data: BackupDataType<unknown>): Promise<void>;
86
- abstract onRestore(data: RestoreDataType<unknown>): Promise<void>;
80
+ abstract getSource(): string;
81
+ abstract fetchDiskStats(config: TConfig): Promise<DiskStats | undefined>;
82
+ ensureFreeDiskSpace(config: TConfig, minFreeDiskSpace: number | string): Promise<void>;
83
+ abstract init(data: RepoInitData): Promise<void>;
84
+ abstract prune(data: RepoPruneData): Promise<void>;
85
+ abstract fetchSnapshots(data: RepoFetchSnapshotsData): Promise<Snapshot[]>;
86
+ abstract copy(data: RepoCopyData<TConfig>): Promise<void>;
87
+ abstract backup(data: RepoBackupData<unknown>): Promise<void>;
88
+ abstract restore(data: RepoRestoreData<unknown>): Promise<void>;
87
89
  }
@@ -16,15 +16,14 @@ var SnapshotTagEnum;
16
16
  class RepositoryAbstract {
17
17
  repository;
18
18
  config;
19
- tmpDirs = [];
20
19
  constructor(repository) {
21
20
  this.repository = repository;
22
21
  this.config = repository.config;
23
22
  }
24
- async mkTmpDir(prefix, id) {
25
- const dir = await (0, fs_1.mkTmpDir)(prefix, id);
26
- this.tmpDirs.push(dir);
27
- return dir;
23
+ async ensureFreeDiskSpace(config, minFreeDiskSpace) {
24
+ const diskStats = await this.fetchDiskStats(config);
25
+ if (diskStats)
26
+ await (0, fs_1.ensureFreeDiskSpace)(diskStats, minFreeDiskSpace);
28
27
  }
29
28
  }
30
29
  exports.RepositoryAbstract = RepositoryAbstract;
@@ -1,5 +1,5 @@
1
1
  import { RepositoryType } from "../utils/Restic";
2
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
+ import { RepositoryAbstract, RepoBackupData, RepoInitData, RepoRestoreData, RepoFetchSnapshotsData, Snapshot, SnapshotTagObjectType, SnapshotTagEnum, RepoPruneData, RepoCopyData } from "./RepositoryAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  export type ResticRepositoryConfigType = {
5
5
  password: string | {
@@ -31,11 +31,12 @@ export declare class ResticRepository extends RepositoryAbstract<ResticRepositor
31
31
  static parseSnapshotTags(tags: string[]): SnapshotTagObjectType & {
32
32
  tags: string[];
33
33
  };
34
- onGetSource(): string;
35
- onInit(data: InitDataType): Promise<void>;
36
- onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
37
- onPrune(data: PruneDataType): Promise<void>;
38
- onBackup(data: BackupDataType<ResticPackageRepositoryConfigType>): Promise<void>;
39
- onCopyBackup(data: CopyBackupType<ResticRepositoryConfigType>): Promise<void>;
40
- onRestore(data: RestoreDataType<ResticPackageRepositoryConfigType>): Promise<void>;
34
+ getSource(): string;
35
+ fetchDiskStats(config: ResticRepositoryConfigType): Promise<import("../utils/fs").DiskStats | undefined>;
36
+ init(data: RepoInitData): Promise<void>;
37
+ fetchSnapshots(data: RepoFetchSnapshotsData): Promise<Snapshot[]>;
38
+ prune(data: RepoPruneData): Promise<void>;
39
+ backup(data: RepoBackupData<ResticPackageRepositoryConfigType>): Promise<void>;
40
+ copy(data: RepoCopyData<ResticRepositoryConfigType>): Promise<void>;
41
+ restore(data: RepoRestoreData<ResticPackageRepositoryConfigType>): Promise<void>;
41
42
  }
@@ -11,8 +11,8 @@ const paths_1 = require("../utils/datatruck/paths");
11
11
  const fs_1 = require("../utils/fs");
12
12
  const math_1 = require("../utils/math");
13
13
  const string_1 = require("../utils/string");
14
+ const temp_1 = require("../utils/temp");
14
15
  const RepositoryAbstract_1 = require("./RepositoryAbstract");
15
- const assert_1 = require("assert");
16
16
  const fast_glob_1 = __importDefault(require("fast-glob"));
17
17
  const promises_1 = require("fs/promises");
18
18
  const micromatch_1 = require("micromatch");
@@ -123,10 +123,14 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
123
123
  }
124
124
  return result;
125
125
  }
126
- onGetSource() {
126
+ getSource() {
127
127
  return (0, string_1.formatUri)({ ...this.config.repository, password: undefined });
128
128
  }
129
- async onInit(data) {
129
+ async fetchDiskStats(config) {
130
+ if (config.repository.backend === "local" && config.repository.path)
131
+ return (0, fs_1.fetchDiskStats)(config.repository.path);
132
+ }
133
+ async init(data) {
130
134
  const restic = new Restic_1.Restic({
131
135
  env: await this.buildEnv(),
132
136
  log: data.options.verbose,
@@ -136,7 +140,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
136
140
  if (!(await restic.checkRepository()))
137
141
  await restic.exec(["init"]);
138
142
  }
139
- async onSnapshots(data) {
143
+ async fetchSnapshots(data) {
140
144
  const restic = new Restic_1.Restic({
141
145
  env: await this.buildEnv(),
142
146
  log: data.options.verbose,
@@ -172,7 +176,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
172
176
  return items;
173
177
  }, []);
174
178
  }
175
- async onPrune(data) {
179
+ async prune(data) {
176
180
  const restic = new Restic_1.Restic({
177
181
  env: await this.buildEnv(),
178
182
  log: data.options.verbose,
@@ -182,30 +186,29 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
182
186
  prune: true,
183
187
  });
184
188
  }
185
- async onBackup(data) {
189
+ async backup(data) {
186
190
  const restic = new Restic_1.Restic({
187
191
  env: await this.buildEnv(),
188
192
  log: data.options.verbose,
189
193
  });
190
194
  const pkg = data.package;
191
- const sourcePath = data.targetPath ?? data.package.path;
192
- (0, assert_1.ok)(sourcePath);
195
+ const path = data.package.path;
193
196
  let gitignorePath;
194
197
  const backupPathsOptions = {
195
198
  package: data.package,
196
199
  snapshot: data.snapshot,
197
- targetPath: sourcePath,
200
+ path,
198
201
  verbose: data.options.verbose,
199
202
  };
200
203
  if (!pkg.include && pkg.exclude) {
201
204
  const exclude = await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions);
202
- await data.onProgress({
205
+ data.onProgress({
203
206
  relative: {
204
207
  description: "Writing excluded paths list",
205
208
  },
206
209
  });
207
- const tmpDir = await this.mkTmpDir("restic-exclude");
208
- const ignoredContents = (0, fs_1.fastglobToGitIgnore)(exclude, sourcePath).join("\n");
210
+ const tmpDir = await (0, temp_1.mkTmpDir)(exports.resticRepositoryName, "repo", "backup", "exclude");
211
+ const ignoredContents = (0, fs_1.fastglobToGitIgnore)(exclude, path).join("\n");
209
212
  gitignorePath = (0, path_1.join)(tmpDir, "ignored.txt");
210
213
  await (0, promises_1.writeFile)(gitignorePath, ignoredContents);
211
214
  }
@@ -215,7 +218,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
215
218
  ? await (0, paths_1.parseBackupPaths)(pkg.exclude, backupPathsOptions)
216
219
  : undefined;
217
220
  const stream = fast_glob_1.default.stream(include, {
218
- cwd: sourcePath,
221
+ cwd: path,
219
222
  ignore: exclude,
220
223
  dot: true,
221
224
  onlyFiles: true,
@@ -223,20 +226,20 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
223
226
  });
224
227
  if (data.options.verbose)
225
228
  (0, cli_1.logExec)(`Writing paths lists`);
226
- await data.onProgress({
229
+ data.onProgress({
227
230
  relative: {
228
231
  description: "Writing excluded paths list",
229
232
  },
230
233
  });
231
234
  gitignorePath = await (0, fs_1.writeGitIgnoreList)({
232
235
  paths: stream,
233
- outDir: await this.mkTmpDir("gitignore-list"),
236
+ outDir: await (0, temp_1.mkTmpDir)(exports.resticRepositoryName, "repo", "backup", "gitignore"),
234
237
  });
235
238
  }
236
239
  if (data.options.tags?.some((tag) => tag.startsWith(ResticRepository.refPrefix)))
237
240
  throw new AppError_1.AppError(`Tag prefix is not allowed`);
238
241
  const packageTag = ResticRepository.buildSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.PACKAGE, data.package.name);
239
- await data.onProgress({
242
+ data.onProgress({
240
243
  relative: {
241
244
  description: "Fetching last snapshot",
242
245
  },
@@ -250,7 +253,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
250
253
  let lastProgress;
251
254
  let totalFilesChanges = 0;
252
255
  const totalFilesChangesLimit = 10;
253
- await data.onProgress({
256
+ data.onProgress({
254
257
  relative: {
255
258
  description: "Executing backup action",
256
259
  },
@@ -258,7 +261,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
258
261
  let resticSnapshotId;
259
262
  let resticTotalBytes;
260
263
  await restic.backup({
261
- cwd: sourcePath,
264
+ cwd: path,
262
265
  paths: ["."],
263
266
  allowEmptySnapshot: true,
264
267
  excludeFile: gitignorePath ? [gitignorePath] : undefined,
@@ -280,7 +283,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
280
283
  : []),
281
284
  ...(data.options.tags ?? []),
282
285
  ],
283
- createEmptyDir: async () => await this.mkTmpDir("empty"),
286
+ createEmptyDir: async () => await (0, temp_1.mkTmpDir)(exports.resticRepositoryName, "repo", "backup", "empty-dir"),
284
287
  onStream: async (streamData) => {
285
288
  if (streamData.message_type === "status") {
286
289
  let showProgressBar = false;
@@ -293,7 +296,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
293
296
  else {
294
297
  totalFilesChanges++;
295
298
  }
296
- await data.onProgress((lastProgress = {
299
+ data.onProgress((lastProgress = {
297
300
  relative: {
298
301
  description: "Copying file",
299
302
  payload: streamData.current_files?.join(", ") ?? "-",
@@ -319,7 +322,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
319
322
  throw new AppError_1.AppError(`Restic snapshot total bytes is not defined`);
320
323
  const sizeTag = ResticRepository.buildSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.SIZE, resticTotalBytes.toString());
321
324
  await restic.exec(["tag", "--add", sizeTag, resticSnapshotId]);
322
- await data.onProgress({
325
+ data.onProgress({
323
326
  absolute: {
324
327
  total: lastProgress?.absolute?.total || 0,
325
328
  current: lastProgress?.absolute?.total || 0,
@@ -327,9 +330,9 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
327
330
  },
328
331
  });
329
332
  }
330
- async onCopyBackup(data) {
333
+ async copy(data) {
331
334
  const config = data.mirrorRepositoryConfig;
332
- const [snapshot] = await this.onSnapshots({
335
+ const [snapshot] = await this.fetchSnapshots({
333
336
  options: {
334
337
  ids: [data.snapshot.id],
335
338
  packageNames: [data.package.name],
@@ -351,14 +354,13 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
351
354
  id: snapshot.originalId,
352
355
  });
353
356
  }
354
- async onRestore(data) {
355
- const restorePath = data.targetPath ?? data.package.restorePath;
356
- (0, assert_1.ok)(restorePath);
357
+ async restore(data) {
358
+ const restorePath = data.snapshotPath;
357
359
  const restic = new Restic_1.Restic({
358
360
  env: await this.buildEnv(),
359
361
  log: data.options.verbose,
360
362
  });
361
- const [snapshot] = await this.onSnapshots({
363
+ const [snapshot] = await this.fetchSnapshots({
362
364
  options: {
363
365
  ids: [data.snapshot.id],
364
366
  packageNames: [data.package.name],
@@ -372,7 +374,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
372
374
  onStream: async (streamData) => {
373
375
  if (streamData.message_type === "restore-status") {
374
376
  const current = Math.min(streamData.total_bytes, snapshot.size);
375
- await data.onProgress({
377
+ data.onProgress({
376
378
  absolute: {
377
379
  total: snapshot.size,
378
380
  current,
package/Task/GitTask.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
1
+ import { TaskBackupData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export type GitTaskConfigType = {
4
4
  command?: string;
@@ -28,12 +28,11 @@ export declare const gitTaskDefinition: JSONSchema7;
28
28
  export declare class GitTask extends TaskAbstract<GitTaskConfigType> {
29
29
  protected verbose?: boolean;
30
30
  private get command();
31
- onBeforeBackup(): Promise<{
32
- targetPath: string;
31
+ backup(data: TaskBackupData): Promise<{
32
+ snapshotPath: string;
33
33
  }>;
34
- onBackup(data: BackupDataType): Promise<void>;
35
- onBeforeRestore(): Promise<{
36
- targetPath: string;
34
+ prepareRestore(): Promise<{
35
+ snapshotPath: string;
37
36
  }>;
38
- onRestore(data: RestoreDataType): Promise<void>;
37
+ restore(data: TaskRestoreData): Promise<void>;
39
38
  }
package/Task/GitTask.js CHANGED
@@ -6,6 +6,7 @@ const cli_1 = require("../utils/cli");
6
6
  const fs_1 = require("../utils/fs");
7
7
  const math_1 = require("../utils/math");
8
8
  const process_1 = require("../utils/process");
9
+ const temp_1 = require("../utils/temp");
9
10
  const TaskAbstract_1 = require("./TaskAbstract");
10
11
  const assert_1 = require("assert");
11
12
  const fs_2 = require("fs");
@@ -59,21 +60,17 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
59
60
  get command() {
60
61
  return this.config.command ?? "git";
61
62
  }
62
- async onBeforeBackup() {
63
- return {
64
- targetPath: await this.mkTmpDir(GitTask.name),
65
- };
66
- }
67
- async onBackup(data) {
63
+ async backup(data) {
64
+ if (!data.package.path)
65
+ throw new Error(`Path is required`);
66
+ const snapshotPath = await (0, temp_1.mkTmpDir)(exports.gitTaskName, "task", "backup", "snapshot");
68
67
  this.verbose = data.options.verbose;
69
68
  const config = this.config;
70
69
  const path = data.package.path;
71
- const targetPath = data.targetPath;
72
70
  (0, assert_1.ok)(typeof path === "string");
73
- (0, assert_1.ok)(typeof targetPath === "string");
74
71
  // Bundle
75
- const bundlePath = (0, path_1.join)(targetPath, "repo.bundle");
76
- await data.onProgress({
72
+ const bundlePath = (0, path_1.join)(snapshotPath, "repo.bundle");
73
+ data.onProgress({
77
74
  relative: {
78
75
  description: "Creating bundle",
79
76
  },
@@ -85,7 +82,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
85
82
  });
86
83
  // Config
87
84
  if (this.config.includeConfig ?? true) {
88
- const configPath = (0, path_1.join)(targetPath, "repo.config");
85
+ const configPath = (0, path_1.join)(snapshotPath, "repo.config");
89
86
  await (0, promises_1.copyFile)((0, path_1.join)(path, ".git", "config"), configPath);
90
87
  }
91
88
  // git ls-files
@@ -112,7 +109,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
112
109
  for (const option of lsFilesConfig) {
113
110
  if (!option.include)
114
111
  continue;
115
- option.pathsPath = (0, path_1.join)(targetPath, `repo.${option.name}-paths.txt`);
112
+ option.pathsPath = (0, path_1.join)(snapshotPath, `repo.${option.name}-paths.txt`);
116
113
  const stream = (0, fs_2.createWriteStream)(option.pathsPath);
117
114
  let streamError;
118
115
  stream.on("error", (e) => (streamError = e));
@@ -161,7 +158,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
161
158
  for (const option of lsFilesConfig) {
162
159
  if (!option.include)
163
160
  continue;
164
- const outPath = (0, path_1.join)(targetPath, `repo.${option.name}`);
161
+ const outPath = (0, path_1.join)(snapshotPath, `repo.${option.name}`);
165
162
  await (0, fs_1.mkdirIfNotExists)(outPath);
166
163
  if (data.options.verbose)
167
164
  (0, cli_1.logExec)(`Copying ${option.name} files to ${outPath}`);
@@ -171,12 +168,12 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
171
168
  path: option.pathsPath,
172
169
  basePath: path,
173
170
  },
174
- targetPath: outPath,
171
+ outPath: outPath,
175
172
  skipNotFoundError: true,
176
173
  concurrency: this.config.fileCopyConcurrency,
177
174
  onPath: async ({ entryPath }) => {
178
175
  currentFiles++;
179
- await data.onProgress({
176
+ data.onProgress({
180
177
  relative: {
181
178
  description: "Copying file",
182
179
  payload: entryPath,
@@ -191,26 +188,23 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
191
188
  });
192
189
  await (0, promises_1.rm)(option.pathsPath);
193
190
  }
191
+ return { snapshotPath };
194
192
  }
195
- async onBeforeRestore() {
193
+ async prepareRestore() {
196
194
  return {
197
- targetPath: await this.mkTmpDir(GitTask.name),
195
+ snapshotPath: await (0, temp_1.mkTmpDir)(exports.gitTaskName, "task", "restore", "snapshot"),
198
196
  };
199
197
  }
200
- async onRestore(data) {
198
+ async restore(data) {
201
199
  this.verbose = data.options.verbose;
202
- const restorePath = data.package.restorePath;
203
- const targetPath = data.targetPath;
204
- (0, assert_1.ok)(typeof restorePath === "string");
205
- (0, assert_1.ok)(typeof targetPath === "string");
206
- await (0, fs_1.mkdirIfNotExists)(restorePath);
207
- await (0, fs_1.ensureEmptyDir)(restorePath);
200
+ const snapshotPath = data.snapshotPath;
201
+ const restorePath = await (0, fs_1.initEmptyDir)(data.package.restorePath ?? data.package.path);
208
202
  // Stats
209
203
  let totalFiles = 0;
210
204
  let currentFiles = 0;
211
- await (0, fs_1.forEachFile)(targetPath, () => totalFiles++, true);
205
+ await (0, fs_1.forEachFile)(snapshotPath, () => totalFiles++, true);
212
206
  const incrementProgress = async (description, item, count = true) => {
213
- await data.onProgress({
207
+ data.onProgress({
214
208
  absolute: {
215
209
  total: totalFiles,
216
210
  current: Math.max(currentFiles, 0),
@@ -222,7 +216,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
222
216
  currentFiles++;
223
217
  };
224
218
  // Bundle
225
- const bundlePath = (0, path_1.join)(targetPath, "repo.bundle");
219
+ const bundlePath = (0, path_1.join)(snapshotPath, "repo.bundle");
226
220
  await (0, process_1.exec)(this.command, ["clone", bundlePath, "."], {
227
221
  cwd: restorePath,
228
222
  }, {
@@ -230,14 +224,14 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
230
224
  });
231
225
  await incrementProgress();
232
226
  // Config
233
- const configPath = (0, path_1.join)(targetPath, "repo.config");
227
+ const configPath = (0, path_1.join)(snapshotPath, "repo.config");
234
228
  if (await (0, fs_1.existsFile)(configPath)) {
235
229
  await (0, promises_1.copyFile)(configPath, (0, path_1.join)(restorePath, ".git", "config"));
236
230
  await incrementProgress();
237
231
  }
238
232
  // ls-files
239
233
  for (const name of ["untracked", "modified", "ignored"]) {
240
- const sourcePath = (0, path_1.join)(targetPath, `repo.${name}`);
234
+ const sourcePath = (0, path_1.join)(snapshotPath, `repo.${name}`);
241
235
  if (await (0, fs_1.existsDir)(sourcePath)) {
242
236
  if (data.options.verbose)
243
237
  (0, cli_1.logExec)(`Copying ${name} files to ${restorePath}`);
@@ -246,7 +240,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
246
240
  type: "glob",
247
241
  sourcePath,
248
242
  },
249
- targetPath: restorePath,
243
+ outPath: restorePath,
250
244
  concurrency: this.config.fileCopyConcurrency,
251
245
  onProgress: async (progress) => await incrementProgress(progress.type === "end" ? "Files copied" : "Copying file", progress.path, !progress.type),
252
246
  });
@@ -1,4 +1,4 @@
1
- import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
1
+ import { TaskBackupData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export type MariadbTaskConfigType = {
4
4
  command?: string;
@@ -28,9 +28,8 @@ export declare const mariadbTaskDefinition: JSONSchema7;
28
28
  export declare class MariadbTask extends TaskAbstract<MariadbTaskConfigType> {
29
29
  protected verbose?: boolean;
30
30
  private get command();
31
- onBeforeBackup(): Promise<{
32
- targetPath: string;
31
+ backup(data: TaskBackupData): Promise<{
32
+ snapshotPath: string;
33
33
  }>;
34
- onBackup(data: BackupDataType): Promise<void>;
35
- onRestore(data: RestoreDataType): Promise<void>;
34
+ restore(data: TaskRestoreData): Promise<void>;
36
35
  }