nitor 1.4.1 → 1.4.2
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/services/mongodb-backup.js +33 -5
- package/services/utils.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitor",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "A comprehensive CLI toolkit for automating GitLab operations, AI-powered code review, build/deploy automation, MongoDB backup/restore, and developer productivity tools",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Nithin V <mails2nithin@gmail.com>",
|
|
@@ -49,6 +49,7 @@ const executeMongoRestore = async (config) => {
|
|
|
49
49
|
: `docker exec -it ${containerName} mongorestore --drop --stopOnError=false ${containerBackupPath}`;
|
|
50
50
|
|
|
51
51
|
console.log('Executing mongorestore...');
|
|
52
|
+
|
|
52
53
|
try {
|
|
53
54
|
execSync(restoreCommand, { stdio: 'inherit', shell: isWindows ? 'cmd.exe' : '/bin/sh' });
|
|
54
55
|
console.log(`${colors.green}✓ Mongorestore completed successfully${colors.reset}`);
|
|
@@ -70,9 +71,10 @@ const executeMongoRestore = async (config) => {
|
|
|
70
71
|
console.log(`${colors.green}Restore completed successfully!${colors.reset}\n`);
|
|
71
72
|
} else {
|
|
72
73
|
console.log(`\nStarting MongoDB restore to local machine`);
|
|
73
|
-
|
|
74
74
|
console.log('Executing mongorestore...');
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
const localRestoreCommand = `mongorestore --stopOnError=false --uri="mongodb://localhost:27017/" "${normalizedLocalPath}"`;
|
|
77
|
+
|
|
76
78
|
try {
|
|
77
79
|
execSync(localRestoreCommand, {
|
|
78
80
|
stdio: 'inherit',
|
|
@@ -127,7 +129,9 @@ const executeMongoBackup = async (config) => {
|
|
|
127
129
|
: `kubectl exec -it ${pod} -- mongodump --username ${username} --password ${password} --authenticationDatabase ${database} --db ${database} --out ${backupPath}`;
|
|
128
130
|
|
|
129
131
|
console.log('Executing mongodump...');
|
|
132
|
+
|
|
130
133
|
execSync(mongodumpCommand, { stdio: 'inherit', shell: isWindows ? 'cmd.exe' : '/bin/sh' });
|
|
134
|
+
|
|
131
135
|
console.log(`${colors.green}✓ Mongodump completed successfully${colors.reset}`);
|
|
132
136
|
|
|
133
137
|
// Expand and normalize paths for cross-platform compatibility
|
|
@@ -144,13 +148,15 @@ const executeMongoBackup = async (config) => {
|
|
|
144
148
|
: `kubectl exec -it ${pod} -- rm -rf ${backupPath}`;
|
|
145
149
|
|
|
146
150
|
console.log(`Copying backup to ${destinationPath}...`);
|
|
151
|
+
|
|
147
152
|
execSync(copyCommand, { stdio: 'inherit', shell: isWindows ? 'cmd.exe' : '/bin/sh' });
|
|
148
|
-
console.log(`${colors.green}✓ Backup copied successfully${colors.reset}`);
|
|
149
153
|
|
|
154
|
+
console.log(`${colors.green}✓ Backup copied successfully${colors.reset}`);
|
|
150
155
|
console.log('Cleaning up backup data from pod...');
|
|
156
|
+
|
|
151
157
|
execSync(cleanupCommand, { stdio: 'inherit', shell: isWindows ? 'cmd.exe' : '/bin/sh' });
|
|
152
|
-
console.log(`${colors.green}✓ Backup data removed from pod${colors.reset}`);
|
|
153
158
|
|
|
159
|
+
console.log(`${colors.green}✓ Backup data removed from pod${colors.reset}`);
|
|
154
160
|
console.log(
|
|
155
161
|
`${colors.green}Backup completed! Files saved to: ${destinationPath}${colors.reset}\n`,
|
|
156
162
|
);
|
|
@@ -191,9 +197,31 @@ const backup = async (values) => {
|
|
|
191
197
|
console.log(`Processing backup for project: ${project}`);
|
|
192
198
|
console.log(`========================================`);
|
|
193
199
|
|
|
194
|
-
|
|
200
|
+
let configs = [];
|
|
201
|
+
|
|
202
|
+
if (values.components) {
|
|
203
|
+
configs = projectConfigs.filter((component) =>
|
|
204
|
+
component.database.includes(values.components),
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
configs = projectConfigs;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (const dbConfig of configs) {
|
|
195
211
|
try {
|
|
196
212
|
await executeMongoBackup(dbConfig);
|
|
213
|
+
|
|
214
|
+
// Drop database in target MongoDB after backup download
|
|
215
|
+
const containerName = restoreConfig?.containerName || 'mongodb';
|
|
216
|
+
const dropCommand = values?.docker
|
|
217
|
+
? `docker exec ${containerName} mongosh --eval "db.getSiblingDB('${dbConfig.database}').dropDatabase()"`
|
|
218
|
+
: `mongosh --eval "db.getSiblingDB('${dbConfig.database}').dropDatabase()"`;
|
|
219
|
+
|
|
220
|
+
console.log(`Dropping database ${dbConfig.database} in target MongoDB...`);
|
|
221
|
+
|
|
222
|
+
execSync(dropCommand, { stdio: 'inherit', shell: isWindows ? 'cmd.exe' : '/bin/sh' });
|
|
223
|
+
|
|
224
|
+
console.log(`${colors.green}✓ Database ${dbConfig.database} dropped${colors.reset}`);
|
|
197
225
|
} catch (error) {
|
|
198
226
|
console.error(
|
|
199
227
|
`${colors.red}Failed to backup database ${dbConfig.database} for project ${project}${colors.reset}`,
|
package/services/utils.js
CHANGED
|
@@ -100,8 +100,10 @@ const projectIdMap = {
|
|
|
100
100
|
phrBackend: '117',
|
|
101
101
|
phrDeployment: '64',
|
|
102
102
|
configService: '227',
|
|
103
|
+
configServiceDeployment: '228',
|
|
103
104
|
healthRecords: '115',
|
|
104
105
|
centralAuth: '134',
|
|
106
|
+
centralAuthDeployment: '138',
|
|
105
107
|
mpi: '10',
|
|
106
108
|
phrAdminBackend: '126',
|
|
107
109
|
phrAdminClient: '130',
|