Files

91 lines
4.3 KiB
Markdown

# QNAP → TrueNAS Migration
Copies all shares from one or more QNAP NAS devices into TrueNAS SCALE datasets.
Run **on the TrueNAS box as root** — it pulls data from each QNAP (nothing to install on QNAP besides enabling the service you choose below).
## 1. Enable access on each QNAP
- **ssh** (recommended, fastest, preserves permissions best): Control Panel → Telnet/SSH → enable SSH. Copy a TrueNAS SSH public key into the QNAP admin user's `~/.ssh/authorized_keys` for passwordless auth.
- **smb**: make sure the shares are accessible to an admin/user account over SMB.
- **nfs**: Control Panel → Network & File Services → NFS service, and allow the TrueNAS host/IP in each share's NFS permissions.
## 2. Configure the NAS list
```bash
cp nas_list.conf.example nas_list.conf
```
Edit `nas_list.conf` — one line per QNAP, see comments in the file for the column format
(`name method host user auth shares`). Mix methods freely (e.g. one QNAP over ssh, another over smb).
For `ssh` entries, generate the key pair(s) referenced in the `auth` column and install them on
each QNAP:
```bash
chmod +x generate_ssh_keys.sh
./generate_ssh_keys.sh --copy # creates missing keys, prompts once per QNAP to install them
```
Run it again without `--copy` any time to just (re)generate missing keys without touching the QNAP.
## 3. Dry run first
```bash
chmod +x migrate.sh
./migrate.sh --list-only # just show discovered shares per NAS
./migrate.sh --dry-run # simulate the full rsync, no files written
```
## 4. Run for real
```bash
./migrate.sh
```
Data lands under `/mnt/stor0/qnap/<nas-name>/<share-name>/`. Per-share rsync logs are written to
`/mnt/stor0/qnap/_logs/`; script messages go to `_logs/migrate.log` while the dashboard is shown.
### Progress dashboard
On a terminal, one block per QNAP is shown (also with `--jobs N`):
```
qnap1 share Photos 3/12 (copying)
File [##########--------------------] 34% 12.3MB/s
Total [######------------------------] 21% 4.2GB / 20.0GB, 183 files
> Photos/2023/IMG_0042.jpg
```
- `File` is the file currently being copied; `Total` is the current share (sized by a dry-run scan before each share, so large shares pause briefly while "scanning").
- Plain rsync output is used instead with `--dry-run`, `--list-only`, non-terminal output, or when an `smb` entry uses `-` (interactive password prompt).
### Stopping
Ctrl+C (or `kill`) stops all rsync/ssh/smbclient processes, unmounts temporary CIFS/NFS mounts and closes SSH connections.
The SSH method reuses one multiplexed connection per NAS, so a key passphrase is asked only once.
## Options
| Flag | Description |
|----------------|------------------------------------------------------------|
| `--config FILE`| Use a different NAS list (default `./nas_list.conf`) |
| `--dest DIR` | Destination root (default `/mnt/stor0/qnap`) |
| `--only NAME` | Only process one NAS entry by name |
| `--jobs N` | Number of NAS devices to process in parallel (default 1) |
| `--retries N` | Retries after a failed network operation (default 3) |
| `--retry-delay SEC` | Seconds between retries (default 5) |
| `--dry-run` | Pass `--dry-run` to rsync, no changes made |
| `--list-only` | Only discover and print shares, don't transfer |
| `--no-ui` | Disable the progress dashboard, use plain rsync output |
QNAP system folders (`@Recycle`, `.@__thumb`, `.system`, snapshots, etc.) are skipped automatically.
Network discovery, mounts, and each rsync transfer are retried (three retries by default); SSH
connections also use keepalives and timeouts. Interrupted file data is kept in rsync's
`.rsync-partial` directories. If all retries fail, the script exits with an error but retains
completed files and partial data. Fix the connection and run the script again: rsync skips files
that already match and resumes/re-copies incomplete or changed files. Per-share logs identify
transfers that still need attention.
If the files were edited on Windows, strip CRLF line endings on TrueNAS before running:
`sed -i 's/\r$//' migrate.sh generate_ssh_keys.sh nas_list.conf`