@datatruck/cli 0.34.5 → 0.35.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.
@@ -399,6 +399,63 @@
399
399
  "name"
400
400
  ]
401
401
  },
402
+ {
403
+ "type": "object",
404
+ "properties": {
405
+ "name": {
406
+ "type": "string",
407
+ "const": "mongo-dump"
408
+ },
409
+ "config": {
410
+ "type": "object",
411
+ "properties": {
412
+ "command": {
413
+ "type": "string"
414
+ },
415
+ "hostname": {
416
+ "type": "string"
417
+ },
418
+ "port": {
419
+ "type": "number"
420
+ },
421
+ "username": {
422
+ "type": "string"
423
+ },
424
+ "password": {
425
+ "anyOf": [
426
+ {
427
+ "type": "object",
428
+ "properties": {
429
+ "path": {
430
+ "type": "string"
431
+ }
432
+ },
433
+ "additionalProperties": false,
434
+ "required": [
435
+ "path"
436
+ ]
437
+ },
438
+ {
439
+ "type": "string"
440
+ }
441
+ ]
442
+ },
443
+ "compress": {
444
+ "type": "boolean"
445
+ },
446
+ "concurrency": {
447
+ "type": "number"
448
+ }
449
+ },
450
+ "additionalProperties": false
451
+ }
452
+ },
453
+ "additionalProperties": false,
454
+ "required": [
455
+ "config",
456
+ "name"
457
+ ]
458
+ },
402
459
  {
403
460
  "type": "object",
404
461
  "properties": {
@@ -0,0 +1,21 @@
1
+ import { TaskBackupData, TaskRestoreData, TaskAbstract } from "./TaskAbstract";
2
+ export type MongoDumpTaskConfig = {
3
+ command?: string;
4
+ hostname?: string;
5
+ port?: number;
6
+ username?: string;
7
+ password?: string | {
8
+ path: string;
9
+ };
10
+ compress?: boolean;
11
+ concurrency?: number;
12
+ };
13
+ export declare const mongodumpTaskName = "mongo-dump";
14
+ export declare class MongoDumpTask extends TaskAbstract<MongoDumpTaskConfig> {
15
+ protected verbose?: boolean;
16
+ private get command();
17
+ backup(data: TaskBackupData): Promise<{
18
+ snapshotPath: string;
19
+ }>;
20
+ restore(data: TaskRestoreData): Promise<void>;
21
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoDumpTask = exports.mongodumpTaskName = void 0;
4
+ const async_process_1 = require("../utils/async-process");
5
+ const fs_1 = require("../utils/fs");
6
+ const temp_1 = require("../utils/temp");
7
+ const TaskAbstract_1 = require("./TaskAbstract");
8
+ exports.mongodumpTaskName = "mongo-dump";
9
+ class MongoDumpTask extends TaskAbstract_1.TaskAbstract {
10
+ verbose;
11
+ get command() {
12
+ return this.config.command ?? "mongodump";
13
+ }
14
+ async backup(data) {
15
+ this.verbose = data.options.verbose;
16
+ const snapshotPath = data.package.path ??
17
+ (await (0, temp_1.mkTmpDir)(exports.mongodumpTaskName, "task", "backup", "snapshot"));
18
+ await (0, fs_1.mkdirIfNotExists)(snapshotPath);
19
+ await (0, fs_1.ensureEmptyDir)(snapshotPath);
20
+ const p = new async_process_1.AsyncProcess(this.command, [
21
+ ...(this.config.hostname ? ["/h", this.config.hostname] : []),
22
+ ...(this.config.port ? ["/p", this.config.port] : []),
23
+ ...(this.config.username ? ["/u", this.config.username] : []),
24
+ ...(this.config.compress ? ["/gzip"] : []),
25
+ ...(this.config.concurrency ? ["/j", this.config.concurrency] : []),
26
+ "/o",
27
+ snapshotPath,
28
+ ], {
29
+ $log: this.verbose,
30
+ });
31
+ const password = this.config.password !== undefined
32
+ ? (await (0, fs_1.fetchData)(this.config.password, (p) => p.path)) ?? ""
33
+ : "";
34
+ p.stdin.writable.write(`${password}\n`);
35
+ await p.stderr.parseLines((line) => {
36
+ data.onProgress({
37
+ absolute: {
38
+ description: line.slice(0, 255),
39
+ },
40
+ });
41
+ });
42
+ return { snapshotPath };
43
+ }
44
+ async restore(data) {
45
+ throw new Error("Not implemented");
46
+ }
47
+ }
48
+ exports.MongoDumpTask = MongoDumpTask;
@@ -64,14 +64,26 @@ class PostgresqlDumpTask extends SqlDumpTaskAbstract_1.SqlDumpTaskAbstract {
64
64
  const dumpProcess = new async_process_1.AsyncProcess("pg_dump", [
65
65
  ...(await this.buildConnectionArgs(this.config.database)),
66
66
  ...(tableNames?.flatMap((v) => ["-t", v]) ?? []),
67
- ], { $log: this.verbose });
67
+ ], {
68
+ $log: {
69
+ exec: this.verbose,
70
+ stderr: this.verbose,
71
+ allToStderr: true,
72
+ },
73
+ });
68
74
  await dumpProcess.stdout.pipe(output, onProgress);
69
75
  }
70
76
  async onExportStoredPrograms() {
71
77
  throw new Error(`Method not implemented: onExportStoredPrograms`);
72
78
  }
73
79
  async onImport(path, database) {
74
- await async_process_1.AsyncProcess.exec("psql", [...(await this.buildConnectionArgs(database)), "-f", (0, path_1.normalize)(path)], { $log: this.verbose });
80
+ await async_process_1.AsyncProcess.exec("psql", [...(await this.buildConnectionArgs(database)), "-f", (0, path_1.normalize)(path)], {
81
+ $log: {
82
+ exec: this.verbose,
83
+ stderr: this.verbose,
84
+ allToStderr: true,
85
+ },
86
+ });
75
87
  }
76
88
  }
77
89
  exports.PostgresqlDumpTask = PostgresqlDumpTask;
@@ -1,5 +1,6 @@
1
1
  import type { GitTaskConfig, gitTaskName } from "../../tasks/GitTask";
2
2
  import type { MariadbTaskConfig, mariadbTaskName } from "../../tasks/MariadbTask";
3
+ import { MongoDumpTaskConfig, mongodumpTaskName } from "../../tasks/MongoDumpTask";
3
4
  import type { MssqlTaskConfig, mssqlTaskName } from "../../tasks/MssqlTask";
4
5
  import type { MysqlDumpTaskConfig, mysqlDumpTaskName } from "../../tasks/MysqlDumpTask";
5
6
  import type { PostgresqlDumpTaskConfig, postgresqlDumpTaskName } from "../../tasks/PostgresqlDumpTask";
@@ -24,8 +25,12 @@ export type PostgresqlDumpTaskConfigItem = {
24
25
  name: typeof postgresqlDumpTaskName;
25
26
  config: PostgresqlDumpTaskConfig;
26
27
  };
28
+ export type MongodumpTaskConfigItem = {
29
+ name: typeof mongodumpTaskName;
30
+ config: MongoDumpTaskConfig;
31
+ };
27
32
  export type ScriptTaskConfigItem = {
28
33
  name: typeof scriptTaskName;
29
34
  config: ScriptTaskConfig;
30
35
  };
31
- export type TaskConfig = GitTaskConfigItem | MariadbTaskConfigItem | MssqlTaskConfigItem | MysqlDumpTaskConfigItem | PostgresqlDumpTaskConfigItem | ScriptTaskConfigItem;
36
+ export type TaskConfig = GitTaskConfigItem | MariadbTaskConfigItem | MssqlTaskConfigItem | MysqlDumpTaskConfigItem | PostgresqlDumpTaskConfigItem | MongodumpTaskConfigItem | ScriptTaskConfigItem;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTask = void 0;
4
4
  const GitTask_1 = require("../../tasks/GitTask");
5
5
  const MariadbTask_1 = require("../../tasks/MariadbTask");
6
+ const MongoDumpTask_1 = require("../../tasks/MongoDumpTask");
6
7
  const MssqlTask_1 = require("../../tasks/MssqlTask");
7
8
  const MysqlDumpTask_1 = require("../../tasks/MysqlDumpTask");
8
9
  const PostgresqlDumpTask_1 = require("../../tasks/PostgresqlDumpTask");
@@ -24,6 +25,9 @@ function createTask(task) {
24
25
  else if (task.name === MssqlTask_1.mssqlTaskName) {
25
26
  return new MssqlTask_1.MssqlTask(task.config ?? {});
26
27
  }
28
+ else if (task.name === MongoDumpTask_1.mongodumpTaskName) {
29
+ return new MongoDumpTask_1.MongoDumpTask(task.config ?? {});
30
+ }
27
31
  else if (task.name === ScriptTask_1.scriptTaskName) {
28
32
  return new ScriptTask_1.ScriptTask(task.config ?? {});
29
33
  }
@@ -62,8 +62,9 @@ async function createMysqlCli(options) {
62
62
  `user = "${options.username}"`,
63
63
  `password = "${password}"`,
64
64
  ];
65
- await (0, promises_1.writeFile)((sqlConfigPath = (0, path_1.join)(dir, "mysql.conf")), data.join("\n"));
66
- return sqlConfigPath;
65
+ const path = (0, path_1.join)(dir, "mysql.conf");
66
+ await (0, promises_1.writeFile)(path, data.join("\n"));
67
+ return (sqlConfigPath = path);
67
68
  }
68
69
  async function args() {
69
70
  return [`--defaults-file=${await createSqlConfig()}`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.34.5",
3
+ "version": "0.35.0",
4
4
  "description": "Tool for creating and managing backups",
5
5
  "homepage": "https://github.com/swordev/datatruck#readme",
6
6
  "bugs": {