Spaces:
Sleeping
Sleeping
File size: 2,840 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 | const fs = require('fs');
const path = require('path');
const mongoose = require('mongoose');
// Atlas MongoDB connection string
const MONGODB_URI = 'mongodb+srv://nothingyu:wSg3lbO1PkHiRMq9@sandbox.ecysggv.mongodb.net/test?retryWrites=true&w=majority&appName=sandbox';
// Create backup with timestamp
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const backupName = `working-version-backup-${timestamp}`;
const backupDir = path.join(__dirname, 'backups', backupName);
async function createWorkingBackup() {
try {
console.log('π Creating backup of current working version...');
console.log('π Backup name:', backupName);
// Create backup directory
if (!fs.existsSync(path.join(__dirname, 'backups'))) {
fs.mkdirSync(path.join(__dirname, 'backups'));
}
fs.mkdirSync(backupDir);
// Connect to MongoDB
console.log('π Connecting to MongoDB...');
await mongoose.connect(MONGODB_URI);
// Backup database collections
console.log('π Backing up database collections...');
const collections = ['users', 'sourcetexts', 'submissions', 'subtitles', 'subtitlesubmissions'];
for (const collectionName of collections) {
try {
const collection = mongoose.connection.db.collection(collectionName);
const data = await collection.find({}).toArray();
const backupPath = path.join(backupDir, `${collectionName}.json`);
fs.writeFileSync(backupPath, JSON.stringify(data, null, 2));
console.log(`β
Backed up ${collectionName}: ${data.length} documents`);
} catch (error) {
console.log(`β οΈ Could not backup ${collectionName}:`, error.message);
}
}
// Create backup manifest
const manifest = {
backupName,
timestamp: new Date().toISOString(),
description: 'Working version backup - subtitle system working correctly',
features: [
'Fixed subtitle display logic with 0.5s buffer',
'Fixed segment 21 and 22 display (60 char limit)',
'Simplified subtitle timing logic',
'Working subtitle submissions system',
'Proper text formatting and line wrapping'
],
collections: collections,
version: '1.0.0'
};
fs.writeFileSync(path.join(backupDir, 'manifest.json'), JSON.stringify(manifest, null, 2));
console.log('β
Backup completed successfully!');
console.log('π Backup location:', backupDir);
console.log('π Manifest created with feature list');
} catch (error) {
console.error('β Backup failed:', error);
} finally {
await mongoose.disconnect();
console.log('π Disconnected from MongoDB');
}
}
// Run the backup
if (require.main === module) {
createWorkingBackup();
}
module.exports = { createWorkingBackup }; |