@datatruck/cli 0.14.0 → 0.16.1

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 (46) hide show
  1. package/Action/BackupAction.d.ts +10 -3
  2. package/Action/BackupAction.js +41 -49
  3. package/Action/RestoreAction.d.ts +2 -2
  4. package/Action/RestoreAction.js +8 -16
  5. package/Command/BackupCommand.js +2 -1
  6. package/Command/BackupSessionsCommand.js +1 -0
  7. package/Command/RestoreCommand.js +1 -1
  8. package/Command/RestoreSessionsCommand.js +1 -0
  9. package/Entity/StateEntityAbstract.d.ts +2 -5
  10. package/Error/AppError.d.ts +1 -0
  11. package/Error/AppError.js +4 -0
  12. package/Repository/DatatruckRepository.d.ts +1 -0
  13. package/Repository/DatatruckRepository.js +162 -158
  14. package/Repository/RepositoryAbstract.d.ts +4 -10
  15. package/Repository/ResticRepository.js +34 -17
  16. package/SessionDriver/ConsoleSessionDriver.d.ts +2 -7
  17. package/SessionDriver/ConsoleSessionDriver.js +51 -24
  18. package/SessionDriver/SqliteSessionDriver.js +5 -0
  19. package/SessionManager/BackupSessionManager.d.ts +12 -11
  20. package/SessionManager/BackupSessionManager.js +20 -5
  21. package/SessionManager/RestoreSessionManager.d.ts +14 -11
  22. package/SessionManager/RestoreSessionManager.js +20 -5
  23. package/SessionManager/SessionManagerAbstract.d.ts +18 -0
  24. package/SessionManager/SessionManagerAbstract.js +32 -0
  25. package/Task/GitTask.js +22 -14
  26. package/Task/MariadbTask.js +9 -4
  27. package/Task/MysqlDumpTask.d.ts +3 -1
  28. package/Task/MysqlDumpTask.js +5 -2
  29. package/Task/PostgresqlDumpTask.d.ts +3 -1
  30. package/Task/PostgresqlDumpTask.js +2 -2
  31. package/Task/SqlDumpTaskAbstract.d.ts +3 -1
  32. package/Task/SqlDumpTaskAbstract.js +55 -13
  33. package/Task/TaskAbstract.d.ts +3 -9
  34. package/cli.js +1 -1
  35. package/migrations/001-initial.sql +6 -30
  36. package/package.json +1 -1
  37. package/util/cli-util.d.ts +1 -1
  38. package/util/cli-util.js +17 -2
  39. package/util/fs-util.d.ts +10 -1
  40. package/util/fs-util.js +10 -1
  41. package/util/process-util.d.ts +3 -0
  42. package/util/process-util.js +11 -0
  43. package/util/progress.d.ts +12 -0
  44. package/util/progress.js +2 -0
  45. package/util/zip-util.d.ts +23 -5
  46. package/util/zip-util.js +82 -25
@@ -23,10 +23,17 @@ export declare class BackupAction<TRequired extends boolean = true> {
23
23
  protected repoErrors: Record<string, Error[]>;
24
24
  constructor(config: ConfigType, options?: IfRequireKeys<TRequired, BackupActionOptionsType>);
25
25
  protected init(session: BackupSessionManager): Promise<[SnapshotType, PackageConfigType[]]>;
26
- protected execTask(session: BackupSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
27
- protected execRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
28
- protected execCopyRepository(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, mirrorRepo: RepositoryConfigType, snapshot: SnapshotType): Promise<boolean>;
26
+ protected task(session: BackupSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
27
+ protected backup(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
28
+ protected copyBackup(session: BackupSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, mirrorRepo: RepositoryConfigType, snapshot: SnapshotType): Promise<boolean>;
29
29
  protected getError(pkg: PackageConfigType): AppError | null;
30
+ protected splitRepositories(repositoryNames: string[]): {
31
+ repoNames: string[];
32
+ mirrors: {
33
+ sourceName: string;
34
+ name: string;
35
+ }[];
36
+ };
30
37
  exec(session: BackupSessionManager): Promise<{
31
38
  total: number;
32
39
  errors: number;
@@ -15,7 +15,7 @@ class BackupAction {
15
15
  }
16
16
  async init(session) {
17
17
  const snapshot = {
18
- id: (0, crypto_1.randomBytes)(20).toString("hex"),
18
+ id: (0, crypto_1.randomUUID)().replaceAll("-", ""),
19
19
  date: this.options.date ?? new Date().toISOString(),
20
20
  };
21
21
  await session.initDrivers();
@@ -53,7 +53,7 @@ class BackupAction {
53
53
  }
54
54
  return [snapshot, packages];
55
55
  }
56
- async execTask(session, pkg, task, snapshot, targetPath) {
56
+ async task(session, pkg, task, snapshot, targetPath) {
57
57
  const taskId = session.findTaskId({
58
58
  packageName: pkg.name,
59
59
  taskName: task.name,
@@ -74,14 +74,10 @@ class BackupAction {
74
74
  options: this.options,
75
75
  snapshot,
76
76
  targetPath,
77
- onProgress: async (data) => {
77
+ onProgress: async (progress) => {
78
78
  await session.progressTask({
79
79
  id: taskId,
80
- progressCurrent: data.current,
81
- progressPercent: data.percent,
82
- progressStep: data.step,
83
- progressStepPercent: data.stepPercent,
84
- progressTotal: data.total,
80
+ progress,
85
81
  });
86
82
  },
87
83
  });
@@ -98,7 +94,7 @@ class BackupAction {
98
94
  });
99
95
  return error ? false : true;
100
96
  }
101
- async execRepository(session, pkg, repo, snapshot, targetPath) {
97
+ async backup(session, pkg, repo, snapshot, targetPath) {
102
98
  const repositoryId = session.findRepositoryId({
103
99
  packageName: pkg.name,
104
100
  repositoryName: repo.name,
@@ -120,14 +116,10 @@ class BackupAction {
120
116
  (!config.names || config.names.includes(repo.name)))?.config,
121
117
  options: this.options,
122
118
  snapshot: snapshot,
123
- onProgress: async (data) => {
119
+ onProgress: async (progress) => {
124
120
  await session.progressRepository({
125
121
  id: repositoryId,
126
- progressCurrent: data.current,
127
- progressPercent: data.percent,
128
- progressStep: data.step,
129
- progressStepPercent: data.stepPercent,
130
- progressTotal: data.total,
122
+ progress,
131
123
  });
132
124
  },
133
125
  });
@@ -144,7 +136,7 @@ class BackupAction {
144
136
  });
145
137
  return error ? false : true;
146
138
  }
147
- async execCopyRepository(session, pkg, repo, mirrorRepo, snapshot) {
139
+ async copyBackup(session, pkg, repo, mirrorRepo, snapshot) {
148
140
  const repositoryId = session.findRepositoryId({
149
141
  packageName: pkg.name,
150
142
  repositoryName: mirrorRepo.name,
@@ -164,14 +156,10 @@ class BackupAction {
164
156
  package: pkg,
165
157
  snapshot,
166
158
  mirrorRepositoryConfig: mirrorRepo.config,
167
- onProgress: async (data) => {
159
+ onProgress: async (progress) => {
168
160
  await session.progressRepository({
169
161
  id: repositoryId,
170
- progressCurrent: data.current,
171
- progressPercent: data.percent,
172
- progressStep: data.step,
173
- progressStepPercent: data.stepPercent,
174
- progressTotal: data.total,
162
+ progress,
175
163
  });
176
164
  },
177
165
  });
@@ -204,12 +192,33 @@ class BackupAction {
204
192
  return null;
205
193
  }
206
194
  }
195
+ splitRepositories(repositoryNames) {
196
+ const mirrorRepoMap = {};
197
+ const allMirrorRepoNames = [];
198
+ const repoNames = repositoryNames ?? [];
199
+ for (const repoName of repoNames) {
200
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
201
+ if (repo.mirrorRepoNames)
202
+ mirrorRepoMap[repoName] = repo.mirrorRepoNames.filter((mirrorRepoName) => {
203
+ allMirrorRepoNames.push(mirrorRepoName);
204
+ return repoNames.includes(mirrorRepoName);
205
+ });
206
+ }
207
+ return {
208
+ repoNames: repoNames.filter((v) => !allMirrorRepoNames.includes(v)),
209
+ mirrors: repoNames.flatMap((sourceName) => {
210
+ const mirrorNames = mirrorRepoMap[sourceName] || [];
211
+ return mirrorNames.map((name) => ({
212
+ sourceName,
213
+ name,
214
+ }));
215
+ }),
216
+ };
217
+ }
207
218
  async exec(session) {
208
219
  const [snapshot, packages] = await this.init(session);
209
- let total = 0;
210
220
  let errors = 0;
211
221
  for (const pkg of packages) {
212
- total++;
213
222
  const id = session.findId({
214
223
  packageName: pkg.name,
215
224
  });
@@ -224,34 +233,17 @@ class BackupAction {
224
233
  package: pkg,
225
234
  snapshot,
226
235
  });
227
- await this.execTask(session, pkg, pkg.task, snapshot, (targetPath = result?.targetPath));
236
+ await this.task(session, pkg, pkg.task, snapshot, (targetPath = result?.targetPath));
228
237
  }
229
- const mirrorRepoMap = {};
230
- const allMirrorRepoNames = [];
231
- const repoNames = pkg.repositoryNames ?? [];
238
+ const { repoNames, mirrors } = this.splitRepositories(pkg.repositoryNames ?? []);
232
239
  for (const repoName of repoNames) {
233
240
  const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
234
- if (repo.mirrorRepoNames)
235
- mirrorRepoMap[repoName] = repo.mirrorRepoNames.filter((mirrorRepoName) => {
236
- allMirrorRepoNames.push(mirrorRepoName);
237
- return repoNames.includes(mirrorRepoName);
238
- });
241
+ await this.backup(session, pkg, repo, snapshot, targetPath);
239
242
  }
240
- for (const repoName of repoNames) {
241
- if (allMirrorRepoNames.includes(repoName))
242
- continue;
243
- const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
244
- await this.execRepository(session, pkg, repo, snapshot, targetPath);
245
- }
246
- for (const repoName of repoNames) {
247
- const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
248
- const mirrorRepoNames = mirrorRepoMap[repoName];
249
- if (mirrorRepoNames) {
250
- for (const mirrorRepoName of mirrorRepoNames) {
251
- const mirrorRepo = (0, config_util_1.findRepositoryOrFail)(this.config, mirrorRepoName);
252
- await this.execCopyRepository(session, pkg, repo, mirrorRepo, snapshot);
253
- }
254
- }
243
+ for (const mirror of mirrors) {
244
+ const repo = (0, config_util_1.findRepositoryOrFail)(this.config, mirror.sourceName);
245
+ const mirrorRepo = (0, config_util_1.findRepositoryOrFail)(this.config, mirror.name);
246
+ await this.copyBackup(session, pkg, repo, mirrorRepo, snapshot);
255
247
  }
256
248
  const error = this.getError(pkg);
257
249
  if (error)
@@ -265,7 +257,7 @@ class BackupAction {
265
257
  snapshotId: snapshot.id.slice(0, 8),
266
258
  });
267
259
  return {
268
- total: total,
260
+ total: packages.length,
269
261
  errors: errors,
270
262
  };
271
263
  }
@@ -30,8 +30,8 @@ export declare class RestoreAction<TRequired extends boolean = true> {
30
30
  protected init(session: RestoreSessionManager, snapshotId: string, snapshots: SnapshotAndConfigType[]): Promise<void>;
31
31
  protected findSnapshots(): Promise<SnapshotType[]>;
32
32
  protected groupSnapshots(snapshots: SnapshotType[]): SnapshotType[];
33
- protected execTask(session: RestoreSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
34
- protected execRepository(session: RestoreSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
33
+ protected task(session: RestoreSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
34
+ protected restore(session: RestoreSessionManager, pkg: PackageConfigType, repo: RepositoryConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
35
35
  protected getError(pkg: PackageConfigType): AppError | null;
36
36
  exec(session: RestoreSessionManager): Promise<boolean>;
37
37
  }
@@ -88,7 +88,7 @@ class RestoreAction {
88
88
  return true;
89
89
  });
90
90
  }
91
- async execTask(session, pkg, task, snapshot, targetPath) {
91
+ async task(session, pkg, task, snapshot, targetPath) {
92
92
  const taskId = session.findTaskId({
93
93
  packageName: pkg.name,
94
94
  taskName: task.name,
@@ -111,14 +111,10 @@ class RestoreAction {
111
111
  options: this.options,
112
112
  snapshot,
113
113
  targetPath,
114
- onProgress: async (data) => {
114
+ onProgress: async (progress) => {
115
115
  await session.progressTask({
116
116
  id: taskId,
117
- progressCurrent: data.current,
118
- progressPercent: data.percent,
119
- progressStep: data.step,
120
- progressStepPercent: data.stepPercent,
121
- progressTotal: data.total,
117
+ progress,
122
118
  });
123
119
  },
124
120
  });
@@ -135,7 +131,7 @@ class RestoreAction {
135
131
  });
136
132
  return error ? false : true;
137
133
  }
138
- async execRepository(session, pkg, repo, snapshot, targetPath) {
134
+ async restore(session, pkg, repo, snapshot, targetPath) {
139
135
  const repositoryId = session.findRepositoryId({
140
136
  packageName: pkg.name,
141
137
  repositoryName: repo.name,
@@ -160,14 +156,10 @@ class RestoreAction {
160
156
  (!config.names || config.names.includes(repo.name)))?.config,
161
157
  options: this.options,
162
158
  snapshot: snapshot,
163
- onProgress: async (data) => {
159
+ onProgress: async (progress) => {
164
160
  await session.progressRepository({
165
161
  id: repositoryId,
166
- progressCurrent: data.current,
167
- progressPercent: data.percent,
168
- progressStep: data.step,
169
- progressStepPercent: data.stepPercent,
170
- progressTotal: data.total,
162
+ progress,
171
163
  });
172
164
  },
173
165
  });
@@ -240,9 +232,9 @@ class RestoreAction {
240
232
  });
241
233
  targetPath = result?.targetPath;
242
234
  }
243
- await this.execRepository(session, pkg, repo, snapshot, targetPath);
235
+ await this.restore(session, pkg, repo, snapshot, targetPath);
244
236
  if (pkg.task)
245
- await this.execTask(session, pkg, pkg.task, snapshot, targetPath);
237
+ await this.task(session, pkg, pkg.task, snapshot, targetPath);
246
238
  const error = this.getError(pkg);
247
239
  await session.end({
248
240
  id,
@@ -68,9 +68,10 @@ class BackupCommand extends CommandAbstract_1.CommandAbstract {
68
68
  new ConsoleSessionDriver_1.ConsoleSessionDriver({
69
69
  verbose: verbose > 0,
70
70
  progress: this.globalOptions.progress,
71
- progressInterval: this.globalOptions.progressInterval,
72
71
  }),
73
72
  ],
73
+ verbose: verbose > 1,
74
+ progressInterval: this.globalOptions.progressInterval,
74
75
  });
75
76
  const result = await backup.exec(sessionManager);
76
77
  if (result.errors) {
@@ -50,6 +50,7 @@ class BackupSessionsCommand extends CommandAbstract_1.CommandAbstract {
50
50
  verbose: verbose > 1,
51
51
  }),
52
52
  verbose: verbose > 1,
53
+ progressInterval: this.globalOptions.progressInterval,
53
54
  });
54
55
  const items = await action.exec(manager);
55
56
  const dataFormat = new DataFormat_1.DataFormat({
@@ -68,10 +68,10 @@ class RestoreCommand extends CommandAbstract_1.CommandAbstract {
68
68
  new ConsoleSessionDriver_1.ConsoleSessionDriver({
69
69
  verbose: verbose > 0,
70
70
  progress: this.globalOptions.progress,
71
- progressInterval: this.globalOptions.progressInterval,
72
71
  }),
73
72
  ],
74
73
  verbose: verbose > 1,
74
+ progressInterval: this.globalOptions.progressInterval,
75
75
  });
76
76
  const result = await restore.exec(sessionManager);
77
77
  return result ? 0 : 1;
@@ -49,6 +49,7 @@ class RestoreSessionsCommand extends CommandAbstract_1.CommandAbstract {
49
49
  driver: new SqliteSessionDriver_1.SqliteSessionDriver({
50
50
  verbose: verbose > 1,
51
51
  }),
52
+ progressInterval: this.globalOptions.progressInterval,
52
53
  });
53
54
  const items = await action.exec(manager);
54
55
  const dataFormat = new DataFormat_1.DataFormat({
@@ -1,12 +1,9 @@
1
+ import { Progress } from "../util/progress";
1
2
  import { CrudEntityAbstract } from "./CrudEntityAbstract";
2
3
  export declare abstract class StateEntityAbstract extends CrudEntityAbstract {
3
4
  state: "started" | "ended" | null;
4
5
  error?: string | null;
5
6
  startDate?: string | null;
6
7
  endDate?: string | null;
7
- progressTotal?: number | null;
8
- progressCurrent?: number | null;
9
- progressPercent?: number | null;
10
- progressStep?: string | null;
11
- progressStepPercent?: number | null;
8
+ progress?: Progress;
12
9
  }
@@ -1,2 +1,3 @@
1
1
  export declare class AppError extends Error {
2
+ constructor(message: string);
2
3
  }
package/Error/AppError.js CHANGED
@@ -2,5 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AppError = void 0;
4
4
  class AppError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = AppError.name;
8
+ }
5
9
  }
6
10
  exports.AppError = AppError;
@@ -49,6 +49,7 @@ export declare class DatatruckRepository extends RepositoryAbstract<DatatruckRep
49
49
  static stringifyMetaData(data: MetaDataType): string;
50
50
  onGetSource(): string;
51
51
  onInit(data: InitDataType): Promise<void>;
52
+ private createFileScanner;
52
53
  onPrune(data: PruneDataType): Promise<void>;
53
54
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
54
55
  private normalizeCompressConfig;