TransHub_backend / create-working-backup.js
linguabot's picture
Upload folder using huggingface_hub
da819ac verified
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 };