-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.ts
41 lines (38 loc) · 1.24 KB
/
backup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Command } from "commander";
import { mongoDbBackup } from "./services/mongodb";
import { mysqlBackup } from "./services/mysql";
import { postgresBackup } from "./services/postgresql";
const program = new Command();
program
.command("backup")
.description("Backup a database")
.requiredOption(
"-dt, --db-type <type>",
"Database type (postgres, mysql, mongodb)"
)
.requiredOption("-h, --host <host>", "Database host")
.requiredOption("-p, --port <port>", "Database port")
.requiredOption("-u, --user <user>", "Database user")
.requiredOption("-ps, --password <password>", "Database password")
.requiredOption("-d, --database <name>", "Database name")
.action(async (options) => {
try {
const { dbType, host, port, user, password, database } = options;
switch (dbType) {
case "postgres":
await postgresBackup(options);
break;
case "mysql":
await mysqlBackup(options);
break;
case "mongodb":
await mongoDbBackup(options);
break;
default:
console.error("Unsupported database type");
}
} catch (error: any) {
console.error("Backup failed:", error.message);
}
});
program.parse(process.argv);