@stamhoofd/backend-backup 2.116.0 → 2.117.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend-backup",
3
- "version": "2.116.0",
3
+ "version": "2.117.1",
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": "842040d2dcbde452fb25178f3586c8d5293b974f"
37
+ "gitHead": "ac4ccac9c6dabba9abd19c830b42a4a37298fd77"
38
38
  }
@@ -17,8 +17,8 @@ const execPromise = util.promisify(exec);
17
17
  // Since well create a backup every day, keeping 1000 binary logs would give
18
18
  // a full history of 40 days - and leaves us enough margin in case more
19
19
  // logs are created in a day
20
- const MAX_BINARY_LOGS = 200;
21
- const MAX_BACKUPS = 30; // in days
20
+ let MAX_BINARY_LOGS = 3000; // ±9 GB = ±90days
21
+ const MAX_BACKUPS = 90; // in days = ±270 GB
22
22
  const BACKUP_PREFIX = 'backup-';
23
23
  const BINARY_LOG_PREFIX = 'binlog.';
24
24
 
@@ -72,10 +72,10 @@ export function getHealth(): BackupHealth {
72
72
  status = 'error';
73
73
  }
74
74
  else {
75
- if (LAST_BINARY_BACKUP.date.getTime() - now.getTime() > 60 * 10 * 1000) {
75
+ if (now.getTime() - LAST_BINARY_BACKUP.date.getTime() > 60 * 10 * 1000) {
76
76
  status = 'error';
77
77
  }
78
- if (LAST_BACKUP.date.getTime() - now.getTime() > 60 * 60 * 1000 * 25) {
78
+ if (now.getTime() - LAST_BACKUP.date.getTime() > 60 * 60 * 1000 * 25) {
79
79
  status = 'error';
80
80
  }
81
81
  if (LAST_BACKUP.size < (STAMHOOFD.MINIMUM_BACKUP_SIZE ?? 1 * 1000 * 1000)) {
@@ -148,7 +148,8 @@ export async function cleanBinaryLogBackups() {
148
148
  const client = getS3Client();
149
149
 
150
150
  // List all backup files on the server
151
- const allBackups = (await listAllFiles(STAMHOOFD.objectStoragePath + '/binlogs')).filter(f => f.key.endsWith('.enc') && path.basename(f.key).startsWith(BINARY_LOG_PREFIX));
151
+ const allBackups = (await listAllFiles(STAMHOOFD.objectStoragePath + '/binlogs')).filter(f => f.key.endsWith('.enc') && f.key.startsWith(BINARY_LOG_PREFIX));
152
+
152
153
  const numberToDelete = allBackups.length - MAX_BINARY_LOGS;
153
154
 
154
155
  if (numberToDelete <= 0) {
@@ -206,6 +207,10 @@ export async function listAllFiles(prefix: string): Promise<ObjectStorageFile[]>
206
207
  break;
207
208
  }
208
209
 
210
+ if (response.Contents.length < 1000) {
211
+ break;
212
+ }
213
+
209
214
  marker = response.NextMarker;
210
215
  }
211
216
 
@@ -456,9 +461,8 @@ export async function backupBinlogs() {
456
461
 
457
462
  if (rows.length > MAX_BINARY_LOGS) {
458
463
  console.error(chalk.bold(chalk.red('Warning: MAX_BINARY_LOGS is larger than the binary logs stored on the system. Please check the MySQL configuration.')));
459
-
460
- // Only copy last MAX_BINARY_LOGS rows
461
- rows.splice(0, rows.length - MAX_BINARY_LOGS);
464
+ console.error('Found ' + rows.length + ' binlogs. Increasing binary logs max size.');
465
+ MAX_BINARY_LOGS = rows.length;
462
466
  }
463
467
 
464
468
  const lastRow = rows.pop();