# Blog Backup Process

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

> **Superseded for strategy and day-to-day commands:** Use **[guides/BACKUP_GUIDE.md](guides/BACKUP_GUIDE.md)** as the canonical blog backup doc. This file remains for detailed procedural steps.

Detailed procedures for manual and automated blog backups, including setup instructions and schedule recommendations.

## Manual Backup Process

### Creating a Snapshot Backup

1. **Navigate to Project Root**

   ```bash
   cd /path/to/landingpage
   ```

2. **Run Backup Script**

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

3. **Verify Backup**

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

4. **Check Backup Status**

   ```bash
   python3 scripts/blog/check-backup-status.py
   ```

### Backup Output

Backup creates:
- Timestamped directory: `docs/backups/blog-snapshots/YYYY-MM-DD-HHMMSS/`
- Backup manifest: `BACKUP_MANIFEST.json`
- All post files: `posts/{category}/{slug}.json`
- Supporting files: `categories.json`, `topics.json`
- Extraction data: `extraction-data/blog-*.json`

## Automated Backup Setup

### Cron Setup (Linux/macOS)

1. **Edit Crontab**

   ```bash
   crontab -e
   ```

2. **Add Daily Backup**

   ```bash
   # Daily backup at 2 AM
   0 2 * * * /path/to/landingpage/scripts/blog/automated-backup.sh >> /path/to/logs/backup.log 2>&1
   ```

3. **Verify Cron Job**

   ```bash
   crontab -l
   ```

### Scheduled Task Setup (Windows)

1. **Open Task Scheduler**
2. **Create Basic Task**
3. **Set Trigger:** Daily at 2 AM
4. **Set Action:** Start program
   - Program: `python.exe`
   - Arguments: `scripts/blog/backup-blog-content.py --automated`
   - Start in: Project root directory

### Automated Script Features

The `automated-backup.sh` script includes:
- Error handling and logging
- Automatic cleanup of old backups
- Optional email notifications
- Status reporting

### Email Notifications

To enable email notifications:

```bash
./scripts/blog/automated-backup.sh --notify-email your@email.com
```

Requires `mail` command configured on system.

## Backup Schedule Recommendations

### Daily Backups

**Frequency:** Once per day

**When:** During low-traffic hours (e.g., 2 AM)

**Retention:** Last 30 backups

**Use Case:**
- Active content development
- Frequent updates
- Before major changes

### Weekly Backups

**Frequency:** Once per week

**When:** End of week (e.g., Sunday 2 AM)

**Retention:** 3 months

**Use Case:**
- Regular content updates
- Stable development
- Monthly content reviews

### Monthly Backups

**Frequency:** Once per month

**When:** Beginning of month (e.g., 1st at 2 AM)

**Retention:** 1 year

**Use Case:**
- Long-term archiving
- Migration milestones
- Major releases

### On-Demand Backups

**Frequency:** As needed

**When:**
- Before major content changes
- Before migration steps
- After significant updates
- Before deployments

**Retention:** Manual management

## Backup Cleanup

### Automatic Cleanup

The automated backup script includes cleanup:

```bash
python3 v2/scripts/blog/cleanup-old-backups.py
```

Runs automatically after backup creation.

### Manual Cleanup

Preview cleanup (dry run):

```bash
python3 v2/scripts/blog/cleanup-old-backups.py --dry-run
```

Execute cleanup:

```bash
python3 v2/scripts/blog/cleanup-old-backups.py
```

### Cleanup Policy

- **Daily backups:** Keep last 30
- **Weekly backups:** Keep for 3 months
- **Monthly backups:** Keep for 1 year
- **Superseded snapshots:** Removed by `v2/scripts/blog/cleanup-old-backups.py` (**delete** by default; `--archive` to move to `docs/backups/archive/`). Prune `archive/` with `--prune-archive` (see [guides/BACKUP_GUIDE.md](guides/BACKUP_GUIDE.md)).

## Backup Monitoring

### Status Check

Check backup status:

```bash
python3 scripts/blog/check-backup-status.py
```

Check last N days:

```bash
python3 scripts/blog/check-backup-status.py --days 7
```

### Log Files

Backup logs stored in:
- `logs/backup-YYYYMMDD.log`

Check recent logs:

```bash
tail -f logs/backup-$(date +%Y%m%d).log
```

### Backup Reports

Reports generated:
- `docs/backups/cleanup-report.json` - Cleanup summary
- `docs/backups/status-report.json` - Status summary

## Troubleshooting

### Backup Script Fails

**Check:**
1. File permissions
2. Disk space
3. Source files exist
4. Python version (3.7+)

**Solution:**
- Review error logs
- Check file permissions: `chmod +x scripts/blog/backup-blog-content.py`
- Verify disk space: `df -h`

### Cron Job Not Running

**Check:**
1. Cron service running
2. Crontab syntax correct
3. File paths absolute
4. Permissions correct

**Solution:**
- Test cron: `crontab -l`
- Check cron logs: `/var/log/cron` or `journalctl -u cron`
- Use absolute paths in crontab

### Backup Validation Fails

**Check:**
1. Backup files exist
2. JSON syntax valid
3. Checksums match

**Solution:**
- Re-run validation
- Check backup integrity
- Re-create backup if corrupted

## Best Practices

1. **Regular Backups**
   - Set up automated daily backups
   - Create manual backups before major changes
   - Test restoration periodically

2. **Monitoring**
   - Check backup status weekly
   - Review logs regularly
   - Monitor disk space

3. **Documentation**
   - Document backup schedule
   - Note backup purposes
   - Track restoration history

4. **Testing**
   - Test restoration monthly
   - Verify backup integrity
   - Practice restoration procedures

## Related Documentation

- [Backup Guide](content/blog/BACKUP_GUIDE.md) - Complete backup and restoration guide
- [Backup Best Practices](BACKUP_BEST_PRACTICES.md) - Best practices guide
- [WordPress Backup](WORDPRESS_BACKUP.md) - WordPress master backup details
