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); +}