Backup System - johnpeterman72/CursorRIPER.sigma GitHub Wiki

💾 Backup System

The Backup System provides automatic safety nets throughout your development process, ensuring you can always recover from mistakes, violations, or unexpected issues.

🎯 Why Backups Matter

Development risks that backups protect against:

  • 🚫 Accidental deletions
  • 🚫 Failed refactoring
  • 🚫 Permission violations
  • 🚫 Corrupted memory files
  • 🚫 Mode transition errors

The backup system provides automatic protection without manual intervention.

🗂️ Backup Structure

/memory-bank/
├── backups/
│   ├── 2024-01-15/
│   │   ├── 10-30-45/           # Timestamp folders
│   │   │   ├── projectbrief.md.bak
│   │   │   ├── systemPatterns.md.bak
│   │   │   └── ...
│   │   └── emergency_14-22-10.json
│   └── context/
│       └── context_2024-01-15_10-30-45.json

🔄 Automatic Backup Triggers

1. Mode Transitions

Every mode switch creates a backup:

Φ_mode_transition = {
  transition(mode_a, mode_b) = {
    Σ_backup.create_backup(),  // Automatic backup
    verify_completion(mode_a),
    set_mode(mode_b),
    // ...
  }
}

2. Destructive Operations

Before any risky operation:

Δ₁: destructive_op(x) ⟶ warn ∧ confirm ∧ Σ_backup.create_backup()

Examples:

  • File deletion
  • Mass updates
  • Database modifications
  • Configuration changes

3. Permission Violations

On any violation detection:

𝕍(op, Ω) = {
  log_violation(op, Ω),
  create_backup(),      // Safety backup
  revert_to_safe_mode(),
  notify_violation(op, Ω)
}

4. Manual Triggers

User-initiated backups:

"Create a backup before this risky operation"
"Backup current state"
"Save memory snapshot"

📦 Backup Types

1. Full Memory Backup

Complete memory state snapshot:

Σ_backup.create_backup() = {
  timestamp = format("YYYY-MM-DD_HH-MM-SS"),
  copy_files(𝕄, 📦 + timestamp)
}

Includes all six memory files:

  • σ₁ (projectbrief.md)
  • σ₂ (systemPatterns.md)
  • σ₃ (techContext.md)
  • σ₄ (activeContext.md)
  • σ₅ (progress.md)
  • σ₆ (protection.md)

2. Context Backup

Preserves active context:

Σ_backup.backup_context() = {
  ctx_backup = {
    refs: Σ_context.active_references,
    status: Σ_context.status_map
  },
  write_json(📦 + "context_" + timestamp + ".json", ctx_backup)
}

Example context backup:

{
  "refs": [
    {"type": "Γ₁", "name": "src/auth.js", "added": "2024-01-15T10:30:00"},
    {"type": "Γ₃", "name": "validateUser()", "added": "2024-01-15T10:31:00"}
  ],
  "status": {
    "src/auth.js": "active",
    "validateUser()": "essential"
  }
}

3. Emergency Backup

Critical state preservation:

Σ_backup.emergency_backup() = {
  create_backup(),
  write_json(📦 + "emergency_" + timestamp + ".json", {
    mode: current_mode,
    context: Σ_context.active_references,
    permissions: current_permissions,
    last_operation: last_op,
    error_state: current_error
  })
}

4. Incremental Backup

Changes since last backup:

incremental_backup() = {
  changes = diff(current_state, last_backup),
  write_json(📦 + "incremental_" + timestamp + ".json", changes)
}

🛡️ Backup Strategies

1. Time-Based Strategy

Regular interval backups:

Every hour: Incremental backup
Every day: Full backup
Every week: Archive old backups

2. Event-Based Strategy

Triggered by specific events:

Mode switch: Full backup
Major feature: Full backup
Before refactor: Full backup
After milestone: Archive backup

3. Risk-Based Strategy

Based on operation risk:

Low risk: No backup
Medium risk: Context backup
High risk: Full backup
Critical risk: Emergency backup

4. Milestone Strategy

At project checkpoints:

Feature complete: Tagged backup
Before deployment: Full backup
After deployment: Archive state
Major version: Permanent backup

🔄 Recovery Procedures

1. Simple Recovery

Restore from most recent backup:

# List available backups
ls /memory-bank/backups/

# Copy backup files
cp /memory-bank/backups/2024-01-15/10-30-45/*.bak /memory-bank/

2. Selective Recovery

Restore specific files:

# Restore only projectbrief.md
cp /memory-bank/backups/2024-01-15/10-30-45/projectbrief.md.bak /memory-bank/projectbrief.md

3. Context Recovery

Restore context state:

// Load context backup
const backup = JSON.parse(
  readFile('/memory-bank/backups/context/context_2024-01-15_10-30-45.json')
);

// Restore references
Σ_context.active_references = backup.refs;
Σ_context.status_map = backup.status;

4. Emergency Recovery

From critical failure:

// Load emergency backup
const emergency = JSON.parse(
  readFile('/memory-bank/backups/emergency_14-22-10.json')
);

// Restore complete state
current_mode = emergency.mode;
Σ_context.active_references = emergency.context;
current_permissions = emergency.permissions;

// Investigate error
console.log('Failed operation:', emergency.last_operation);
console.log('Error state:', emergency.error_state);

📊 Backup Management

Backup Retention Policy

Hourly backups: Keep for 24 hours
Daily backups: Keep for 7 days
Weekly backups: Keep for 4 weeks
Milestone backups: Keep permanently
Emergency backups: Keep until resolved

Backup Naming Convention

Format: TYPE_YYYY-MM-DD_HH-MM-SS.ext

Examples:
full_2024-01-15_10-30-45/
context_2024-01-15_10-30-45.json
emergency_2024-01-15_14-22-10.json
incremental_2024-01-15_11-30-00.json
milestone_v1.0_2024-01-15.tar.gz

Backup Verification

verify_backup(backup_path) = {
  // Check all files present
  for (file in required_files) {
    if (!exists(backup_path + file)) {
      return false;
    }
  }
  
  // Verify file integrity
  for (file in backup_files) {
    if (!valid_checksum(file)) {
      return false;
    }
  }
  
  return true;
}

Backup Cleanup

cleanup_old_backups() = {
  backups = list_backups();
  
  for (backup in backups) {
    if (should_delete(backup, retention_policy)) {
      delete_backup(backup);
      log_deletion(backup);
    }
  }
}

💡 Best Practices

1. Pre-emptive Backups

Before risky operations:

Before: Major refactoring
Before: Database migrations
Before: Configuration changes
Before: Permission changes

2. Tagged Backups

Mark important states:

# Tag milestone backup
mv backup_2024-01-15 backup_v1.0_release

# Tag before major change
cp -r /memory-bank /memory-bank_before_refactor

3. Backup Verification

Regularly test recovery:

Weekly: Restore test backup
Monthly: Full recovery drill
Quarterly: Disaster recovery test

4. External Backups

Additional safety:

# Git backup
git add /memory-bank
git commit -m "Backup: Daily snapshot"
git push backup-branch

# Cloud backup
rsync -av /memory-bank/ cloud:/project-backups/

🚨 Recovery Scenarios

Scenario 1: Accidental Deletion

Situation: Deleted important file
Solution:
1. Check recent backups
2. Find file in backup
3. Restore single file
4. Verify restoration

Scenario 2: Failed Refactoring

Situation: Refactoring broke functionality
Solution:
1. Load pre-refactor backup
2. Restore all files
3. Re-approach refactoring
4. Create incremental changes

Scenario 3: Permission Violation

Situation: Unauthorized operation attempted
Solution:
1. Emergency backup created automatically
2. System reverted to safe mode
3. Review violation log
4. Restore if needed

Scenario 4: Corrupted Memory

Situation: Memory file corrupted
Solution:
1. Identify corrupted file
2. Find last good backup
3. Restore specific file
4. Verify cross-references

🛠️ Backup Commands

Manual Backup Commands

"Create full backup"
"Backup current context"
"Create milestone backup"
"Archive current state"

Recovery Commands

"List available backups"
"Restore from yesterday"
"Recover context from 10:30"
"Show backup contents"

Verification Commands

"Verify backup integrity"
"Check backup completeness"
"Test recovery procedure"
"Compare with backup"

📈 Backup Metrics

Track Backup Health

## Backup Statistics
- Last backup: 10 minutes ago
- Total backups: 127
- Storage used: 450MB
- Oldest backup: 30 days
- Recovery tests: 3 successful

Monitor Backup Frequency

Mode transitions: 45 backups
Manual requests: 12 backups
Violations: 3 backups
Scheduled: 67 backups

Recovery Success Rate

Total recoveries: 8
Successful: 8
Failed: 0
Success rate: 100%

🔐 Backup Security

Encryption

Sensitive backups encrypted:

if (contains_sensitive_data(backup)) {
  encrypted = encrypt(backup, backup_key);
  save(encrypted);
}

Access Control

Limit backup access:

Read: All modes
Create: System only
Restore: With confirmation
Delete: Admin only

Integrity Checks

Verify backup validity:

checksum = calculate_hash(backup);
store_checksum(checksum);

// On restore
if (verify_checksum(backup) !== stored_checksum) {
  throw new Error('Backup corrupted');
}

📚 Related Topics


← Cross-References | Home | Guides →