| 72 | } |
| 73 | |
| 74 | async function pruneBackups(backupDir, retentionDays) { |
| 75 | if (!Number.isFinite(retentionDays) || retentionDays <= 0) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | const entries = await readdir(backupDir, { withFileTypes: true }); |
| 80 | const cutoff = Date.now() - (retentionDays * 24 * 60 * 60 * 1000); |
| 81 | |
| 82 | for (const entry of entries) { |
| 83 | if (!entry.isFile() || !entry.name.endsWith('.dump')) { |
| 84 | continue; |
| 85 | } |
| 86 | |
| 87 | const fullPath = path.join(backupDir, entry.name); |
| 88 | const fileStats = await stat(fullPath); |
| 89 | if (fileStats.mtimeMs < cutoff) { |
| 90 | await unlink(fullPath); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | function buildDatabaseUrlWithName(databaseUrl, databaseName) { |
| 96 | const parsed = new URL(databaseUrl); |