---
name: step-01-backup
description: Create backup of migration files
next_step: step-02-fetch.md
---

# Step 1: Backup

## YOUR TASK:

Create a complete backup before modifying migration files.

**Previous step:** `step-00-init.md`

---

## EXECUTION SEQUENCE:

### 1. Create Backup Directory

```bash
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR=".claude/gitflow/backup/migrations/rebase_${TIMESTAMP}"

mkdir -p "$BACKUP_DIR"
echo "Backup directory: $BACKUP_DIR"
```

### 2. Backup All Migration Files

```bash
cp "$MIGRATIONS_DIR"/*.cs "$BACKUP_DIR/" 2>/dev/null || {
  echo "ERROR: No migration files to backup"
  exit 1
}

BACKUP_COUNT=$(ls -1 "$BACKUP_DIR"/*.cs 2>/dev/null | wc -l)
echo "Backed up: $BACKUP_COUNT files"
```

### 3. Create Manifest

```bash
cat > "$BACKUP_DIR/MANIFEST.md" << EOF
# Rebase-Snapshot Backup Manifest

**Created:** $(date -Iseconds)
**Branch:** $CURRENT_BRANCH
**Parent:** $BASE_BRANCH
**DbContext:** $DBCONTEXT

## Branch Migrations (to be replaced)

$(for mig in "${BRANCH_MIGRATIONS[@]}"; do echo "- $mig"; done)

## Restore Command

\`\`\`bash
cp "$BACKUP_DIR"/*.cs "$MIGRATIONS_DIR/"
\`\`\`
EOF
```

### 4. Verify Backup

```bash
echo ""
echo "Backup complete:"
echo "  Directory: $BACKUP_DIR"
echo "  Files: $BACKUP_COUNT"
```

---

## STATE OUTPUT:

| Variable | Description |
|----------|-------------|
| `{backup_dir}` | Backup directory path |
| `{backup_count}` | Number of files backed up |

---

## RECOVERY:

```bash
cp "{BACKUP_DIR}"/*.cs "{MIGRATIONS_DIR}/"
```

---

## SUCCESS CRITERIA:

- Backup directory created
- All files copied
- Manifest created

## NEXT STEP:

→ `step-02-fetch.md`
