@datatruck/cli 0.8.0 → 0.11.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 (43) hide show
  1. package/Action/BackupAction.d.ts +1 -0
  2. package/Action/BackupAction.js +68 -1
  3. package/Action/ConfigAction.js +16 -0
  4. package/Command/BackupSessionsCommand.js +9 -2
  5. package/Command/ConfigCommand.d.ts +1 -1
  6. package/Command/ConfigCommand.js +7 -3
  7. package/Command/InitCommand.js +1 -1
  8. package/Command/PruneCommand.js +1 -1
  9. package/Command/RestoreSessionsCommand.js +9 -2
  10. package/Command/SnapshotsCommand.js +9 -2
  11. package/Config/RepositoryConfig.d.ts +1 -0
  12. package/Config/RepositoryConfig.js +1 -0
  13. package/Factory/CommandFactory.js +2 -2
  14. package/Repository/GitRepository.d.ts +2 -1
  15. package/Repository/GitRepository.js +3 -0
  16. package/Repository/LocalRepository.d.ts +2 -1
  17. package/Repository/LocalRepository.js +23 -1
  18. package/Repository/RepositoryAbstract.d.ts +8 -0
  19. package/Repository/ResticRepository.d.ts +2 -1
  20. package/Repository/ResticRepository.js +24 -0
  21. package/Task/MariadbTask.js +1 -1
  22. package/Task/MssqlTask.js +1 -1
  23. package/Task/MysqlDumpTask.d.ts +2 -1
  24. package/Task/MysqlDumpTask.js +31 -1
  25. package/Task/PostgresqlDumpTask.d.ts +2 -1
  26. package/Task/PostgresqlDumpTask.js +4 -1
  27. package/Task/SqlDumpTaskAbstract.d.ts +3 -1
  28. package/Task/SqlDumpTaskAbstract.js +8 -3
  29. package/cli.js +3 -2
  30. package/config.schema.json +6 -0
  31. package/package.json +11 -11
  32. package/util/DataFormat.d.ts +4 -2
  33. package/util/DataFormat.js +11 -1
  34. package/util/GitUtil.js +1 -2
  35. package/util/ResticUtil.d.ts +4 -0
  36. package/util/ResticUtil.js +16 -0
  37. package/util/cli-util.js +2 -2
  38. package/util/date-util.d.ts +1 -1
  39. package/util/entity-util.d.ts +1 -1
  40. package/util/fs-util.d.ts +7 -0
  41. package/util/fs-util.js +60 -5
  42. package/util/process-util.d.ts +1 -0
  43. package/CHANGELOG.md +0 -145
@@ -25,6 +25,7 @@ export declare class BackupAction<TRequired extends boolean = true> {
25
25
  protected init(session: BackupSessionManager): Promise<[SnapshotType, PackageConfigType[]]>;
26
26
  protected execTask(session: BackupSessionManager, pkg: PackageConfigType, task: TaskConfigType, snapshot: SnapshotType, targetPath: string | undefined): Promise<boolean>;
27
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>;
28
29
  protected getError(pkg: PackageConfigType): AppError | null;
29
30
  exec(session: BackupSessionManager): Promise<{
30
31
  total: number;
@@ -144,6 +144,50 @@ class BackupAction {
144
144
  });
145
145
  return error ? false : true;
146
146
  }
147
+ async execCopyRepository(session, pkg, repo, mirrorRepo, snapshot) {
148
+ const repositoryId = session.findRepositoryId({
149
+ packageName: pkg.name,
150
+ repositoryName: mirrorRepo.name,
151
+ });
152
+ await session.startRepository({
153
+ id: repositoryId,
154
+ });
155
+ let error;
156
+ if (this.taskErrors[pkg.name]?.length) {
157
+ error = new AppError_1.AppError("Task failed");
158
+ }
159
+ else {
160
+ try {
161
+ const repoInstance = (0, RepositoryFactory_1.RepositoryFactory)(repo);
162
+ await repoInstance.onCopyBackup({
163
+ options: this.options,
164
+ package: pkg,
165
+ snapshot,
166
+ mirrorRepositoryConfig: mirrorRepo.config,
167
+ onProgress: async (data) => {
168
+ await session.progressRepository({
169
+ id: repositoryId,
170
+ progressCurrent: data.current,
171
+ progressPercent: data.percent,
172
+ progressStep: data.step,
173
+ progressStepPercent: data.stepPercent,
174
+ progressTotal: data.total,
175
+ });
176
+ },
177
+ });
178
+ }
179
+ catch (_) {
180
+ if (!this.repoErrors[pkg.name])
181
+ this.repoErrors[pkg.name] = [];
182
+ this.repoErrors[pkg.name].push((error = _));
183
+ }
184
+ }
185
+ await session.endRepository({
186
+ id: repositoryId,
187
+ error: error?.stack,
188
+ });
189
+ return error ? false : true;
190
+ }
147
191
  getError(pkg) {
148
192
  const taskErrors = this.taskErrors[pkg.name]?.length;
149
193
  const repoErrors = this.repoErrors[pkg.name]?.length;
@@ -182,10 +226,33 @@ class BackupAction {
182
226
  });
183
227
  await this.execTask(session, pkg, pkg.task, snapshot, (targetPath = result?.targetPath));
184
228
  }
185
- for (const repoName of pkg.repositoryNames ?? []) {
229
+ const mirrorRepoMap = {};
230
+ const allMirrorRepoNames = [];
231
+ const repoNames = pkg.repositoryNames ?? [];
232
+ for (const repoName of repoNames) {
233
+ 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
+ });
239
+ }
240
+ for (const repoName of repoNames) {
241
+ if (allMirrorRepoNames.includes(repoName))
242
+ continue;
186
243
  const repo = (0, config_util_1.findRepositoryOrFail)(this.config, repoName);
187
244
  await this.execRepository(session, pkg, repo, snapshot, targetPath);
188
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
+ }
255
+ }
189
256
  const error = this.getError(pkg);
190
257
  if (error)
191
258
  errors++;
@@ -22,11 +22,27 @@ class ConfigAction {
22
22
  }
23
23
  static check(config) {
24
24
  const repositoryNames = [];
25
+ const mirrorRepoNames = [];
26
+ const repos = {};
25
27
  for (const repo of config.repositories) {
28
+ repos[repo.name] = repo;
26
29
  if (repositoryNames.includes(repo.name))
27
30
  throw new AppError_1.AppError(`Duplicated repository name: ${repo.name}`);
28
31
  repositoryNames.push(repo.name);
29
32
  }
33
+ for (const repo of config.repositories) {
34
+ if (repo.mirrorRepoNames) {
35
+ for (const mirrorRepoName of repo.mirrorRepoNames) {
36
+ if (!repos[mirrorRepoName])
37
+ throw new AppError_1.AppError(`Mirror repository name not found: ${mirrorRepoName}`);
38
+ if (repos[mirrorRepoName].type !== repo.type)
39
+ throw new AppError_1.AppError(`Mirror repository type is incompatible: ${mirrorRepoName}`);
40
+ if (mirrorRepoNames.includes(mirrorRepoName))
41
+ throw new AppError_1.AppError(`Mirror repository is already used`);
42
+ mirrorRepoNames.push(mirrorRepoName);
43
+ }
44
+ }
45
+ }
30
46
  const packageNames = [];
31
47
  for (const pkg of config.packages) {
32
48
  if (packageNames.includes(pkg.name))
@@ -51,8 +51,9 @@ class BackupSessionsCommand extends CommandAbstract_1.CommandAbstract {
51
51
  }),
52
52
  verbose: verbose > 1,
53
53
  });
54
+ const items = await action.exec(manager);
54
55
  const dataFormat = new DataFormat_1.DataFormat({
55
- items: await action.exec(manager),
56
+ items,
56
57
  table: {
57
58
  labels: [
58
59
  " ",
@@ -77,7 +78,13 @@ class BackupSessionsCommand extends CommandAbstract_1.CommandAbstract {
77
78
  },
78
79
  });
79
80
  if (this.globalOptions.outputFormat)
80
- console.log(dataFormat.format(this.globalOptions.outputFormat));
81
+ console.info(dataFormat.format(this.globalOptions.outputFormat, {
82
+ tpl: {
83
+ sids: () => items.map((i) => i.snapshotId).join(),
84
+ ssids: () => items.map((i) => i.snapshotId.slice(0, 8)).join(),
85
+ pkgNames: () => items.map((i) => i.packageName).join(),
86
+ },
87
+ }));
81
88
  return 0;
82
89
  }
83
90
  }
@@ -8,7 +8,7 @@ export declare type ConfigCommandOptionsType<TResolved = false> = {
8
8
  repositoryType?: If<TResolved, RepositoryConfigType["type"][]>;
9
9
  };
10
10
  export declare type ConfigCommandLogType = {
11
- package: string;
11
+ packageName: string;
12
12
  repositoryNames: string[];
13
13
  taskName: string | undefined;
14
14
  }[];
@@ -40,7 +40,7 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
40
40
  repositoryTypes: this.options.repositoryType,
41
41
  });
42
42
  const summaryConfig = packages.flatMap((pkg) => ({
43
- package: pkg.name,
43
+ packageName: pkg.name,
44
44
  repositoryNames: pkg.repositoryNames ?? [],
45
45
  taskName: pkg.task?.name,
46
46
  }));
@@ -49,14 +49,18 @@ class ConfigCommand extends CommandAbstract_1.CommandAbstract {
49
49
  table: {
50
50
  labels: ["Package", "Repository", "Task"],
51
51
  handler: (item) => [
52
- item.package,
52
+ item.packageName,
53
53
  item.repositoryNames.join(", "),
54
54
  item.taskName ?? "",
55
55
  ],
56
56
  },
57
57
  });
58
58
  if (this.globalOptions.outputFormat)
59
- console.log(dataFormat.format(this.globalOptions.outputFormat));
59
+ console.info(dataFormat.format(this.globalOptions.outputFormat, {
60
+ tpl: {
61
+ pkgNames: () => summaryConfig.map((i) => i.packageName).join(),
62
+ },
63
+ }));
60
64
  return 0;
61
65
  }
62
66
  }
@@ -56,7 +56,7 @@ class InitCommand extends CommandAbstract_1.CommandAbstract {
56
56
  },
57
57
  });
58
58
  if (this.globalOptions.outputFormat)
59
- console.log(dataFormat.format(this.globalOptions.outputFormat));
59
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
60
60
  return 0;
61
61
  }
62
62
  }
@@ -144,7 +144,7 @@ class PruneCommand extends CommandAbstract_1.CommandAbstract {
144
144
  },
145
145
  });
146
146
  if (this.globalOptions.outputFormat)
147
- console.log(dataFormat.format(this.globalOptions.outputFormat));
147
+ console.info(dataFormat.format(this.globalOptions.outputFormat));
148
148
  if (!this.options.confirm && !this.options.dryRun) {
149
149
  const answer = await (0, cli_util_1.confirm)(`Delete ${pruneResult.prune}/${pruneResult.total} snapshots?`);
150
150
  if (answer)
@@ -50,8 +50,9 @@ class RestoreSessionsCommand extends CommandAbstract_1.CommandAbstract {
50
50
  verbose: verbose > 1,
51
51
  }),
52
52
  });
53
+ const items = await action.exec(manager);
53
54
  const dataFormat = new DataFormat_1.DataFormat({
54
- items: await action.exec(manager),
55
+ items,
55
56
  table: {
56
57
  labels: [
57
58
  " ",
@@ -76,7 +77,13 @@ class RestoreSessionsCommand extends CommandAbstract_1.CommandAbstract {
76
77
  },
77
78
  });
78
79
  if (this.globalOptions.outputFormat)
79
- console.log(dataFormat.format(this.globalOptions.outputFormat));
80
+ console.info(dataFormat.format(this.globalOptions.outputFormat, {
81
+ tpl: {
82
+ sids: () => items.map((i) => i.snapshotId).join(),
83
+ ssids: () => items.map((i) => i.snapshotId.slice(0, 8)).join(),
84
+ pkgNames: () => items.map((i) => i.packageName).join(),
85
+ },
86
+ }));
80
87
  return 0;
81
88
  }
82
89
  }
@@ -106,8 +106,9 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
106
106
  verbose: verbose > 0,
107
107
  tags: this.options.tag,
108
108
  });
109
+ const items = await snapshots.exec();
109
110
  const dataFormat = new DataFormat_1.DataFormat({
110
- items: await snapshots.exec(),
111
+ items,
111
112
  table: {
112
113
  labels: [
113
114
  "Id.",
@@ -128,7 +129,13 @@ class SnapshotsCommand extends CommandAbstract_1.CommandAbstract {
128
129
  },
129
130
  });
130
131
  if (this.globalOptions.outputFormat)
131
- console.log(dataFormat.format(this.globalOptions.outputFormat));
132
+ console.info(dataFormat.format(this.globalOptions.outputFormat, {
133
+ tpl: {
134
+ sids: () => items.map((i) => i.id).join(),
135
+ ssids: () => items.map((i) => i.shortId).join(),
136
+ pkgNames: () => items.map((i) => i.packageName).join(),
137
+ },
138
+ }));
132
139
  return 0;
133
140
  }
134
141
  }
@@ -7,6 +7,7 @@ export declare type RepositoryConfigTypeType = RepositoryConfigType["type"];
7
7
  export declare type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
8
8
  export declare type RepositoryConfigType = {
9
9
  name: string;
10
+ mirrorRepoNames?: string[];
10
11
  enabled?: boolean | {
11
12
  [K in "defaults" | RepositoryConfigEnabledActionType]?: boolean;
12
13
  };
@@ -17,6 +17,7 @@ exports.repositoryConfigDefinition = {
17
17
  properties: {
18
18
  type: { type: "string" },
19
19
  name: { type: "string" },
20
+ mirrorRepoNames: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
20
21
  enabled: {
21
22
  anyOf: [
22
23
  {
@@ -35,11 +35,11 @@ exports.exec = exec;
35
35
  function makeParseLog(type) {
36
36
  const data = [];
37
37
  const consoleLog = console.log;
38
- console.log = (...items) => {
38
+ console.log = console.info = (...items) => {
39
39
  data.push(...items);
40
40
  };
41
41
  return function parseLog() {
42
- console.log = consoleLog;
42
+ console.log = console.info = consoleLog;
43
43
  return JSON.parse(data.flat().join("\n"));
44
44
  };
45
45
  }
@@ -1,4 +1,4 @@
1
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType } from "./RepositoryAbstract";
1
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export declare type GitRepositoryConfigType = {
4
4
  repo: string;
@@ -25,5 +25,6 @@ export declare class GitRepository extends RepositoryAbstract<GitRepositoryConfi
25
25
  onPrune(data: PruneDataType): Promise<void>;
26
26
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
27
27
  onBackup(data: BackupDataType<GitPackageRepositoryConfigType>): Promise<void>;
28
+ onCopyBackup(data: CopyBackupType<GitRepositoryConfigType>): Promise<void>;
28
29
  onRestore(data: RestoreDataType<GitPackageRepositoryConfigType>): Promise<void>;
29
30
  }
@@ -215,6 +215,9 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
215
215
  recursive: true,
216
216
  });
217
217
  }
218
+ onCopyBackup(data) {
219
+ throw new Error("Method not implemented.");
220
+ }
218
221
  async onRestore(data) {
219
222
  const restorePath = data.targetPath ?? data.package.restorePath;
220
223
  (0, assert_1.ok)(restorePath);
@@ -1,4 +1,4 @@
1
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType } from "./RepositoryAbstract";
1
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import type { JSONSchema7 } from "json-schema";
3
3
  export declare type MetaDataType = {
4
4
  id: string;
@@ -51,6 +51,7 @@ export declare class LocalRepository extends RepositoryAbstract<LocalRepositoryC
51
51
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
52
52
  private normalizeCompressConfig;
53
53
  onBackup(data: BackupDataType<LocalPackageRepositoryConfigType>): Promise<void>;
54
+ onCopyBackup(data: CopyBackupType<LocalRepositoryConfigType>): Promise<void>;
54
55
  onRestore(data: RestoreDataType<LocalPackageRepositoryConfigType>): Promise<void>;
55
56
  }
56
57
  export {};
@@ -122,7 +122,7 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
122
122
  async onSnapshots(data) {
123
123
  if (!(await (0, fs_util_1.checkDir)(this.config.outPath)))
124
124
  throw new Error(`Repository (${this.repository.name}) out path does not exist: ${this.config.outPath}`);
125
- const snapshotNames = await (0, promises_1.readdir)(this.config.outPath);
125
+ const snapshotNames = await (0, fs_util_1.readDir)(this.config.outPath);
126
126
  const snapshots = [];
127
127
  const packagePatterns = (0, string_util_1.makePathPatterns)(data.options.packageNames);
128
128
  const taskPatterns = (0, string_util_1.makePathPatterns)(data.options.packageTaskNames);
@@ -299,6 +299,28 @@ class LocalRepository extends RepositoryAbstract_1.RepositoryAbstract {
299
299
  (0, cli_util_1.logExec)(`Writing metadata into ${metaPath}`);
300
300
  await (0, promises_1.writeFile)(metaPath, LocalRepository.stringifyMetaData(meta));
301
301
  }
302
+ async onCopyBackup(data) {
303
+ const snapshotName = LocalRepository.buildSnapshotName({
304
+ snapshotId: data.snapshot.id,
305
+ snapshotDate: data.snapshot.date,
306
+ packageName: data.package.name,
307
+ });
308
+ const sourcePath = (0, path_1.resolve)((0, path_1.join)(this.config.outPath, snapshotName));
309
+ const targetPath = (0, path_1.resolve)((0, path_1.join)(data.mirrorRepositoryConfig.outPath, snapshotName));
310
+ const sourceMetaPath = `${sourcePath}.json`;
311
+ const targetMetaPath = `${targetPath}.json`;
312
+ if (data.options.verbose)
313
+ (0, cli_util_1.logExec)(`Copying files to ${targetPath}`);
314
+ await (0, promises_1.mkdir)(targetPath);
315
+ await (0, fs_util_1.cpy)({
316
+ input: {
317
+ type: "glob",
318
+ sourcePath,
319
+ },
320
+ targetPath,
321
+ });
322
+ await (0, promises_1.copyFile)(sourceMetaPath, targetMetaPath);
323
+ }
302
324
  async onRestore(data) {
303
325
  const relRestorePath = data.targetPath ?? data.package.restorePath;
304
326
  (0, assert_1.ok)(relRestorePath);
@@ -27,6 +27,13 @@ export declare type InitDataType = {
27
27
  export declare type SnapshotsDataType = {
28
28
  options: Pick<SnapshotsActionOptionsType, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
29
29
  };
30
+ export declare type CopyBackupType<TRepositoryConfig> = {
31
+ options: BackupActionOptionsType;
32
+ snapshot: SnapshotType;
33
+ package: PackageConfigType;
34
+ mirrorRepositoryConfig: TRepositoryConfig;
35
+ onProgress: (data: ProgressDataType) => Promise<void>;
36
+ };
30
37
  export declare type BackupDataType<TPackageConfig> = {
31
38
  options: BackupActionOptionsType;
32
39
  snapshot: SnapshotType;
@@ -75,6 +82,7 @@ export declare abstract class RepositoryAbstract<TConfig> {
75
82
  abstract onInit(data: InitDataType): Promise<void>;
76
83
  abstract onPrune(data: PruneDataType): Promise<void>;
77
84
  abstract onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
85
+ abstract onCopyBackup(data: CopyBackupType<TConfig>): Promise<void>;
78
86
  abstract onBackup(data: BackupDataType<unknown>): Promise<void>;
79
87
  abstract onRestore(data: RestoreDataType<unknown>): Promise<void>;
80
88
  }
@@ -1,5 +1,5 @@
1
1
  import { RepositoryType } from "../util/ResticUtil";
2
- import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType } from "./RepositoryAbstract";
2
+ import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  export declare type ResticRepositoryConfigType = {
5
5
  password: string | {
@@ -36,5 +36,6 @@ export declare class ResticRepository extends RepositoryAbstract<ResticRepositor
36
36
  onSnapshots(data: SnapshotsDataType): Promise<SnapshotResultType[]>;
37
37
  onPrune(data: PruneDataType): Promise<void>;
38
38
  onBackup(data: BackupDataType<ResticPackageRepositoryConfigType>): Promise<void>;
39
+ onCopyBackup(data: CopyBackupType<ResticRepositoryConfigType>): Promise<void>;
39
40
  onRestore(data: RestoreDataType<ResticPackageRepositoryConfigType>): Promise<void>;
40
41
  }
@@ -271,6 +271,30 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
271
271
  percent: 100,
272
272
  });
273
273
  }
274
+ async onCopyBackup(data) {
275
+ const config = data.mirrorRepositoryConfig;
276
+ const [snapshot] = await this.onSnapshots({
277
+ options: {
278
+ ids: [data.snapshot.id],
279
+ packageNames: [data.package.name],
280
+ },
281
+ });
282
+ if (!snapshot)
283
+ throw new AppError_1.AppError(`Snapshot not found`);
284
+ const restic = new ResticUtil_1.ResticUtil({
285
+ env: {
286
+ ...(await this.buildEnv()),
287
+ ...(typeof config.password === "string"
288
+ ? { RESTIC_PASSWORD2: config.password }
289
+ : { RESTIC_PASSWORD_FILE2: (0, path_1.resolve)(config.password.path) }),
290
+ RESTIC_REPOSITORY2: await ResticUtil_1.ResticUtil.formatRepository(config.repository),
291
+ },
292
+ log: data.options.verbose,
293
+ });
294
+ await restic.copy({
295
+ id: snapshot.originalId,
296
+ });
297
+ }
274
298
  async onRestore(data) {
275
299
  const restorePath = data.targetPath ?? data.package.restorePath;
276
300
  (0, assert_1.ok)(restorePath);
@@ -137,7 +137,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
137
137
  const restorePath = data.package.restorePath;
138
138
  (0, assert_1.ok)(typeof restorePath === "string");
139
139
  await (0, fs_util_1.mkdirIfNotExists)(restorePath);
140
- const files = await (0, promises_1.readdir)(restorePath);
140
+ const files = await (0, fs_util_1.readDir)(restorePath);
141
141
  for (const file of files) {
142
142
  if (file.startsWith("ib_logfile")) {
143
143
  const filePath = (0, path_1.join)(restorePath, file);
package/Task/MssqlTask.js CHANGED
@@ -84,7 +84,7 @@ class MssqlTask extends TaskAbstract_1.TaskAbstract {
84
84
  const restorePath = data.package.restorePath;
85
85
  (0, assert_1.ok)(typeof restorePath === "string");
86
86
  await (0, fs_util_1.mkdirIfNotExists)(restorePath);
87
- const files = await (0, promises_1.readdir)(restorePath);
87
+ const files = await (0, fs_util_1.readDir)(restorePath);
88
88
  for (const file of files) {
89
89
  if (!file.endsWith(MssqlTask.SUFFIX))
90
90
  continue;
@@ -9,6 +9,7 @@ export declare class MysqlDumpTask extends SqlDumpTaskAbstract<MysqlDumpTaskConf
9
9
  onCreateDatabase(database: TargetDatabaseType): Promise<void>;
10
10
  onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
11
11
  onFetchTableNames(database: string): Promise<string[]>;
12
- onExport(tableNames: string[], output: string): Promise<void>;
12
+ onExportTables(tableNames: string[], output: string): Promise<void>;
13
+ onExportStoredPrograms(output: string): Promise<void>;
13
14
  onImport(path: string, database: string): Promise<void>;
14
15
  }
@@ -68,7 +68,7 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
68
68
  table_schema = '${database}'
69
69
  `);
70
70
  }
71
- async onExport(tableNames, output) {
71
+ async onExportTables(tableNames, output) {
72
72
  const stream = (0, fs_1.createWriteStream)(output);
73
73
  await Promise.all([
74
74
  new Promise((resolve, reject) => {
@@ -107,6 +107,36 @@ class MysqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
107
107
  if (!successFooter)
108
108
  throw new AppError_1.AppError("No end line found (incomplete backup)");
109
109
  }
110
+ async onExportStoredPrograms(output) {
111
+ const stream = (0, fs_1.createWriteStream)(output);
112
+ await Promise.all([
113
+ new Promise((resolve, reject) => {
114
+ stream.on("close", resolve);
115
+ stream.on("error", reject);
116
+ }),
117
+ await (0, process_util_1.exec)("mysqldump", [
118
+ ...(await this.buildConnectionArgs()),
119
+ "--lock-tables=false",
120
+ "--routines",
121
+ "--events",
122
+ "--skip-triggers",
123
+ "--no-create-info",
124
+ "--no-data",
125
+ "--no-create-db",
126
+ "--skip-opt",
127
+ ], null, {
128
+ pipe: { stream: stream },
129
+ log: {
130
+ exec: this.verbose,
131
+ stderr: this.verbose,
132
+ allToStderr: true,
133
+ },
134
+ stderr: {
135
+ toExitCode: true,
136
+ },
137
+ }),
138
+ ]);
139
+ }
110
140
  async onImport(path, database) {
111
141
  await (0, process_util_1.exec)("mysql", [...(await this.buildConnectionArgs(false)), database], null, {
112
142
  pipe: {
@@ -9,6 +9,7 @@ export declare class PostgresqlDumpTask extends SqlDumpTaskAbstract<PostgresqlDu
9
9
  onCreateDatabase(database: TargetDatabaseType): Promise<void>;
10
10
  onExecQuery(query: string): Promise<import("../util/process-util").ExecResultType>;
11
11
  onFetchTableNames(database: string): Promise<string[]>;
12
- onExport(tableNames: string[], output: string): Promise<void>;
12
+ onExportTables(tableNames: string[], output: string): Promise<void>;
13
+ onExportStoredPrograms(): Promise<void>;
13
14
  onImport(path: string, database: string): Promise<void>;
14
15
  }
@@ -71,7 +71,7 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
71
71
  table_schema NOT IN ('pg_catalog', 'information_schema')
72
72
  `);
73
73
  }
74
- async onExport(tableNames, output) {
74
+ async onExportTables(tableNames, output) {
75
75
  const stream = (0, fs_1.createWriteStream)(output);
76
76
  await Promise.all([
77
77
  new Promise((resolve, reject) => {
@@ -90,6 +90,9 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
90
90
  }),
91
91
  ]);
92
92
  }
93
+ async onExportStoredPrograms() {
94
+ throw new Error(`Method not implemented: onExportStoredPrograms`);
95
+ }
93
96
  async onImport(path, database) {
94
97
  await (0, process_util_1.exec)("psql", [...(await this.buildConnectionArgs(database)), "-f", (0, path_1.normalize)(path)], undefined, {
95
98
  log: this.verbose,
@@ -14,6 +14,7 @@ export declare type SqlDumpTaskConfigType = {
14
14
  port?: number;
15
15
  database: string;
16
16
  username: string;
17
+ storedPrograms?: boolean;
17
18
  targetDatabase?: TargetDatabaseType;
18
19
  includeTables?: string[];
19
20
  excludeTables?: string[];
@@ -28,7 +29,8 @@ export declare abstract class SqlDumpTaskAbstract<TConfig extends SqlDumpTaskCon
28
29
  abstract onDatabaseIsEmpty(databaseName: string): Promise<boolean>;
29
30
  abstract onFetchTableNames(database: string): Promise<string[]>;
30
31
  abstract onExecQuery(query: string): ReturnType<typeof exec>;
31
- abstract onExport(tableNames: string[], output: string): Promise<void>;
32
+ abstract onExportTables(tableNames: string[], output: string): Promise<void>;
33
+ abstract onExportStoredPrograms(output: string): Promise<void>;
32
34
  abstract onImport(path: string, database: string): Promise<void>;
33
35
  onBackup(data: BackupDataType): Promise<void>;
34
36
  onRestore(data: RestoreDataType): Promise<void>;
@@ -44,6 +44,7 @@ exports.sqlDumpTaskDefinition = {
44
44
  collate: { type: "string" },
45
45
  },
46
46
  },
47
+ storedPrograms: { type: "boolean" },
47
48
  includeTables: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
48
49
  excludeTables: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
49
50
  oneFileByTable: { type: "boolean" },
@@ -116,7 +117,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
116
117
  await (0, promises_1.mkdir)(outputPath, { recursive: true });
117
118
  if (!this.config.oneFileByTable) {
118
119
  const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ database: this.config.database }));
119
- await this.onExport(tableNames, outPath);
120
+ await this.onExportTables(tableNames, outPath);
120
121
  }
121
122
  else {
122
123
  let current = 0;
@@ -129,9 +130,13 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
129
130
  });
130
131
  current++;
131
132
  const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ table: tableName }));
132
- await this.onExport([tableName], outPath);
133
+ await this.onExportTables([tableName], outPath);
133
134
  }
134
135
  }
136
+ if (this.config.storedPrograms) {
137
+ const outPath = (0, path_1.join)(outputPath, "stored-programs.sql");
138
+ await this.onExportStoredPrograms(outPath);
139
+ }
135
140
  }
136
141
  async onRestore(data) {
137
142
  const restorePath = data.package.restorePath;
@@ -155,7 +160,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
155
160
  database: database.name,
156
161
  });
157
162
  }
158
- const items = (await (0, promises_1.readdir)(restorePath))
163
+ const items = (await (0, fs_util_1.readDir)(restorePath))
159
164
  .map(parseSqlFile)
160
165
  .filter((v) => !!v);
161
166
  // Database check
package/cli.js CHANGED
@@ -78,9 +78,10 @@ const cwd = process.cwd();
78
78
  program.name(subname);
79
79
  program.version(version);
80
80
  program.description(description);
81
+ program.usage("dtt");
81
82
  program.option("-v,--verbose", "Verbose", (_, previous) => previous + 1, 0);
82
83
  program.option("-c,--config <path>", "Config path", process.env["DATATRUCK_CONFIG"] ?? (cwd.endsWith(path_1.sep) ? cwd : `${cwd}${path_1.sep}`));
83
- program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$)", "table");
84
+ program.option("-o,--output-format <format>", "Output format (json, pjson, yaml, table, custom=$, tpl=name)", "table");
84
85
  makeCommand(CommandFactory_1.CommandEnum.config).alias("c");
85
86
  makeCommand(CommandFactory_1.CommandEnum.init).alias("i");
86
87
  makeCommand(CommandFactory_1.CommandEnum.snapshots).alias("s");
@@ -104,7 +105,7 @@ function parseArgs(args) {
104
105
  (0, process_util_1.onExit)((eventName, error) => {
105
106
  if (eventName !== "exit") {
106
107
  process.stdout.write(cli_util_1.showCursorCommand);
107
- console.log(`\nClosing... (reason: ${eventName})`);
108
+ console.info(`\nClosing... (reason: ${eventName})`);
108
109
  if (error instanceof Error)
109
110
  console.error((0, chalk_1.red)(error.stack));
110
111
  }
@@ -20,6 +20,9 @@
20
20
  "name": {
21
21
  "type": "string"
22
22
  },
23
+ "mirrorRepoNames": {
24
+ "$ref": "#/definitions/stringlist-util"
25
+ },
23
26
  "enabled": {
24
27
  "anyOf": [
25
28
  {
@@ -713,6 +716,9 @@
713
716
  }
714
717
  }
715
718
  },
719
+ "storedPrograms": {
720
+ "type": "boolean"
721
+ },
716
722
  "includeTables": {
717
723
  "$ref": "#/definitions/stringlist-util"
718
724
  },
package/package.json CHANGED
@@ -1,29 +1,25 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.8.0",
3
+ "version": "0.11.0",
4
4
  "dependencies": {
5
5
  "ajv": "^8.11.0",
6
6
  "async": "^3.2.4",
7
7
  "chalk": "^4.1.2",
8
8
  "cli-table3": "^0.6.2",
9
- "commander": "^9.2.0",
10
- "dayjs": "^1.11.2",
9
+ "commander": "^9.4.0",
10
+ "dayjs": "^1.11.5",
11
11
  "fast-glob": "^3.2.11",
12
12
  "micromatch": "^4.0.5",
13
- "sqlite": "^4.1.1",
14
- "sqlite3": "^5.0.8"
13
+ "sqlite": "^4.1.2",
14
+ "sqlite3": "^5.0.11"
15
15
  },
16
16
  "optionalDependencies": {
17
- "ts-node": "^10.7.0",
18
- "yaml": "^2.1.0"
17
+ "ts-node": "^10.9.1",
18
+ "yaml": "^2.1.1"
19
19
  },
20
20
  "engine": {
21
21
  "node": ">=16.0.0"
22
22
  },
23
- "bin": {
24
- "datatruck": "bin.js",
25
- "dtt": "bin.js"
26
- },
27
23
  "description": "Tool for creating and managing backups",
28
24
  "homepage": "https://github.com/swordev/datatruck#readme",
29
25
  "bugs": {
@@ -38,5 +34,9 @@
38
34
  "name": "Juanra GM",
39
35
  "email": "juanrgm724@gmail.com",
40
36
  "url": "https://github.com/juanrgm"
37
+ },
38
+ "bin": {
39
+ "datatruck": "bin.js",
40
+ "dtt": "bin.js"
41
41
  }
42
42
  }
@@ -1,4 +1,4 @@
1
- export declare type FormatType = "json" | "pjson" | "table" | "yaml" | "custom";
1
+ export declare 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[];
@@ -20,5 +20,7 @@ export declare class DataFormat<TItem extends Record<string, unknown>> {
20
20
  protected formatToPrettyJson(): string;
21
21
  protected formatToYaml(): any;
22
22
  protected formatToTable(): string;
23
- format(format: FormatType): any;
23
+ format(format: FormatType, options?: {
24
+ tpl?: Record<string, () => string>;
25
+ }): any;
24
26
  }
@@ -8,6 +8,7 @@ const AppError_1 = require("../Error/AppError");
8
8
  const cli_table3_1 = __importDefault(require("cli-table3"));
9
9
  const util_1 = require("util");
10
10
  const customPrefix = "custom=";
11
+ const tplPrefix = "tpl=";
11
12
  class DataFormat {
12
13
  constructor(options) {
13
14
  this.options = options;
@@ -34,7 +35,7 @@ class DataFormat {
34
35
  table.push(this.options.table.handler(item));
35
36
  return table.toString();
36
37
  }
37
- format(format) {
38
+ format(format, options) {
38
39
  if (format === "table") {
39
40
  return this.formatToTable();
40
41
  }
@@ -51,6 +52,15 @@ class DataFormat {
51
52
  const code = format.slice(customPrefix.length);
52
53
  return runCustomCode(this.options.items, code);
53
54
  }
55
+ else if (format.startsWith(tplPrefix)) {
56
+ const name = format.slice(tplPrefix.length);
57
+ const tpl = options?.tpl || {};
58
+ if (!(name in tpl)) {
59
+ const tplNames = Object.keys(tpl).join(", ");
60
+ throw new AppError_1.AppError(`Template name not found: ${name} (valid names: ${tplNames})`);
61
+ }
62
+ return tpl[name]();
63
+ }
54
64
  else {
55
65
  throw new AppError_1.AppError(`Invalid output format: ${format}`);
56
66
  }
package/util/GitUtil.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GitUtil = void 0;
4
4
  const fs_util_1 = require("./fs-util");
5
5
  const process_util_1 = require("./process-util");
6
- const promises_1 = require("fs/promises");
7
6
  class GitUtil {
8
7
  constructor(options) {
9
8
  this.options = options;
@@ -16,7 +15,7 @@ class GitUtil {
16
15
  }
17
16
  async canBeInit(repo) {
18
17
  return ((0, fs_util_1.isLocalDir)(repo) &&
19
- (!(await (0, fs_util_1.checkDir)(repo)) || !(await (0, promises_1.readdir)(repo)).length));
18
+ (!(await (0, fs_util_1.checkDir)(repo)) || !(await (0, fs_util_1.readDir)(repo)).length));
20
19
  }
21
20
  async clone(options) {
22
21
  return await this.exec([
@@ -86,6 +86,10 @@ export declare class ResticUtil {
86
86
  allowEmptySnapshot?: boolean;
87
87
  onStream?: (data: BackupStreamType) => void;
88
88
  }): Promise<ExecResultType>;
89
+ copy(options: {
90
+ id: string;
91
+ onStream?: (data: BackupStreamType) => Promise<void>;
92
+ }): Promise<ExecResultType>;
89
93
  restore(options: {
90
94
  id: string;
91
95
  target: string;
@@ -154,6 +154,22 @@ class ResticUtil {
154
154
  throw error;
155
155
  }
156
156
  }
157
+ async copy(options) {
158
+ return await this.exec(["copy", "--json", options.id], {
159
+ stderr: {
160
+ toExitCode: true,
161
+ },
162
+ stdout: {
163
+ ...(options.onStream && {
164
+ onData: async (data) => {
165
+ if (data.startsWith("{") && data.endsWith("}")) {
166
+ await options.onStream?.(JSON.parse(data));
167
+ }
168
+ },
169
+ }),
170
+ },
171
+ });
172
+ }
157
173
  async restore(options) {
158
174
  return await this.exec(["restore", "--json", options.id, "--target", options.target], {
159
175
  stderr: {
package/util/cli-util.js CHANGED
@@ -32,11 +32,11 @@ function logVars(data) {
32
32
  let first = true;
33
33
  for (const key in data) {
34
34
  if (first) {
35
- console.log();
35
+ console.info();
36
36
  first = false;
37
37
  }
38
38
  const value = data[key];
39
- console.log(`${chalk_1.default.cyan(key)}${chalk_1.default.grey(":")} ${chalk_1.default.white(value ?? "")}`);
39
+ console.info(`${chalk_1.default.cyan(key)}${chalk_1.default.grey(":")} ${chalk_1.default.white(value ?? "")}`);
40
40
  }
41
41
  }
42
42
  exports.logVars = logVars;
@@ -12,5 +12,5 @@ export declare function filterByLast<TItem extends {
12
12
  }>(items: TItem[], options: FilterByLastOptionsType, reasons?: Record<number, string[]>): TItem[];
13
13
  export declare function createChron(): {
14
14
  start: () => number;
15
- elapsed: (formatted?: boolean | undefined) => string | number;
15
+ elapsed: (formatted?: boolean) => string | number;
16
16
  };
@@ -1,4 +1,4 @@
1
1
  export declare function makeTableSelector<T>(tableName: string): {
2
- (name?: keyof T | undefined): string;
2
+ (name?: keyof T): string;
3
3
  toString: any;
4
4
  };
package/util/fs-util.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { Stats } from "fs";
2
5
  import { Interface } from "readline";
6
+ export declare const isWSLSystem: boolean;
3
7
  export declare function isLocalDir(path: string): boolean;
4
8
  export declare function isDirEmpty(path: string): Promise<boolean>;
5
9
  export declare function mkdirIfNotExists(path: string): Promise<string>;
@@ -23,6 +27,7 @@ export declare function mkTmpDir(prefix: string, id?: string): Promise<string>;
23
27
  export declare function readPartialFile(path: string, positions: [number, number?]): Promise<string>;
24
28
  export declare function checkFile(path: string): Promise<boolean>;
25
29
  export declare function checkDir(path: string): Promise<boolean>;
30
+ export declare function readDir(path: string): Promise<string[]>;
26
31
  export declare function forEachFile(dirPath: string, cb: (path: string, dir: boolean) => void, includeDir?: boolean): Promise<void>;
27
32
  export declare function writeGitIgnoreList(options: {
28
33
  paths: NodeJS.ReadableStream | string[];
@@ -45,6 +50,8 @@ export declare function writePathLists(options: {
45
50
  multipleStats: Record<string, number>;
46
51
  };
47
52
  }>;
53
+ export declare function copyFileWithStreams(source: string, target: string): Promise<unknown>;
54
+ export declare function updateFileStats(path: string, fileInfo: Stats): Promise<void>;
48
55
  export declare function cpy(options: {
49
56
  input: {
50
57
  type: "glob";
package/util/fs-util.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cpy = exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = void 0;
6
+ exports.cpy = exports.updateFileStats = exports.copyFileWithStreams = exports.writePathLists = exports.writeGitIgnoreList = exports.forEachFile = exports.readDir = exports.checkDir = exports.checkFile = exports.readPartialFile = exports.mkTmpDir = exports.tmpDir = exports.sessionTmpDir = exports.parentTmpDir = exports.existsFile = exports.findFile = exports.parsePackageFile = exports.parseFile = exports.parseFileExtensions = exports.readdirIfExists = exports.writeJSONFile = exports.existsDir = exports.ensureEmptyDir = exports.mkdirIfNotExists = exports.isDirEmpty = exports.isLocalDir = exports.isWSLSystem = void 0;
7
7
  const globalData_1 = __importDefault(require("../globalData"));
8
8
  const path_util_1 = require("./path-util");
9
9
  const async_1 = require("async");
@@ -13,15 +13,17 @@ const fs_1 = require("fs");
13
13
  const fs_2 = require("fs");
14
14
  const promises_1 = require("fs/promises");
15
15
  const micromatch_1 = require("micromatch");
16
+ const os_1 = require("os");
16
17
  const path_1 = require("path");
17
18
  const path_2 = require("path");
18
19
  const readline_1 = require("readline");
20
+ exports.isWSLSystem = (0, os_1.release)().includes("microsoft-standard-WSL");
19
21
  function isLocalDir(path) {
20
22
  return /^[\/\.]|([A-Z]:)/i.test(path);
21
23
  }
22
24
  exports.isLocalDir = isLocalDir;
23
25
  async function isDirEmpty(path) {
24
- const files = await (0, promises_1.readdir)(path);
26
+ const files = await readDir(path);
25
27
  return !files.length;
26
28
  }
27
29
  exports.isDirEmpty = isDirEmpty;
@@ -57,7 +59,7 @@ exports.writeJSONFile = writeJSONFile;
57
59
  async function readdirIfExists(path) {
58
60
  if (!(await existsDir(path)))
59
61
  return [];
60
- return await (0, promises_1.readdir)(path);
62
+ return await readDir(path);
61
63
  }
62
64
  exports.readdirIfExists = readdirIfExists;
63
65
  exports.parseFileExtensions = ["json", "js", "ts", "yaml", "yml"];
@@ -179,8 +181,25 @@ async function checkDir(path) {
179
181
  }
180
182
  }
181
183
  exports.checkDir = checkDir;
184
+ async function readDir(path) {
185
+ try {
186
+ return await (0, promises_1.readdir)(path);
187
+ }
188
+ catch (anyError) {
189
+ const nodeError = anyError;
190
+ if (nodeError.code === "ENOENT") {
191
+ const error = new Error(nodeError.message);
192
+ error.code = nodeError.code;
193
+ error.errno = nodeError.errno;
194
+ error.path = nodeError.path;
195
+ throw error;
196
+ }
197
+ throw anyError;
198
+ }
199
+ }
200
+ exports.readDir = readDir;
182
201
  async function forEachFile(dirPath, cb, includeDir) {
183
- const files = await (0, promises_1.readdir)(dirPath);
202
+ const files = await readDir(dirPath);
184
203
  for (const file of files) {
185
204
  const filePath = (0, path_1.join)(dirPath, file);
186
205
  if ((await (0, promises_1.stat)(filePath)).isDirectory()) {
@@ -315,6 +334,30 @@ async function writePathLists(options) {
315
334
  };
316
335
  }
317
336
  exports.writePathLists = writePathLists;
337
+ async function copyFileWithStreams(source, target) {
338
+ const r = (0, fs_1.createReadStream)(source);
339
+ const w = (0, fs_2.createWriteStream)(target);
340
+ try {
341
+ return await new Promise((resolve, reject) => {
342
+ r.on("error", reject);
343
+ w.on("error", reject);
344
+ w.on("finish", resolve);
345
+ r.pipe(w);
346
+ });
347
+ }
348
+ catch (error) {
349
+ r.destroy();
350
+ w.end();
351
+ throw error;
352
+ }
353
+ }
354
+ exports.copyFileWithStreams = copyFileWithStreams;
355
+ async function updateFileStats(path, fileInfo) {
356
+ await (0, promises_1.utimes)(path, fileInfo.atime, fileInfo.mtime);
357
+ await (0, promises_1.chmod)(path, fileInfo.mode);
358
+ await (0, promises_1.chown)(path, fileInfo.uid, fileInfo.gid);
359
+ }
360
+ exports.updateFileStats = updateFileStats;
318
361
  async function cpy(options) {
319
362
  const stats = { paths: 0, files: 0, dirs: 0 };
320
363
  const dirs = new Set();
@@ -350,7 +393,19 @@ async function cpy(options) {
350
393
  const dir = (0, path_1.dirname)(entryTargetPath);
351
394
  await makeRecursiveDir(dir);
352
395
  stats.files++;
353
- await (0, promises_1.cp)(entrySourcePath, entryTargetPath);
396
+ // https://github.com/nodejs/node/issues/44261
397
+ if (exports.isWSLSystem) {
398
+ const fileInfo = await (0, promises_1.stat)(entryTargetPath);
399
+ const isWritable = (fileInfo.mode & 0o200) === 0o200;
400
+ if (!isWritable) {
401
+ await copyFileWithStreams(entrySourcePath, entryTargetPath);
402
+ await updateFileStats(entryTargetPath, fileInfo);
403
+ return;
404
+ }
405
+ }
406
+ await (0, promises_1.cp)(entrySourcePath, entryTargetPath, {
407
+ preserveTimestamps: true,
408
+ });
354
409
  }
355
410
  };
356
411
  const { input } = options;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { SpawnOptions, ChildProcess } from "child_process";
3
4
  import { ReadStream, WriteStream } from "fs";
4
5
  export declare type ExecLogSettingsType = {
package/CHANGELOG.md DELETED
@@ -1,145 +0,0 @@
1
- # @datatruck/cli
2
-
3
- ## 0.8.0
4
-
5
- ### Minor Changes
6
-
7
- - [`8c421ab`](https://github.com/swordev/datatruck/commit/8c421ab0adb6f2d5bc81e91fa387c5daa848f411) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `--package-task` option to snapshot command
8
-
9
- ## 0.7.0
10
-
11
- ### Minor Changes
12
-
13
- - [`3b8d6da`](https://github.com/swordev/datatruck/commit/3b8d6da01495799aceb848a63b35b8c46a7d1b0e) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `--package-task` cli option
14
-
15
- * [`69b34a0`](https://github.com/swordev/datatruck/commit/69b34a02b9cade48df2b071a92a8f79d5cfec23e) Thanks [@juanrgm](https://github.com/juanrgm)! - Allow restore multiple backups over the same database
16
-
17
- - [`69caf26`](https://github.com/swordev/datatruck/commit/69caf26881272331bd4c8d7d345b3b85d33e33ac) Thanks [@juanrgm](https://github.com/juanrgm)! - Add cli short option to `--tag`
18
-
19
- * [`377f0de`](https://github.com/swordev/datatruck/commit/377f0de345c9c8f45c772ac47e4ded81e91725d7) Thanks [@juanrgm](https://github.com/juanrgm)! - Rename cli short option to `-rt`
20
-
21
- ### Patch Changes
22
-
23
- - [`c03200a`](https://github.com/swordev/datatruck/commit/c03200a6347d1e9f9fdad86dcb22df30bbefcab4) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix `sql-dump` tasks
24
-
25
- * [`f56a4bc`](https://github.com/swordev/datatruck/commit/f56a4bcb429a674c13f32de73985cd67eb1acc23) Thanks [@juanrgm](https://github.com/juanrgm)! - Show full error message
26
-
27
- - [`4324422`](https://github.com/swordev/datatruck/commit/4324422550474619811a8d455af55bc6e3b08aeb) Thanks [@juanrgm](https://github.com/juanrgm)! - Use connection port in `mysql-dump` task
28
-
29
- ## 0.6.1
30
-
31
- ### Patch Changes
32
-
33
- - [`0ba6229`](https://github.com/swordev/datatruck/commit/0ba6229348c109a59783e72242ab7c0e61f25e36) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix progress bar in restic repository
34
-
35
- ## 0.6.0
36
-
37
- ### Minor Changes
38
-
39
- - [`0c6877d`](https://github.com/swordev/datatruck/commit/0c6877d189761e75dd434b0a8d72b71621d024de) Thanks [@juanrgm](https://github.com/juanrgm)! - Show more progress stats
40
-
41
- * [`751e1f6`](https://github.com/swordev/datatruck/commit/751e1f6d6b33d3fa96eb40d998fdd140ce0e3875) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `fileCopyConcurrency` option
42
-
43
- - [`05487e6`](https://github.com/swordev/datatruck/commit/05487e6a33f875a3afb7ff0815b16da6f2a41301) Thanks [@juanrgm](https://github.com/juanrgm)! - Parse InnoDB error in `MariadbTask` to avoid infinite wait
44
-
45
- ### Patch Changes
46
-
47
- - [`b62a6f8`](https://github.com/swordev/datatruck/commit/b62a6f8a82409339afd65d4f96476eb57bbfb5a2) Thanks [@juanrgm](https://github.com/juanrgm)! - Resolve target/restore path in local repository
48
-
49
- ## 0.5.0
50
-
51
- ### Minor Changes
52
-
53
- - [`5aeb2af`](https://github.com/swordev/datatruck/commit/5aeb2afb96692e00bdba501b58df9cc0e02dceaa) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `enabled` option to repository config
54
-
55
- * [`75de836`](https://github.com/swordev/datatruck/commit/75de8369356cf02ed3fd5c58b1f9bea66432cda8) Thanks [@juanrgm](https://github.com/juanrgm)! - Allow restic password without file
56
-
57
- ## 0.4.0
58
-
59
- ### Minor Changes
60
-
61
- - [`eeb00a6`](https://github.com/swordev/datatruck/commit/eeb00a69d75c91da40711ae79475612b1d5193b6) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `tempDir` config option
62
-
63
- ## 0.3.2
64
-
65
- ### Patch Changes
66
-
67
- - [`8957c3b`](https://github.com/swordev/datatruck/commit/8957c3b5846606db8b825fef357445210f2a3ac3) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix restic progress parser
68
-
69
- * [`2989718`](https://github.com/swordev/datatruck/commit/29897185e3d6659359d51ab2212351005137f86c) Thanks [@juanrgm](https://github.com/juanrgm)! - Show closing reason
70
-
71
- - [`b9e0843`](https://github.com/swordev/datatruck/commit/b9e0843c7970944cfd30a7d2a543f515adfa60e4) Thanks [@juanrgm](https://github.com/juanrgm)! - Show restic progress in megabytes
72
-
73
- ## 0.3.1
74
-
75
- ### Patch Changes
76
-
77
- - [`c3bb4c6`](https://github.com/swordev/datatruck/commit/c3bb4c609887c5525cf35487ea237750addb6e75) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix restic stdout parser
78
-
79
- ## 0.3.0
80
-
81
- ### Minor Changes
82
-
83
- - [`d63fd25`](https://github.com/swordev/datatruck/commit/d63fd25ffa8d2e539d2125dfd6a3f55020086804) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `snapshotDate` param
84
-
85
- * [`486ef4a`](https://github.com/swordev/datatruck/commit/486ef4add27ae1dbfd166b16c257522f43537ecd) Thanks [@juanrgm](https://github.com/juanrgm)! - Resolve params in `include` and `exclude`
86
-
87
- - [`617dae2`](https://github.com/swordev/datatruck/commit/617dae2c8ed90e6e65e8109f03cfad0e64bd7c02) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `script` task
88
-
89
- ### Patch Changes
90
-
91
- - [`d1b3ea9`](https://github.com/swordev/datatruck/commit/d1b3ea9c9540d30898c00490963523a4fbc68193) Thanks [@juanrgm](https://github.com/juanrgm)! - Avoid use gitignore if is not necessary in restic repository
92
-
93
- ## 0.2.0
94
-
95
- ### Minor Changes
96
-
97
- - [`120460c`](https://github.com/swordev/datatruck/commit/120460c8824cef4184e43f571a4cc0798b899b66) Thanks [@juanrgm](https://github.com/juanrgm)! - Enable `include` option in restic repository
98
-
99
- ### Patch Changes
100
-
101
- - [`e30ede3`](https://github.com/swordev/datatruck/commit/e30ede371bc7ab3fc1cd47758fdac7a28e8e2705) Thanks [@juanrgm](https://github.com/juanrgm)! - Resolve `RESTIC_PASSWORD_FILE` path
102
-
103
- * [`8539d28`](https://github.com/swordev/datatruck/commit/8539d285b2c51d700aa811cd772d573fa0d613eb) Thanks [@juanrgm](https://github.com/juanrgm)! - Allow empty backup in restic repository
104
-
105
- ## 0.1.0
106
-
107
- ### Minor Changes
108
-
109
- - [`88d46cd`](https://github.com/swordev/datatruck/commit/88d46cd56293df4c6fc21a9ad61d6236ac91f325) Thanks [@juanrgm](https://github.com/juanrgm)! - Add `custom` output format
110
-
111
- ### Patch Changes
112
-
113
- - [`24a1e5e`](https://github.com/swordev/datatruck/commit/24a1e5e86336e7a92556287e49548dc542f0e579) Thanks [@juanrgm](https://github.com/juanrgm)! - Update dependencies
114
-
115
- ## 0.0.6
116
-
117
- ### Patch Changes
118
-
119
- - [`8de6e6c`](https://github.com/swordev/datatruck/commit/8de6e6ceddb59635cb4634d884e7690eeaf59bac) Thanks [@juanrgm](https://github.com/juanrgm)! - Publish migrations
120
-
121
- ## 0.0.5
122
-
123
- ### Patch Changes
124
-
125
- - [`78cb0c1`](https://github.com/swordev/datatruck/commit/78cb0c17558543841cd7080dc4c672e6cbfd5634) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix docker image
126
-
127
- ## 0.0.4
128
-
129
- ### Patch Changes
130
-
131
- - [`d9e534b`](https://github.com/swordev/datatruck/commit/d9e534bd968acf9cd1c93f20e6152c004cb1f23b) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix package file read
132
-
133
- * [`b882c58`](https://github.com/swordev/datatruck/commit/b882c58183e9a75abc876645e18d7b67186dd662) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix read of migrations
134
-
135
- ## 0.0.3
136
-
137
- ### Patch Changes
138
-
139
- - [`051a7da`](https://github.com/swordev/datatruck/commit/051a7da225fcfea1c30a4fbfa8aea1b8f5538367) Thanks [@juanrgm](https://github.com/juanrgm)! - Fix dist files
140
-
141
- ## 0.0.2
142
-
143
- ### Patch Changes
144
-
145
- - [`0911351`](https://github.com/swordev/datatruck/commit/09113517e1a77f2d2a1e19e4c3d9af7da1e28415) Thanks [@juanrgm](https://github.com/juanrgm)! - Publish docker image