ante-erp-cli 1.10.0 → 1.10.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.
- package/package.json +1 -1
- package/src/utils/mongodb.js +68 -30
package/package.json
CHANGED
package/src/utils/mongodb.js
CHANGED
|
@@ -153,41 +153,79 @@ export async function dumpDatabase(connectionInfo, outputDir) {
|
|
|
153
153
|
// Convert to absolute path for Docker volume mount
|
|
154
154
|
const absoluteOutputDir = resolve(outputDir);
|
|
155
155
|
|
|
156
|
-
//
|
|
157
|
-
const dumpArgs = ['run', '--rm', '-v', `${absoluteOutputDir}:/backups`, 'mongo:latest', 'mongodump'];
|
|
158
|
-
|
|
159
|
-
// Build connection URI
|
|
160
|
-
let dumpHost = host;
|
|
156
|
+
// For localhost connections (CLI installations), use docker exec on existing container
|
|
161
157
|
if (host === 'localhost' || host === '127.0.0.1') {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
// Check if ante-mongodb container exists
|
|
159
|
+
try {
|
|
160
|
+
await execa('docker', ['inspect', 'ante-mongodb'], { reject: false });
|
|
161
|
+
|
|
162
|
+
// Dump inside the container to /tmp/mongodb-dump
|
|
163
|
+
const dumpArgs = ['exec', 'ante-mongodb', 'mongodump'];
|
|
164
|
+
if (user) dumpArgs.push('--username', user);
|
|
165
|
+
if (password) dumpArgs.push('--password', password);
|
|
166
|
+
if (authDatabase) dumpArgs.push('--authenticationDatabase', authDatabase);
|
|
167
|
+
dumpArgs.push('--db', database);
|
|
168
|
+
dumpArgs.push('--out', '/tmp/mongodb-dump');
|
|
169
|
+
|
|
170
|
+
await execa('docker', dumpArgs, {
|
|
171
|
+
timeout: 600000 // 10 minute timeout
|
|
172
|
+
});
|
|
165
173
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
// Copy dump from container to host
|
|
175
|
+
await execa('docker', [
|
|
176
|
+
'cp',
|
|
177
|
+
`ante-mongodb:/tmp/mongodb-dump/${database}`,
|
|
178
|
+
join(outputDir, database)
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
// Clean up dump inside container
|
|
182
|
+
await execa('docker', [
|
|
183
|
+
'exec',
|
|
184
|
+
'ante-mongodb',
|
|
185
|
+
'rm',
|
|
186
|
+
'-rf',
|
|
187
|
+
'/tmp/mongodb-dump'
|
|
188
|
+
], { reject: false });
|
|
189
|
+
|
|
190
|
+
} catch (containerError) {
|
|
191
|
+
throw new Error('MongoDB container (ante-mongodb) not found or not running');
|
|
192
|
+
}
|
|
174
193
|
} else {
|
|
175
|
-
// For
|
|
176
|
-
dumpArgs
|
|
177
|
-
if (port) dumpArgs.push('--port', port);
|
|
178
|
-
if (user) dumpArgs.push('--username', user);
|
|
179
|
-
if (password) dumpArgs.push('--password', password);
|
|
180
|
-
if (authDatabase) dumpArgs.push('--authenticationDatabase', authDatabase);
|
|
181
|
-
dumpArgs.push('--db', database);
|
|
182
|
-
}
|
|
194
|
+
// For remote connections, use docker run with volume mount
|
|
195
|
+
const dumpArgs = ['run', '--rm', '-v', `${absoluteOutputDir}:/backups`, 'mongo:latest', 'mongodump'];
|
|
183
196
|
|
|
184
|
-
|
|
185
|
-
|
|
197
|
+
let dumpHost = host;
|
|
198
|
+
if (host === 'localhost' || host === '127.0.0.1') {
|
|
199
|
+
dumpHost = 'host.docker.internal';
|
|
200
|
+
dumpArgs.splice(1, 0, '--add-host=host.docker.internal:host-gateway');
|
|
201
|
+
}
|
|
186
202
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
203
|
+
// Add connection parameters
|
|
204
|
+
if (isSrv) {
|
|
205
|
+
// For SRV connections, use --uri
|
|
206
|
+
const protocol = 'mongodb+srv://';
|
|
207
|
+
const auth = user && password ? `${user}:${password}@` : '';
|
|
208
|
+
const authDbPart = authDatabase && authDatabase !== database ? `?authSource=${authDatabase}` : '';
|
|
209
|
+
const uri = `${protocol}${auth}${dumpHost}/${database}${authDbPart}`;
|
|
210
|
+
dumpArgs.push('--uri', uri);
|
|
211
|
+
} else {
|
|
212
|
+
// For standard connections, use individual parameters
|
|
213
|
+
dumpArgs.push('--host', dumpHost);
|
|
214
|
+
if (port) dumpArgs.push('--port', port);
|
|
215
|
+
if (user) dumpArgs.push('--username', user);
|
|
216
|
+
if (password) dumpArgs.push('--password', password);
|
|
217
|
+
if (authDatabase) dumpArgs.push('--authenticationDatabase', authDatabase);
|
|
218
|
+
dumpArgs.push('--db', database);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Output directory
|
|
222
|
+
dumpArgs.push('--out', '/backups');
|
|
223
|
+
|
|
224
|
+
// Execute mongodump
|
|
225
|
+
await execa('docker', dumpArgs, {
|
|
226
|
+
timeout: 600000 // 10 minute timeout
|
|
227
|
+
});
|
|
228
|
+
}
|
|
191
229
|
|
|
192
230
|
// Verify dump directory was created and has content
|
|
193
231
|
const dumpDbDir = join(outputDir, database);
|