DB: Add npm backup command for DB backups

This commit is contained in:
2026-02-03 13:40:56 +01:00
parent 2df9279c1b
commit 5046fe91ba

25
scripts/backup.js Normal file
View File

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