@stamhoofd/backend-backup 2.107.1 → 2.107.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/index.ts +1 -1
- package/package.json +2 -2
- package/src/boot.ts +2 -2
- package/src/crons.ts +1 -1
- package/src/endpoints/BackupEndpoint.ts +1 -1
- package/src/endpoints/HealthEndpoint.ts +2 -2
- package/src/helpers/backup.ts +8 -8
package/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ backendEnv.load({ service: 'backup' }).catch((error) => {
|
|
|
4
4
|
console.error('Failed to load environment:', error);
|
|
5
5
|
process.exit(1);
|
|
6
6
|
}).then(async () => {
|
|
7
|
-
await import('./src/boot');
|
|
7
|
+
await import('./src/boot.js');
|
|
8
8
|
}).catch((error) => {
|
|
9
9
|
console.error('Failed to start the API:', error);
|
|
10
10
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/backend-backup",
|
|
3
|
-
"version": "2.107.
|
|
3
|
+
"version": "2.107.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "33deb06a0bac15cc46fe141bc3dcf1dafb6e82a1"
|
|
38
38
|
}
|
package/src/boot.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CORSPreflightEndpoint, Router, RouterServer } from '@simonbackx/simple-
|
|
|
2
2
|
import { CORSMiddleware, LogMiddleware } from '@stamhoofd/backend-middleware';
|
|
3
3
|
import { loadLogger } from '@stamhoofd/logging';
|
|
4
4
|
import { startCrons, stopCrons, waitForCrons } from '@stamhoofd/crons';
|
|
5
|
-
import { cleanBackups } from './helpers/backup';
|
|
5
|
+
import { cleanBackups } from './helpers/backup.js';
|
|
6
6
|
|
|
7
7
|
process.on('unhandledRejection', (error: Error) => {
|
|
8
8
|
console.error('unhandledRejection');
|
|
@@ -96,7 +96,7 @@ const start = async () => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
// Register crons
|
|
99
|
-
await import('./crons');
|
|
99
|
+
await import('./crons.js');
|
|
100
100
|
startCrons();
|
|
101
101
|
|
|
102
102
|
// Clean backups on boot (bit faster to retrieve the timestamp of the last backup for the health endpoint)
|
package/src/crons.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerCron } from '@stamhoofd/crons';
|
|
2
|
-
import { backup, backupBinlogs, cleanBackups, cleanBinaryLogBackups } from './helpers/backup';
|
|
2
|
+
import { backup, backupBinlogs, cleanBackups, cleanBinaryLogBackups } from './helpers/backup.js';
|
|
3
3
|
import { Formatter } from '@stamhoofd/utility';
|
|
4
4
|
|
|
5
5
|
let lastFullBackup: Date | null = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
2
2
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
|
-
import { backup } from '../helpers/backup';
|
|
4
|
+
import { backup } from '../helpers/backup.js';
|
|
5
5
|
|
|
6
6
|
type Params = Record<string, never>;
|
|
7
7
|
type Body = undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
|
-
import { BackupHealth, getHealth } from '../helpers/backup';
|
|
2
|
+
import { BackupHealth, getHealth } from '../helpers/backup.js';
|
|
3
3
|
import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
4
4
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
5
|
-
import { checkReplicaStatus } from '../helpers/replica-status';
|
|
5
|
+
import { checkReplicaStatus } from '../helpers/replica-status.js';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Body = undefined;
|
package/src/helpers/backup.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { DeleteObjectCommand, HeadObjectCommand, ListObjectsCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'; // ES Modules import
|
|
2
2
|
import { Database } from '@simonbackx/simple-database';
|
|
3
3
|
import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
4
|
+
import { QueueHandler } from '@stamhoofd/queues';
|
|
4
5
|
import { Formatter } from '@stamhoofd/utility';
|
|
5
6
|
import chalk from 'chalk';
|
|
6
7
|
import { exec } from 'child_process';
|
|
7
8
|
import fs from 'fs';
|
|
8
9
|
import { DateTime } from 'luxon';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { createReadStream } from 'node:fs';
|
|
9
12
|
import path from 'path';
|
|
10
13
|
import util from 'util';
|
|
11
14
|
const execPromise = util.promisify(exec);
|
|
12
|
-
import { createHash } from 'node:crypto';
|
|
13
|
-
import { createReadStream } from 'node:fs';
|
|
14
|
-
import { QueueHandler } from '@stamhoofd/queues';
|
|
15
15
|
|
|
16
16
|
// Normally we'll have ±24 binary logs per day (if max size is set to 50MB)
|
|
17
17
|
// Since well create a backup every day, keeping 1000 binary logs would give
|
|
@@ -86,14 +86,14 @@ export function getHealth(): BackupHealth {
|
|
|
86
86
|
return BackupHealth.create({
|
|
87
87
|
lastBinaryBackup: LAST_BINARY_BACKUP
|
|
88
88
|
? BackupDateSize.create({
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
date: Formatter.dateTimeIso(LAST_BINARY_BACKUP.date),
|
|
90
|
+
})
|
|
91
91
|
: null,
|
|
92
92
|
lastBackup: LAST_BACKUP
|
|
93
93
|
? BackupDateSize.create({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
date: Formatter.dateTimeIso(LAST_BACKUP.date),
|
|
95
|
+
size: Formatter.fileSize(LAST_BACKUP.size),
|
|
96
|
+
})
|
|
97
97
|
: null,
|
|
98
98
|
status,
|
|
99
99
|
});
|