# Data Migration

> Plans and executes data migrations between databases: dumps, restores, validation, and cutover. Use when working with db dump restore or when the user mentions db dump restore.

- Skill: `opknock/data-migration` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/data-migration`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/data-migration/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/data-migration

---


Plans and executes data migrations between databases: dumps, restores, validation, and cutover.

## Agentic Workflow: Read -> Reason -> Act (data-migration)

You are **data-migration** (data) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — data context for `data-migration`
- Domain: Plans and executes data migrations between databases: dumps, restores, validation, and cutover.
- **db-dump-restore**: Backup, transfer, and restore data between PostgreSQL, MySQL, and MongoDB — `pg_dump -h oldhost -U app -Fc appdb > appdb.dump`
- Check `knowledge` and `prerequisites: node.js, python, knex, alembic`

### 2. Reason — think for `data-migration`
- For `db-dump-restore`: Backup, transfer, and restore data between PostgreSQL, MySQL, and MongoDB — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `data-migration` tools
- Tools: `Glob`, `Grep`, `Read`, `Pg_dump`, `Pg_restore` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `data-migration:e0099575`

# Data Migration

Moves data between database systems safely: export, transfer, import, then
validation and cutover.

## When to Use

- Upgrading database engines or versions
- Moving to a new hosting provider
- Consolidating databases

## Real Commands

```bash
# PostgreSQL custom-format dump
pg_dump -h oldhost -U app -Fc appdb > appdb.dump

# Parallel restore with ownership stripped
pg_restore -h newhost -U app -d appdb -j4 --no-owner --clean appdb.dump

# MySQL logical dump
mysqldump -h oldhost -u root -p --single-transaction appdb > appdb.sql
mysql -h newhost -u root -p appdb < appdb.sql

# MongoDB
mongodump --host oldhost --db app --out ./mongo-dump
mongorestore --host newhost --db app ./mongo-dump/app

# Table-level export
pg_dump -h oldhost -U app -Fc --table=public.orders appdb > orders.dump
```

## Validation Checklist

- Row counts match: `pg_restore -l appdb.dump | wc -l` vs restored table count
- Sample values spot check
- `pg_dump` with `--schema-only` on a test first
- Compare checksums: `pg_dump ... | md5sum` on both ends for small dbs

## Best Practices

- Schedule a maintenance window; migrations lock writes
- Test restore on a staging instance first
- Keep the old system readable until validation passes
- Document rollback: keep the dump until the next full backup cycle
- Run `VACUUM ANALYZE` (PG) or `ANALYZE TABLE` (MySQL) after load

## Example Response

Plans the migration with commands per phase, executes dump/transfer/restore,
validates counts, and reports the cutover steps with rollback plan.

## Capabilities

### db-dump-restore
Backup, transfer, and restore data between PostgreSQL, MySQL, and MongoDB

**Parameters:**
- `format` (string): Dump format: -Fc custom, -Fp plain, -Ft tar
- `jobs` (integer): Parallel restore worker count (-j)
- `no-owner` (boolean): Skip ownership clauses on restore

**Commands:**
- `pg_dump -h oldhost -U app -Fc appdb > appdb.dump`
- `pg_restore -h newhost -U app -d appdb -j4 --no-owner appdb.dump`
- `mysqldump -h oldhost -u root -p appdb > appdb.sql`
- `mysql -h newhost -u root -p appdb < appdb.sql`
- `mongodump --host oldhost --db app --out ./mongo-dump`

**Examples:**
- pg_dump -h oldhost -U app -Fc --table=orders appdb > orders.dump
- mongoimport --host newhost --db app --collection users users.json
- pg_dumpall -h oldhost -U postgres > all-dbs.sql

## References
- [PostgreSQL pg_dump docs](https://www.postgresql.org/docs/current/app-pgdump.html)
- [MySQL mysqldump docs](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
- [MongoDB backup docs](https://www.mongodb.com/docs/database-tools/mongodump-mongorestore/)

