DB: Add npm backup command for DB backups
This commit is contained in:
25
scripts/backup.js
Normal file
25
scripts/backup.js
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user