@catladder/cli 1.73.0 → 1.75.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.
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js +59 -33
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js.map +1 -1
- package/dist/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/cli/commands/cloudSQL/commandRestoreDb.ts +38 -16
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=12.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@catladder/pipeline": "1.
|
|
27
|
+
"@catladder/pipeline": "1.75.0",
|
|
28
28
|
"@kubernetes/client-node": "^0.16.2",
|
|
29
29
|
"@tsconfig/node14": "^1.0.1",
|
|
30
30
|
"@types/common-tags": "^1.8.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"typescript": "^4.5.4",
|
|
58
58
|
"vorpal": "^1.12.0"
|
|
59
59
|
},
|
|
60
|
-
"version": "1.
|
|
60
|
+
"version": "1.75.0"
|
|
61
61
|
}
|
|
@@ -36,16 +36,29 @@ export default async (vorpal: Vorpal) =>
|
|
|
36
36
|
type: "input",
|
|
37
37
|
name: "sourceInstance",
|
|
38
38
|
|
|
39
|
-
message: "Source instance (connection string)? 🤔 ",
|
|
39
|
+
message: "Source instance (connection string or 'local')? 🤔 ",
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
const TARGET_INSTANCE_PORT = 54499;
|
|
42
|
+
let sourceProxy: { stop: () => void };
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
let targetProxy: { stop: () => void };
|
|
45
|
+
|
|
46
|
+
let sourcePort: number;
|
|
47
|
+
let targetPort: number;
|
|
48
|
+
|
|
49
|
+
if (sourceInstance === "local") {
|
|
50
|
+
const { sourceLocalPort } = await this.prompt({
|
|
51
|
+
type: "number",
|
|
52
|
+
name: "sourceLocalPort",
|
|
53
|
+
default: 5432,
|
|
54
|
+
|
|
55
|
+
message: "Local Port for source? 🤔 ",
|
|
56
|
+
});
|
|
57
|
+
sourcePort = sourceLocalPort;
|
|
58
|
+
} else {
|
|
59
|
+
sourcePort = 54399;
|
|
60
|
+
sourceProxy = await createProxy(sourceInstance, sourcePort);
|
|
61
|
+
}
|
|
49
62
|
|
|
50
63
|
const { sourcePassword } = await this.prompt({
|
|
51
64
|
type: "input",
|
|
@@ -65,13 +78,22 @@ export default async (vorpal: Vorpal) =>
|
|
|
65
78
|
type: "input",
|
|
66
79
|
name: "targetInstance",
|
|
67
80
|
|
|
68
|
-
message: "Targe INSTANCE (connection string)? 🤔 ",
|
|
81
|
+
message: "Targe INSTANCE (connection string or 'local')? 🤔 ",
|
|
69
82
|
});
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
if (targetInstance === "local") {
|
|
85
|
+
const { targetLocalPort } = await this.prompt({
|
|
86
|
+
type: "number",
|
|
87
|
+
name: "targetLocalPort",
|
|
88
|
+
default: 5432,
|
|
89
|
+
|
|
90
|
+
message: "Local Port for target? 🤔 ",
|
|
91
|
+
});
|
|
92
|
+
targetPort = targetLocalPort;
|
|
93
|
+
} else {
|
|
94
|
+
targetPort = 54499;
|
|
95
|
+
targetProxy = await createProxy(targetInstance, targetPort);
|
|
96
|
+
}
|
|
75
97
|
|
|
76
98
|
const { targetPassword } = await this.prompt({
|
|
77
99
|
type: "input",
|
|
@@ -98,7 +120,7 @@ export default async (vorpal: Vorpal) =>
|
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
const targetPSQL = (command: string) =>
|
|
101
|
-
`PGPASSWORD=${targetPassword} psql -p ${
|
|
123
|
+
`PGPASSWORD=${targetPassword} psql -p ${targetPort} --host=localhost --user=postgres -q ${command}`;
|
|
102
124
|
|
|
103
125
|
const copyDBScript = `
|
|
104
126
|
set -e
|
|
@@ -108,7 +130,7 @@ export default async (vorpal: Vorpal) =>
|
|
|
108
130
|
dumptmp=$(mktemp /tmp/dump.XXXXXX)
|
|
109
131
|
|
|
110
132
|
echo "Dumping file to $dumptmp"
|
|
111
|
-
pg_dump --dbname=postgres://postgres:${sourcePassword}@localhost:${
|
|
133
|
+
pg_dump --dbname=postgres://postgres:${sourcePassword}@localhost:${sourcePort}/${sourceDbName} --no-owner --no-privileges > $dumptmp
|
|
112
134
|
echo "dump done"
|
|
113
135
|
${targetPSQL(
|
|
114
136
|
`-c 'drop database "${targetDbName}" WITH (FORCE)' 1> /dev/null || true`
|
|
@@ -126,7 +148,7 @@ export default async (vorpal: Vorpal) =>
|
|
|
126
148
|
try {
|
|
127
149
|
await spawn(copyDBScript, [], { shell: "bash", stdio: "inherit" });
|
|
128
150
|
} finally {
|
|
129
|
-
sourceProxy
|
|
130
|
-
targetProxy
|
|
151
|
+
sourceProxy?.stop();
|
|
152
|
+
targetProxy?.stop();
|
|
131
153
|
}
|
|
132
154
|
});
|