Spaces:
Sleeping
Sleeping
File size: 7,404 Bytes
da819ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
#!/usr/bin/env node
const fs = require('fs').promises;
const path = require('path');
// Cron Setup and Backup Usage Guide
const cronGuide = {
// Show cron setup instructions
showCronSetup() {
console.log('β° CRON JOB SETUP GUIDE');
console.log('=======================\n');
console.log('1. π EDIT CRONTAB:');
console.log(' crontab -e');
console.log('');
console.log('2. π ADD BACKUP JOB (choose one):');
console.log('');
console.log(' # Daily backup at 2 AM');
console.log(' 0 2 * * * cd /Users/hongchangyu/Downloads/App\\ Projects/Cultural\\ Shift\\ Sandbox/deploy/backend && node comprehensive-backup.js');
console.log('');
console.log(' # Weekly backup on Sunday at 3 AM');
console.log(' 0 3 * * 0 cd /Users/hongchangyu/Downloads/App\\ Projects/Cultural\\ Shift\\ Sandbox/deploy/backend && node comprehensive-backup.js');
console.log('');
console.log(' # Every 6 hours');
console.log(' 0 */6 * * * cd /Users/hongchangyu/Downloads/App\\ Projects/Cultural\\ Shift\\ Sandbox/deploy/backend && node comprehensive-backup.js');
console.log('');
console.log('3. β
VERIFY CRON JOBS:');
console.log(' crontab -l');
console.log('');
console.log('4. π CHECK CRON LOGS:');
console.log(' tail -f /var/log/cron');
console.log(' or');
console.log(' grep CRON /var/log/syslog');
console.log('');
},
// Show backup usage instructions
showBackupUsage() {
console.log('πΎ BACKUP USAGE GUIDE');
console.log('=====================\n');
console.log('π CHECK AVAILABLE BACKUPS:');
console.log(' node simple-automated-backup.js');
console.log(' # Lists all backups with details');
console.log('');
console.log('π VERIFY BACKUP INTEGRITY:');
console.log(' node comprehensive-backup.js');
console.log(' # Creates new backup and verifies integrity');
console.log('');
console.log('π BACKUP CONTENTS:');
console.log(' - Database: All collections (subtitles, source texts, users)');
console.log(' - Code: Frontend and backend files');
console.log(' - Configuration: package.json, Dockerfile, etc.');
console.log(' - Manifest: Backup metadata and verification info');
console.log('');
console.log('π RESTORE FROM BACKUP:');
console.log(' # Database only (safe)');
console.log(' node restore-database.js <backup-name>');
console.log('');
console.log(' # Full restore (including code)');
console.log(' node restore-comprehensive.js <backup-name>');
console.log('');
},
// Show cron job examples
showCronExamples() {
console.log('π CRON JOB EXAMPLES');
console.log('====================\n');
console.log('β° TIME FORMAT: minute hour day month day-of-week command');
console.log('');
console.log('π
COMMON SCHEDULES:');
console.log(' 0 2 * * * # Daily at 2 AM');
console.log(' 0 */6 * * * # Every 6 hours');
console.log(' 0 3 * * 0 # Weekly on Sunday at 3 AM');
console.log(' 0 1 1 * * # Monthly on 1st at 1 AM');
console.log(' */30 * * * * # Every 30 minutes');
console.log('');
console.log('π§ BACKUP COMMANDS:');
console.log(' # Simple data backup');
console.log(' node simple-automated-backup.js');
console.log('');
console.log(' # Comprehensive backup (data + code)');
console.log(' node comprehensive-backup.js');
console.log('');
console.log(' # With logging');
console.log(' node comprehensive-backup.js >> backup.log 2>&1');
console.log('');
},
// Show backup locations
showBackupLocations() {
console.log('π BACKUP LOCATIONS');
console.log('===================\n');
const backupDir = path.join(__dirname, 'backups');
console.log(`π Local backups: ${backupDir}`);
console.log('');
console.log('π BACKUP STRUCTURE:');
console.log(' backups/');
console.log(' βββ comprehensive-backup-2025-08-05T.../');
console.log(' β βββ database.json # All database data');
console.log(' β βββ code/ # All source code');
console.log(' β β βββ backend/ # Backend files');
console.log(' β β βββ frontend/ # Frontend files');
console.log(' β β βββ root/ # Root config');
console.log(' β βββ config/ # Configuration files');
console.log(' β βββ manifest.json # Backup metadata');
console.log(' βββ auto-backup-2025-08-05T.../');
console.log(' βββ database.json # Data only');
console.log('');
console.log('πΎ BACKUP TYPES:');
console.log(' - comprehensive-backup-* : Data + Code + Config');
console.log(' - auto-backup-* : Data only (faster)');
console.log('');
},
// Show how to check backup contents
async showBackupContents() {
console.log('π CHECKING BACKUP CONTENTS');
console.log('===========================\n');
const backupDir = path.join(__dirname, 'backups');
try {
const backups = await fs.readdir(backupDir);
if (backups.length === 0) {
console.log('β No backups found');
return;
}
console.log('π Available backups:');
for (const backup of backups) {
const backupPath = path.join(backupDir, backup);
const stats = await fs.stat(backupPath);
if (stats.isDirectory()) {
console.log(` π¦ ${backup} (${stats.mtime.toLocaleString()})`);
// Check if it's a comprehensive backup
const manifestPath = path.join(backupPath, 'manifest.json');
try {
await fs.access(manifestPath);
console.log(` β
Comprehensive backup (data + code)`);
} catch {
console.log(` π Data backup only`);
}
}
}
} catch (error) {
console.log('β Could not read backup directory:', error.message);
}
console.log('');
console.log('π TO EXAMINE A SPECIFIC BACKUP:');
console.log(' ls -la backups/comprehensive-backup-*/');
console.log(' cat backups/comprehensive-backup-*/manifest.json');
console.log('');
}
};
// Main function
const main = async () => {
console.log('π CRON & BACKUP GUIDE');
console.log('======================\n');
// Show all guides
cronGuide.showCronSetup();
cronGuide.showBackupUsage();
cronGuide.showCronExamples();
cronGuide.showBackupLocations();
await cronGuide.showBackupContents();
console.log('π― QUICK START:');
console.log('1. Set up cron: crontab -e');
console.log('2. Add: 0 2 * * * cd /path/to/backend && node comprehensive-backup.js');
console.log('3. Check backups: node simple-automated-backup.js');
console.log('4. Restore if needed: node restore-database.js <backup-name>');
console.log('');
console.log('π NEED HELP?');
console.log('- Check cron logs: tail -f /var/log/cron');
console.log('- Test backup: node comprehensive-backup.js');
console.log('- List backups: node simple-automated-backup.js');
};
// Run the guide
main(); |