# Git Backup Strategy

**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 (Git vs local snapshots). This file expands on commit/tag conventions for migration-era work.

Git version control strategy for blog content backups, including commit strategy, tagging milestones, and branch strategy.

## Overview

This document defines the git workflow for blog content backups, ensuring version control integration with backup system.

## Commit Strategy

### Commit Message Format

**Format:**
```
blog: <type> <description>

<details>
```

**Types:**
- `backup` - Creating backups
- `restore` - Restoring from backups
- `content` - Content updates
- `fix` - Bug fixes
- `docs` - Documentation updates

**Examples:**

```
blog: backup Create WordPress master backup before migration

- Extracted all 99 posts
- Created backup manifest
- Validated backup integrity
```

```
blog: content Update post content with internal links

- Added 15 internal links
- Updated related posts
- Backup created before changes
```

### When to Commit

**Always commit:**
- After creating WordPress master backup
- After creating snapshot backups (optional, can batch)
- After major content updates
- After restoration operations

**Commit frequency:**
- WordPress master backup: Immediate commit
- Snapshot backups: Daily/weekly batch commits
- Content updates: Per update or batch related changes

## Tagging Strategy

### Migration Milestones

**Tag Format:**
```
blog-migration-<milestone>-<date>
```

**Milestones:**
- `wordpress-backup` - WordPress master backup created
- `content-extracted` - Content extraction complete
- `templates-ready` - Templates developed
- `migration-complete` - Migration completed
- `backup-system-ready` - Backup system implemented

**Examples:**

```bash
git tag -a blog-migration-wordpress-backup-2026-01-10 -m "WordPress master backup created with all 99 posts"
git tag -a blog-migration-backup-system-ready-2026-01-10 -m "Backup system implemented and tested"
```

### Tagging Script

**Script:** `scripts/blog/tag-blog-migration.sh`

**Usage:**

```bash
# Tag WordPress backup
./scripts/blog/tag-blog-migration.sh wordpress-backup

# Tag migration completion
./scripts/blog/tag-blog-migration.sh migration-complete
```

## Branch Strategy

### Main Branches

**master/main:**
- Production-ready code
- Stable backups
- Validated content

**development:**
- Active development
- Testing backups
- Content updates

### Feature Branches

**Naming:** `blog-<feature>-<description>`

**Examples:**
- `blog-backup-system` - Backup system implementation
- `blog-content-updates` - Content updates
- `blog-restoration-test` - Testing restoration procedures

### Backup Validation Branches

**Purpose:** Test backup restoration without affecting main branches

**Naming:** `blog-backup-test-<timestamp>`

**Usage:**

```bash
# Create test branch
git checkout -b blog-backup-test-2026-01-10

# Test restoration
python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<timestamp>

# Validate restoration
python3 scripts/blog/check-backup-integrity.py docs/backups/blog-snapshots/<timestamp>

# Merge if successful, discard if not
```

## Pre-Commit Validation

### Git Hook

**Location:** `.git/hooks/pre-commit`

**Purpose:** Validate JSON files before commit

**Checks:**
- JSON syntax validity
- Required fields present
- File structure correct

**Implementation:**

See `scripts/blog/pre-commit-validate-json.sh` for hook implementation.

### Hook Installation

```bash
# Copy hook
cp scripts/blog/pre-commit-validate-json.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

# Test hook
git add v2/data/blog/posts/lexikon/test.json
git commit -m "Test commit"
```

## Backup Integration

### Backup Before Commits

**Best Practice:** Create backup before major commits

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

# Commit changes
git add .
git commit -m "blog: content Update posts with new links"

# Note backup location in commit message if needed
```

### Commit Backup Manifests

**Policy:** Commit backup manifests for tracking

**Include:**
- `docs/backups/wordpress-master/BACKUP_MANIFEST.json`
- `docs/backups/blog-snapshots/*/BACKUP_MANIFEST.json` (selected snapshots)

**Exclude:**
- Large backup files (posts, content)
- Temporary backup files
- Archive directories

## Workflow Examples

### Creating WordPress Master Backup

```bash
# 1. Extract content
python3 scripts/blog/extract-content.py

# 2. Create backup
python3 scripts/blog/copy-wordpress-backup.py

# 3. Validate backup
python3 scripts/blog/validate-backup.py docs/backups/wordpress-master

# 4. Commit backup manifest
git add docs/backups/wordpress-master/BACKUP_MANIFEST.json
git commit -m "blog: backup Create WordPress master backup

- Extracted all 99 posts
- Created backup manifest
- Validated backup integrity"

# 5. Tag milestone
git tag -a blog-migration-wordpress-backup-2026-01-10 -m "WordPress master backup created"
```

### Updating Content with Backup

```bash
# 1. Create backup before changes
python3 scripts/blog/backup-blog-content.py --manual
BACKUP_TIMESTAMP=$(ls -t docs/backups/blog-snapshots/ | head -1)

# 2. Make content changes
# ... edit post files ...

# 3. Validate changes
python3 scripts/blog/validate-backup.py docs/backups/blog-snapshots/$BACKUP_TIMESTAMP

# 4. Commit changes
git add v2/data/blog/posts/
git commit -m "blog: content Update posts with internal links

- Added 15 internal links
- Updated related posts
- Backup: $BACKUP_TIMESTAMP"
```

### Testing Restoration

```bash
# 1. Create test branch
git checkout -b blog-backup-test-2026-01-10

# 2. Test restoration
python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<timestamp> --dry-run

# 3. If successful, restore
python3 scripts/blog/restore-from-snapshot.py docs/backups/blog-snapshots/<timestamp>

# 4. Validate restoration
python3 scripts/blog/check-backup-integrity.py docs/backups/blog-snapshots/<timestamp>

# 5. Commit restoration test
git add .
git commit -m "blog: restore Test restoration from snapshot <timestamp>"

# 6. Merge or discard branch
git checkout main
git merge blog-backup-test-2026-01-10  # or git branch -D blog-backup-test-2026-01-10
```

## Best Practices

1. **Always Backup Before Major Changes**
   - Create snapshot backup
   - Note backup location
   - Include in commit message

2. **Tag Migration Milestones**
   - WordPress backup creation
   - Major migration steps
   - System completion

3. **Use Feature Branches**
   - Isolate backup testing
   - Test restoration procedures
   - Validate before merging

4. **Commit Backup Manifests**
   - Track backup metadata
   - Document backup history
   - Enable restoration tracking

5. **Validate Before Committing**
   - Use pre-commit hooks
   - Validate JSON files
   - Check backup integrity

## Related Documentation

- [Backup Guide](content/blog/BACKUP_GUIDE.md) - Complete backup guide
- [Backup Process](BACKUP_PROCESS.md) - Backup procedures
- [Restoration Guide](content/blog/RESTORATION_GUIDE.md) - Restoration procedures
