Files
general-purpose-bot/scripts/backup.js

26 lines
730 B
JavaScript

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