Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3379699
D4283.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D4283.diff
View Options
diff --git a/keyserver/src/cron/backups.js b/keyserver/src/cron/backups.js
--- a/keyserver/src/cron/backups.js
+++ b/keyserver/src/cron/backups.js
@@ -19,6 +19,7 @@
type BackupConfig = {
+enabled: boolean,
+directory: string,
+ +maxDirSizeMiB?: ?number,
};
function getBackupConfig(): Promise<?BackupConfig> {
@@ -74,6 +75,8 @@
console.warn(`saveBackup threw for ${filename}`, e);
await unlink(filePath);
}
+
+ await deleteOldBackupsIfSpaceExceeded();
}
function mysqldump(
@@ -247,4 +250,27 @@
return filteredBackups;
}
+async function deleteOldBackupsIfSpaceExceeded() {
+ const backupConfig = await getBackupConfig();
+ invariant(backupConfig, 'backupConfig should be non-null');
+ const { maxDirSizeMiB } = backupConfig;
+ if (!maxDirSizeMiB) {
+ return;
+ }
+
+ const sortedBackupInfos = await getSortedBackupInfos();
+ const mostRecentBackup = sortedBackupInfos.pop();
+ let bytesLeft = maxDirSizeMiB * 1024 * 1024 - mostRecentBackup.bytes;
+
+ const deleteBackupPromises = [];
+ for (let i = sortedBackupInfos.length - 1; i >= 0; i--) {
+ const backupInfo = sortedBackupInfos[i];
+ bytesLeft -= backupInfo.bytes;
+ if (bytesLeft <= 0) {
+ deleteBackupPromises.push(deleteBackup(backupInfo.filename));
+ }
+ }
+ await Promise.all(deleteBackupPromises);
+}
+
export { backupDB };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 6:33 PM (21 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594595
Default Alt Text
D4283.diff (1 KB)
Attached To
Mode
D4283: [keyserver] Add maxDirSizeMiB to BackupConfig
Attached
Detach File
Event Timeline
Log In to Comment