@tmlmobilidade/backupd 20260608.6.45 → 20260608.1237.46
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 +11 -11
- package/src/database/mongo.service.ts +9 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/backupd",
|
|
3
3
|
"description": "A backup service for databases.",
|
|
4
|
-
"version": "20260608.
|
|
4
|
+
"version": "20260608.1237.46",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "iso@tmlmobilidade.pt",
|
|
7
7
|
"name": "TML-ISO"
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"start": "npm run build && node dist/index.js"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@tmlmobilidade/consts": "
|
|
19
|
-
"@tmlmobilidade/dates": "
|
|
20
|
-
"@tmlmobilidade/emails": "
|
|
21
|
-
"@tmlmobilidade/interfaces": "
|
|
22
|
-
"@tmlmobilidade/logger": "
|
|
23
|
-
"@tmlmobilidade/types": "
|
|
24
|
-
"@tmlmobilidade/utils": "
|
|
25
|
-
"@types/archiver": "
|
|
18
|
+
"@tmlmobilidade/consts": "20260608.1209.6",
|
|
19
|
+
"@tmlmobilidade/dates": "20260608.1209.6",
|
|
20
|
+
"@tmlmobilidade/emails": "20260608.1209.6",
|
|
21
|
+
"@tmlmobilidade/interfaces": "20260608.1209.6",
|
|
22
|
+
"@tmlmobilidade/logger": "20260608.1209.6",
|
|
23
|
+
"@tmlmobilidade/types": "20260608.1209.6",
|
|
24
|
+
"@tmlmobilidade/utils": "20260608.1209.6",
|
|
25
|
+
"@types/archiver": "8.0.0",
|
|
26
26
|
"archiver": "8.0.0",
|
|
27
27
|
"mongodb": "7.2.0",
|
|
28
28
|
"nodemailer": "8.0.10",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"yaml": "2.9.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tmlmobilidade/tsconfig": "
|
|
35
|
-
"@types/node": "25.9.
|
|
34
|
+
"@tmlmobilidade/tsconfig": "20260608.1209.6",
|
|
35
|
+
"@types/node": "25.9.2",
|
|
36
36
|
"@types/nodemailer": "8.0.0",
|
|
37
37
|
"typescript": "6.0.3"
|
|
38
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ZipArchive } from 'archiver';
|
|
2
2
|
import { exec } from 'child_process';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { Collection, Db, DbOptions, MongoClient, MongoClientOptions } from 'mongodb';
|
|
@@ -18,12 +18,8 @@ export interface MongoDbConfig {
|
|
|
18
18
|
|
|
19
19
|
export class MongoDbService implements IDatabaseService {
|
|
20
20
|
private static _instance: MongoDbService;
|
|
21
|
-
get client(): MongoClient {
|
|
22
|
-
return this._client;
|
|
23
|
-
}
|
|
24
21
|
|
|
25
22
|
private _client: MongoClient;
|
|
26
|
-
|
|
27
23
|
private _dumpOptions?: MongoDbConfig['dump_options'];
|
|
28
24
|
private _uri: string;
|
|
29
25
|
|
|
@@ -40,6 +36,10 @@ export class MongoDbService implements IDatabaseService {
|
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
38
|
|
|
39
|
+
get client(): MongoClient {
|
|
40
|
+
return this._client;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
43
|
/**
|
|
44
44
|
* Get the singleton instance of MongoDbService.
|
|
45
45
|
*/
|
|
@@ -73,13 +73,12 @@ export class MongoDbService implements IDatabaseService {
|
|
|
73
73
|
if (error) {
|
|
74
74
|
console.error(`⤷ Error running mongodump: ${stderr}`);
|
|
75
75
|
reject(new Error(`Mongodump failed: ${stderr}`));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
76
|
+
} else {
|
|
78
77
|
console.log(`⤷ Mongodump completed successfully`);
|
|
79
78
|
|
|
80
79
|
// Create a file to stream archive data to.
|
|
81
80
|
const output = fs.createWriteStream(`${dumpDir}.zip`);
|
|
82
|
-
const archive =
|
|
81
|
+
const archive = new ZipArchive({
|
|
83
82
|
zlib: { level: 9 }, // Sets the compression level.
|
|
84
83
|
});
|
|
85
84
|
|
|
@@ -116,8 +115,7 @@ export class MongoDbService implements IDatabaseService {
|
|
|
116
115
|
try {
|
|
117
116
|
await this._client.connect();
|
|
118
117
|
console.log('⤷ Connected to MongoDB.');
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
118
|
+
} catch (error) {
|
|
121
119
|
throw new Error('Error connecting to MongoDB', { cause: error });
|
|
122
120
|
}
|
|
123
121
|
}
|
|
@@ -163,8 +161,7 @@ export class MongoDbService implements IDatabaseService {
|
|
|
163
161
|
exec(command, (error, stdout, stderr) => {
|
|
164
162
|
if (error) {
|
|
165
163
|
console.error(`⤷ Error running mongorestore: ${stderr}`);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
164
|
+
} else {
|
|
168
165
|
console.log(`⤷ Mongorestore completed successfully:\n${stdout}`);
|
|
169
166
|
}
|
|
170
167
|
});
|