npm package: @sehlceris/migrate-openwrt-router-config
Description: Migrate OpenWrt router configurations between any two routers. Transfers VLANs, WiFi SSIDs, firewall rules, DHCP leases, and more — no hardcoded profiles needed.
Author: sehlceris
Latest version: 0.1.1

# migrate-openwrt-router-config

Migrate OpenWrt router configurations between any two routers. Transfers VLANs, WiFi SSIDs/passwords, firewall zones/rules, DHCP static leases, and more — with no hardcoded router profiles.

The tool auto-discovers hardware capabilities (LAN ports, radios, bands, ifname patterns) from backup files and interactively maps your source config onto the destination hardware.

## Disclaimer

This has only been tested with one router transition: Belkin RT3200 (Linksys E8450) → GL-iNET MT6000 (Flint 2)
Although this script should be generic enough and may be worth a try, please note that this has not been tested thoroughly.
Be prepared and able to do a 30/30/30 reset on your router if things go wrong.

## What it migrates

- **VLANs / Bridge VLANs** — network segmentation (LAN, IoT, Guest, Work, etc.)
- **WiFi Networks** — SSIDs, passwords, encryption, band assignments, client isolation
- **Firewall** — custom zones, rules, forwardings, port forwards (deduplicated with destination)
- **DHCP** — static leases, DHCP pools for custom networks

## What it does NOT migrate (kept from destination)

- **Installed packages**
- WAN configuration (device, protocol, metrics)
- Radio hardware settings (channels, tx power, country code)
- SSH keys and certificates
- System hostname and timezone
- Root password
- Vendor-specific configs (GL-iNET, etc.)

## Prerequisites

### 1. Back up both routers

Before running this tool, you need a backup `.tar.gz` from **both** your old (source) and new (destination) routers.

On each router:

1. Open LuCI (usually `http://192.168.1.1`)
2. Go to **System → Backup / Flash Firmware**
3. Click **Generate archive** to download a `.tar.gz` backup

You should end up with two files, e.g.:

- `backup-old-router.tar.gz` — the router you're migrating **from**
- `backup-new-router.tar.gz` — the router you're migrating **to** (fresh or factory-reset)

### 2. System requirements

- Node.js >= 18
- `tar` available in PATH (standard on macOS/Linux)

## Installation

### Via npx (no install needed)

```bash
npx @sehlceris/migrate-openwrt-router-config <source-backup.tar.gz> <dest-backup.tar.gz>
```

### Global install

```bash
npm install -g @sehlceris/migrate-openwrt-router-config
migrate-openwrt <source-backup.tar.gz> <dest-backup.tar.gz>
```

### Local development (npm link)

```bash
git clone https://github.com/sehlceris/migrate-openwrt-router-config.git
cd migrate-openwrt-router-config
npm link
migrate-openwrt <source-backup.tar.gz> <dest-backup.tar.gz>
```

## Usage

### Interactive mode (default)

```bash
migrate-openwrt backup-old-router.tar.gz backup-new-router.tar.gz
```

The tool will:

1. Extract both backups into `source/`, `unmodified/`, and `migrated/` directories (next to the source backup)
2. Show you what it found in each backup
3. Ask you to assign LAN ports to each VLAN/network
4. Ask you which WiFi bands each SSID should broadcast on
5. Show a migration plan summary
6. Apply the migration and create `migrated-<date>.tar.gz`

### Folder mode

If both positional arguments are directories instead of `.tar.gz` files, the tool automatically uses folder mode — no extra flags needed. This is useful for testing and development.

```bash
migrate-openwrt source-config-dir/ dest-config-dir/
```

In folder mode the tool:

- Skips tar extraction and archive creation
- Reads source and destination configs directly from the given directories
- Creates a `migrated/` directory as a sibling of the destination directory
- Overwrites `migrated/` on re-run
- Prints the migrated directory path instead of an archive path

### Non-interactive mode

```bash
migrate-openwrt -y \
  --port-map lan=lan1,lan2,lan3 \
  --port-map iot=lan5 \
  --port-map work=lan4 \
  backup-old.tar.gz backup-new.tar.gz
```

### Options

| Flag                      | Description                                |
| ------------------------- | ------------------------------------------ |
| `-y`, `--non-interactive` | Accept all defaults without prompting      |
| `--port-map NAME=PORTS`   | Assign LAN ports to a network (repeatable) |

### After migration

1. **Review** the files in `migrated/etc/config/` before uploading
2. **Have physical access** to the router in case a factory reset is needed
3. **Set the root password** separately after restoring the backup

## How it works

1. **Extracts** both backup archives
2. **Discovers** destination hardware from its config (bridge ports, radios, ifname patterns, vendor)
3. **Extracts** logical configuration from the source (VLANs, SSIDs, firewall rules, DHCP leases)
4. **Maps** source config onto destination hardware (port assignment, band selection)
5. **Merges** source config into a copy of the destination backup, preserving vendor-specific and hardware-specific settings
6. **Archives** the result as an OpenWrt-compatible backup

## Supported routers

Any OpenWrt-based router should work. Tested with:

- Belkin RT3200 (Linksys E8450) → GL-iNET MT6000 (Flint 2)

The tool handles differences in:

- LAN port count and naming
- WiFi driver types (mac80211 vs mtk)
- Bridge VLAN (DSA) configurations
- Vendor-specific extensions (GL-iNET glconfig, etc.)

## Publishing to npm

```bash
# Log in to npm (one-time)
npm login

# Publish (scoped packages are private by default, use --access public)
npm publish --access public
```

## License

MIT