From 02888c5f02d0d945a4e2a07da8b6de55cd339921 Mon Sep 17 00:00:00 2001 From: Patrick Mac Cann Date: Sun, 29 Mar 2026 17:17:00 -0400 Subject: [PATCH] Run backup on startup if none exists for today If the app starts after the scheduled 11 AM backup time, no backup would be created until the next day. This checks for an existing backup file matching today's date on startup and runs one immediately if missing. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/backup_database.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backup_database.ts b/src/backup_database.ts index 8d8249f..9eb5261 100755 --- a/src/backup_database.ts +++ b/src/backup_database.ts @@ -94,8 +94,23 @@ function cleanupOldBackups() { } } +// Check if a backup for today already exists +function todayBackupExists(): boolean { + const todayFilename = filename(database!) + const filePath = `${backupDir}/${todayFilename}` + return fs.existsSync(filePath) +} + // Running backups daily at 11 am local time function startSchedule() { + // Run a backup immediately on startup if none exists for today + if (!todayBackupExists()) { + console.log('No backup found for today, starting one now...') + script() + } else { + console.log('Backup for today already exists, skipping immediate backup.') + } + cron.schedule( '0 0 11 * * *', () => {