From 5046fe91ba3c878e00df9e6941ff22abdefb068d Mon Sep 17 00:00:00 2001 From: Minz Date: Tue, 3 Feb 2026 13:40:56 +0100 Subject: [PATCH] DB: Add npm backup command for DB backups --- scripts/backup.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/backup.js diff --git a/scripts/backup.js b/scripts/backup.js new file mode 100644 index 0000000..5bf7f6d --- /dev/null +++ b/scripts/backup.js @@ -0,0 +1,25 @@ +const fs = require('fs'); +const path = require('path'); + +const dbPath = path.join(__dirname, '../data/minzbot.db'); +const backupDir = path.join(__dirname, '../data/backups'); + +if (!fs.existsSync(backupDir)) { + fs.mkdirSync(backupDir, { recursive: true }); +} + +const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); +const backupPath = path.join(backupDir, `${timestamp}_minzbot.db`); + +try { + if (fs.existsSync(dbPath)) { + fs.copyFileSync(dbPath, backupPath); + console.log(`Backup successful: ${backupPath}`); + } else { + console.error(`Database file not found at ${dbPath}`); + process.exit(1); + } +} catch (error) { + console.error('Backup failed:', error); + process.exit(1); +}