# Blog Restoration Guide

**Last Updated:** 2026-01-10

Step-by-step guide for restoring blog content from backups, including validation steps and troubleshooting.

## Overview

This guide provides detailed procedures for restoring blog content from WordPress master backups and snapshot backups.

## Restoration Types

### 1. WordPress Master Backup Restoration

**Use Case:** Restore original WordPress content

**Source:** `docs/backups/wordpress-master/`

**Restores:**

- All 99 blog posts
- Original WordPress content
- WordPress URLs and metadata

### 2. Snapshot Backup Restoration

**Use Case:** Restore from previous snapshot

**Source:** `docs/backups/blog-snapshots/YYYY-MM-DD-HHMMSS/`

**Restores:**

- Blog post JSON files
- Categories and topics data
- Extraction data files

## Step-by-Step Restoration

### WordPress Master Backup Restoration

#### Step 1: Validate Backup

```bash
python3 scripts/blog/validate-backup.py docs/backups/wordpress-master
```

**Expected Output:**

- ✅ All JSON files valid
- ✅ All checksums match
- ✅ 99 posts verified

**If validation fails:**

- Check backup integrity
- Review validation errors
- Consider using alternative backup

#### Step 2: Backup Current Content (Optional)

If you want to preserve current content:

```bash
python3 scripts/blog/backup-blog-content.py --manual
```

Note the backup timestamp for potential rollback.

#### Step 3: Test Restoration (Dry Run)

```bash
python3 scripts/blog/restore-from-wordpress-backup.py --dry-run
```

**Review:**

- Posts to be restored
- Files to be created/modified
- Any errors or warnings

#### Step 4: Restore Posts

```bash
python3 scripts/blog/restore-from-wordpress-backup.py
```

**Process:**

- Restores all 99 posts
- Creates post JSON files
- Preserves WordPress URLs
- Generates restoration report

#### Step 5: Verify Restoration

**Check restoration report:**

- `docs/backups/restoration-report.json`

**Verify files:**

```bash
# Count restored posts
find v2/data/blog/posts -name "*.json" | wc -l
# Should show 99

# Check sample post
cat v2/data/blog/posts/lexikon/leitfaden-zur-finanzbuchhaltung.json | head -20
```

**Test content loading:**

- Load a post in browser
- Verify content displays correctly
- Check image references
- Test internal links

### Snapshot Backup Restoration

#### Step 1: List Available Snapshots

```bash
ls docs/backups/blog-snapshots/
```

Note the timestamp of the snapshot to restore.

#### Step 2: Validate Snapshot

```bash
python3 scripts/blog/validate-backup.py docs/backups/blog-snapshots/<timestamp>
```

**Expected Output:**

- ✅ All JSON files valid
- ✅ Checksums match
- ✅ Files complete

#### Step 3: Test Restoration (Dry Run)

```bash
python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<timestamp> --dry-run
```

**Review:**

- Files to be restored
- Current content backup location
- Any warnings

#### Step 4: Restore Snapshot

```bash
python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<timestamp>
```

**Process:**

- Backs up current posts automatically
- Restores posts directory
- Restores categories.json
- Restores topics.json
- Generates restoration report

#### Step 5: Verify Restoration

**Check restoration report:**

- `docs/backups/snapshot-restoration-report.json`

**Verify files:**

```bash
# Check post count
find v2/data/blog/posts -name "*.json" | wc -l

# Check categories
cat v2/data/blog/categories.json | head -20

# Check topics
cat v2/data/blog/topics.json | head -20
```

**Test content:**

- Load posts in browser
- Verify content correct
- Check relationships
- Test navigation

## Validation Steps

### Post-Restoration Validation

1. **File Count Validation**

   ```bash
   # Count posts
   find v2/data/blog/posts -name "*.json" | wc -l
   # Should match backup post count
   ```

2. **JSON Syntax Validation**

   ```bash
   # Validate all JSON files
   find v2/data/blog/posts -name "*.json" -exec python3 -m json.tool {} \; > /dev/null
   # No output = all valid
   ```

3. **Content Loading Test**

   ```bash
   # Test loading a post
   php -r "require 'v2/config/blog-template-helpers.php'; \$post = load_blog_post('lexikon', 'leitfaden-zur-finanzbuchhaltung'); echo \$post ? 'OK' : 'FAIL';"
   ```

4. **Integrity Check**

   ```bash
   python3 scripts/blog/check-backup-integrity.py docs/backups/blog-snapshots/<timestamp>
   ```

## Troubleshooting

### Restoration Failed

**Symptoms:**

- Script exits with error
- Posts not restored
- Partial restoration

**Solutions:**

1. **Check Error Messages**

   - Review console output
   - Check restoration report
   - Identify specific errors

2. **Verify Backup**

   - Validate backup integrity
   - Check backup completeness
   - Verify backup not corrupted

3. **Check Permissions**

   ```bash
   # Check write permissions
   ls -la v2/data/blog/posts/
   # Should show write permissions
   ```

4. **Retry Restoration**
   - Fix identified issues
   - Retry restoration
   - Use alternative backup if needed

### Posts Not Restored

**Symptoms:**

- Post count doesn't match
- Missing posts
- Empty directories

**Solutions:**

1. **Check Backup Content**

   ```bash
   # Check backup post count
   find docs/backups/blog-snapshots/<timestamp>/posts -name "*.json" | wc -l
   ```

2. **Verify Restoration Log**

   - Check restoration report
   - Review restored files list
   - Identify missing posts

3. **Manual Restoration**
   - Copy missing files manually
   - Verify file structure
   - Test content loading

### JSON Validation Errors

**Symptoms:**

- JSON syntax errors
- Parse errors
- Invalid structure

**Solutions:**

1. **Validate Backup JSON**

   ```bash
   python3 scripts/blog/validate-backup.py <backup_directory>
   ```

2. **Fix JSON Files**

   - Review error messages
   - Fix syntax errors
   - Re-validate

3. **Use Alternative Backup**
   - Try different snapshot
   - Use WordPress master backup
   - Restore from git history

### Content Mismatch

**Symptoms:**

- Content doesn't match backup
- Missing content
- Incorrect data

**Solutions:**

1. **Verify Backup Source**

   - Check backup timestamp
   - Verify backup content
   - Compare with source

2. **Check Restoration Process**

   - Review restoration log
   - Verify restoration steps
   - Check for errors

3. **Re-restore**
   - Use correct backup
   - Follow restoration steps
   - Validate after restoration

## Rollback Procedures

### Rolling Back Changes

If restoration causes issues:

1. **Identify Current Backup**

   - Note current backup timestamp
   - Check backup location

2. **Restore Previous Backup**

   ```bash
   python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<previous_timestamp>
   ```

3. **Verify Rollback**
   - Check content restored
   - Validate files
   - Test functionality

### Emergency Restoration

If critical issues occur:

1. **Use WordPress Master Backup**

   ```bash
   python3 scripts/blog/restore-from-wordpress-backup.py
   ```

2. **Verify Restoration**

   - Check all 99 posts restored
   - Validate content
   - Test functionality

3. **Document Issue**
   - Note what went wrong
   - Document restoration steps
   - Update backup procedures if needed

## Best Practices

1. **Always Test First**

   - Use dry run before restoration
   - Verify backup integrity
   - Test restoration process

2. **Backup Before Restoration**

   - Create snapshot of current content
   - Note backup location
   - Keep for potential rollback

3. **Validate After Restoration**

   - Check file counts
   - Validate JSON files
   - Test content loading
   - Verify functionality

4. **Document Restoration**
   - Note restoration date
   - Document source backup
   - Record any issues
   - Update restoration history

## Related Documentation

- [Backup Guide](BACKUP_GUIDE.md) - Complete backup guide
- [WordPress Backup](WORDPRESS_BACKUP.md) - WordPress backup details
- [Backup Process](BACKUP_PROCESS.md) - Backup procedures
