T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/backup-database.js
#!/usr/bin/env node

// Database Backup Script for lavocat.quebec
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const BACKUP_DIR = '/var/backups/lavocat.quebec';
const DB_PATH = '/var/www/lavocat.quebec/production.db';
const DOMAIN = 'lavocat.quebec';

console.log('๐Ÿ’พ Starting database backup for lavocat.quebec...');

// Create backup directory if it doesn't exist
if (!fs.existsSync(BACKUP_DIR)) {
  fs.mkdirSync(BACKUP_DIR, { recursive: true });
  console.log('โœ… Created backup directory');
}

// Generate backup filename with timestamp
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const backupFilename = `production-${timestamp}.db`;
const backupPath = path.join(BACKUP_DIR, backupFilename);

try {
  // Check if database file exists
  if (!fs.existsSync(DB_PATH)) {
    console.error('โŒ Database file not found:', DB_PATH);
    console.log('๐Ÿ’ก Make sure the application is deployed and running');
    process.exit(1);
  }

  // Create backup
  console.log('๐Ÿ“‹ Creating database backup...');
  execSync(`cp "${DB_PATH}" "${backupPath}"`, { stdio: 'inherit' });
  
  // Get file size
  const stats = fs.statSync(backupPath);
  const fileSizeInMB = (stats.size / (1024 * 1024)).toFixed(2);
  
  console.log('โœ… Database backup completed successfully!');
  console.log(`๐Ÿ“ Backup file: ${backupPath}`);
  console.log(`๐Ÿ“Š File size: ${fileSizeInMB} MB`);
  
  // Clean up old backups (keep last 10)
  console.log('๐Ÿงน Cleaning up old backups...');
  const files = fs.readdirSync(BACKUP_DIR)
    .filter(file => file.startsWith('production-') && file.endsWith('.db'))
    .map(file => ({
      name: file,
      path: path.join(BACKUP_DIR, file),
      mtime: fs.statSync(path.join(BACKUP_DIR, file)).mtime
    }))
    .sort((a, b) => b.mtime - a.mtime);
  
  // Keep only the last 10 backups
  if (files.length > 10) {
    const filesToDelete = files.slice(10);
    filesToDelete.forEach(file => {
      fs.unlinkSync(file.path);
      console.log(`๐Ÿ—‘๏ธ  Deleted old backup: ${file.name}`);
    });
  }
  
  console.log(`๐Ÿ“Š Total backups: ${files.length}`);
  
} catch (error) {
  console.error('โŒ Backup failed:', error.message);
  process.exit(1);
}

// Optional: Create a compressed backup
const createCompressedBackup = () => {
  try {
    const compressedFilename = `production-${timestamp}.db.gz`;
    const compressedPath = path.join(BACKUP_DIR, compressedFilename);
    
    console.log('๐Ÿ—œ๏ธ  Creating compressed backup...');
    execSync(`gzip -c "${backupPath}" > "${compressedPath}"`, { stdio: 'inherit' });
    
    const stats = fs.statSync(compressedPath);
    const fileSizeInMB = (stats.size / (1024 * 1024)).toFixed(2);
    
    console.log('โœ… Compressed backup created!');
    console.log(`๐Ÿ“ Compressed file: ${compressedPath}`);
    console.log(`๐Ÿ“Š Compressed size: ${fileSizeInMB} MB`);
    
    // Clean up uncompressed backup
    fs.unlinkSync(backupPath);
    console.log('๐Ÿ—‘๏ธ  Removed uncompressed backup');
    
  } catch (error) {
    console.error('โŒ Compressed backup failed:', error.message);
  }
};

// Create compressed backup if requested
if (process.argv.includes('--compress')) {
  createCompressedBackup();
}

console.log('\n๐Ÿ“‹ Backup completed successfully!');
console.log('๐Ÿ’ก To restore from backup:');
console.log(`   cp "${backupPath}" "${DB_PATH}"`);
console.log('๐Ÿ’ก To create compressed backup:');
console.log('   node scripts/backup-database.js --compress'); 

CasperSecurity Mini