Skip to content

Commit

Permalink
feat: email admins of stale backups removed from block volume storage
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 14, 2023
1 parent c1c4231 commit 1e1eb7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 18 additions & 0 deletions jobs/sqlite-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const AFFIXES = ['-backup', '-backup-wal', '-backup-shm'];
withFileTypes: true
});

const filePaths = [];

for (const dirent of dirents) {
if (!dirent.isDirectory()) continue;
// eslint-disable-next-line no-await-in-loop
Expand All @@ -92,12 +94,28 @@ const AFFIXES = ['-backup', '-backup-wal', '-backup-shm'];
if (stat.mtimeMs && stat.mtimeMs <= Date.now() - ms('4h')) {
// eslint-disable-next-line no-await-in-loop
await fs.promises.unlink(filePath);
filePaths.push(filePath);
}

break;
}
}
}

// email admins of any old files cleaned up
if (filePaths.length > 0)
await emailHelper({
template: 'alert',
message: {
to: config.email.message.from,
subject: `SQLite cleanup successfully removed (${filePaths.length}) stale backups`
},
locals: {
message: `<ul><li><code class="small">${filePaths.join(
'</code></li><li><code class="small">'
)}</code></li></ul>`
}
});
} catch (err) {
await logger.error(err);

Expand Down
6 changes: 2 additions & 4 deletions sqlite-bree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ const bree = new Bree({
jobs: [
{
//
// this is a long running job, but we attempt to restart it
// every 30s in case errors (e.g. uncaught exception edge case causes `process.exit()`)
// this job cleans up any backup artifacts from 1 hr+ ago for 'rekey' and 'backup' sqlite-server cases
// this job cleans up any backup artifacts from 4 hr+ ago for 'rekey' and 'backup' sqlite-server cases
// (e.g. the server stopped mid-backup or an error occurred, e.g. ran out of memory)
// and in an attempt to save on disk stoarge, we will run `fs.unlink` on each of these files
//
name: 'sqlite-cleanup',
interval: '30s',
interval: '1h',
timeout: 0
}
]
Expand Down

0 comments on commit 1e1eb7a

Please sign in to comment.