---
title: "CLI Export"
description: "Export TraceRTM data for backup, migration, or integration with external tools"
keywords: [cli, export, backup, migration, json, csv, yaml]
---

# CLI Export

Export projects, items, links, and related data from TraceRTM for backup, migration, or integration with external tools.

## Export Formats

The CLI supports multiple export formats:

| Format | Extension | Use Case |
|--------|-----------|----------|
| JSON | `.json` | Backup, migration, programmatic processing |
| CSV | `.csv` | Spreadsheet analysis, reporting |
| YAML | `.yaml` | Human-readable, version control |
| Markdown | `.md` | Documentation, reports |
| Excel | `.xlsx` | Business reporting |

---

## Export Project

### Complete Project Export

```bash
# Export entire project
trace export project proj_abc123 --format json --output project.json
```

### Export with Options

```bash
# Export with all related data
trace export project proj_abc123 \
  --format json \
  --include items,links,workflows,settings \
  --output project.json
```

### Export Specific Resources

```bash
# Export only items
trace export project proj_abc123 \
  --format json \
  --include items \
  --output items.json

# Export only links
trace export project proj_abc123 \
  --format json \
  --include links \
  --output links.json
```

### Export to Different Formats

```bash
# JSON
trace export project proj_abc123 --format json --output project.json

# CSV
trace export project proj_abc123 --format csv --output project.csv

# YAML
trace export project proj_abc123 --format yaml --output project.yaml

# Markdown
trace export project proj_abc123 --format markdown --output project.md

# Excel
trace export project proj_abc123 --format xlsx --output project.xlsx
```

---

## Export Items

### Export All Items

```bash
# Export all items
trace export items --project proj_abc123 --format json --output items.json
```

### Export with Filters

```bash
# Export specific view
trace export items \
  --project proj_abc123 \
  --view requirements \
  --format json \
  --output requirements.json

# Export by status
trace export items \
  --project proj_abc123 \
  --status approved \
  --format json \
  --output approved.json

# Export by date range
trace export items \
  --project proj_abc123 \
  --created-after "2024-01-01" \
  --created-before "2024-12-31" \
  --format json \
  --output items_2024.json
```

### Export with Related Data

```bash
# Include links
trace export items \
  --project proj_abc123 \
  --include links \
  --format json \
  --output items_with_links.json

# Include history
trace export items \
  --project proj_abc123 \
  --include history \
  --format json \
  --output items_with_history.json

# Include all related data
trace export items \
  --project proj_abc123 \
  --include all \
  --format json \
  --output items_complete.json
```

---

## Export Links

### Export All Links

```bash
# Export all links
trace export links --project proj_abc123 --format json --output links.json
```

### Export by Type

```bash
# Export specific link type
trace export links \
  --project proj_abc123 \
  --type verified_by \
  --format json \
  --output verified_by_links.json

# Export multiple types
trace export links \
  --project proj_abc123 \
  --type verified_by,implements \
  --format json \
  --output traceability_links.json
```

### Export Link Matrix

```bash
# Export as traceability matrix
trace export links \
  --project proj_abc123 \
  --format matrix \
  --output traceability_matrix.csv
```

---

## Export Reports

### Coverage Report

```bash
# Export coverage report
trace export coverage \
  --project proj_abc123 \
  --source-type requirement \
  --target-type test_case \
  --format json \
  --output coverage.json
```

### Traceability Matrix

```bash
# Export traceability matrix
trace export matrix \
  --project proj_abc123 \
  --row-type requirement \
  --col-type test_case \
  --format csv \
  --output matrix.csv
```

### Impact Analysis

```bash
# Export impact analysis
trace export impact \
  --item item_req_001 \
  --depth 5 \
  --format json \
  --output impact.json
```

---

## Export Options

### Compression

```bash
# Compress export
trace export project proj_abc123 \
  --format json \
  --compress \
  --output project.json.gz
```

### Filtering

```bash
# Export with filters
trace export items \
  --project proj_abc123 \
  --view requirements \
  --status approved \
  --priority high \
  --format json \
  --output high_priority_approved.json
```

### Pagination

```bash
# Export in chunks
trace export items \
  --project proj_abc123 \
  --limit 1000 \
  --offset 0 \
  --format json \
  --output items_part1.json

trace export items \
  --project proj_abc123 \
  --limit 1000 \
  --offset 1000 \
  --format json \
  --output items_part2.json
```

---

## Export Examples

### Complete Backup

```bash
#!/bin/bash

PROJECT_ID="proj_abc123"
BACKUP_DIR="backups/$(date +%Y%m%d)"
mkdir -p "$BACKUP_DIR"

# Export project
trace export project "$PROJECT_ID" \
  --format json \
  --include all \
  --output "$BACKUP_DIR/project.json"

# Export items separately
trace export items \
  --project "$PROJECT_ID" \
  --format json \
  --include all \
  --output "$BACKUP_DIR/items.json"

# Export links
trace export links \
  --project "$PROJECT_ID" \
  --format json \
  --output "$BACKUP_DIR/links.json"

# Compress
tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"

echo "Backup created: $BACKUP_DIR.tar.gz"
```

### Export for Migration

```bash
#!/bin/bash

# Export for migration to another instance
trace export project proj_source \
  --format json \
  --include items,links,workflows \
  --output migration.json

# Verify export
jq '.items | length' migration.json
jq '.links | length' migration.json
```

### Export for Reporting

```bash
#!/bin/bash

# Export to Excel for business reporting
trace export project proj_abc123 \
  --format xlsx \
  --include items,links \
  --output report.xlsx

# Or export to CSV
trace export items \
  --project proj_abc123 \
  --view requirements \
  --format csv \
  --output requirements.csv
```

### Scheduled Exports

```bash
#!/bin/bash

# Daily export script
DATE=$(date +%Y%m%d)
PROJECT_ID="proj_abc123"

trace export project "$PROJECT_ID" \
  --format json \
  --output "/backups/project_${DATE}.json"

# Keep only last 30 days
find /backups -name "project_*.json" -mtime +30 -delete
```

---

## Export Formats

### JSON Format

```json
{
  "project": {
    "id": "proj_abc123",
    "name": "My Project",
    "key": "MP"
  },
  "items": [
    {
      "id": "item_req_001",
      "title": "User Authentication",
      "status": "approved",
      "links": [...]
    }
  ],
  "links": [
    {
      "id": "link_001",
      "source_id": "item_req_001",
      "target_id": "item_tc_001",
      "type": "verified_by"
    }
  ]
}
```

### CSV Format

```csv
id,title,status,priority,view
item_req_001,User Authentication,approved,high,requirements
item_tc_001,Login Test,passed,high,test-cases
```

### YAML Format

```yaml
project:
  id: proj_abc123
  name: My Project
items:
  - id: item_req_001
    title: User Authentication
    status: approved
links:
  - id: link_001
    source_id: item_req_001
    target_id: item_tc_001
    type: verified_by
```

---

## Best Practices

### 1. Always Use --project

```bash
# Good: Explicit project
trace export items --project proj_123 --format json

# Bad: Relies on default project
trace export items --format json
```

### 2. Verify Exports

```bash
# Check export file
trace export project proj_123 --format json --output export.json

# Verify structure
jq '.items | length' export.json
jq '.links | length' export.json

# Verify data integrity
jq '.items[] | select(.id == null)' export.json
```

### 3. Use Compression for Large Exports

```bash
# Compress large exports
trace export project proj_123 \
  --format json \
  --compress \
  --output export.json.gz
```

### 4. Export Incrementally

```bash
# Export only recent changes
trace export items \
  --project proj_123 \
  --updated-after "$(date -d '7 days ago' -Iseconds)" \
  --format json \
  --output recent_changes.json
```

### 5. Include Metadata

```bash
# Export with all metadata
trace export project proj_123 \
  --include all \
  --format json \
  --output complete_export.json
```

---

## Related Documentation

- [CLI Import](./08-import) - Import data
- [CLI Commands](./03-commands) - All CLI commands
- [Backup Strategies](/docs/wiki/guides/backup-restore/backup-strategies) - Backup best practices
