From b955356d7acdbb10bb02cb5f15e5764584e88a68 Mon Sep 17 00:00:00 2001 From: Tero Huttunen Date: Fri, 2 Oct 2026 11:42:03 +0300 Subject: [PATCH] Add more graph --- README.md | 120 +++++++++++++++++++++--------------------- migrate.sh | 52 +++++++++++++++++- nas_list.conf.example | 38 ++++++------- 3 files changed, 129 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index be1ef9c..c98621d 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,60 @@ -# 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///`. Per-share rsync logs are written to -`/mnt/stor0/qnap/_logs/`. - -## 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) | -| `--dry-run` | Pass `--dry-run` to rsync, no changes made | -| `--list-only` | Only discover and print shares, don't transfer | - -QNAP system folders (`@Recycle`, `.@__thumb`, `.system`, snapshots, etc.) are skipped automatically. -Re-running the script is safe/idempotent — rsync only copies new or changed files. +# 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///`. Per-share rsync logs are written to +`/mnt/stor0/qnap/_logs/`. + +## 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) | +| `--dry-run` | Pass `--dry-run` to rsync, no changes made | +| `--list-only` | Only discover and print shares, don't transfer | + +QNAP system folders (`@Recycle`, `.@__thumb`, `.system`, snapshots, etc.) are skipped automatically. +Re-running the script is safe/idempotent — rsync only copies new or changed files. diff --git a/migrate.sh b/migrate.sh index 39692cb..d22f853 100644 --- a/migrate.sh +++ b/migrate.sh @@ -79,11 +79,59 @@ run_rsync() { mkdir -p "$dst" local -a excludes=() mapfile -t excludes < <(rsync_exclude_args) - local -a flags=(-aAXH --partial --info=progress2 "${excludes[@]}") + local -a flags=(-aAXH --partial "${excludes[@]}") [ -n "$ssh_cmd" ] && flags+=(-e "$ssh_cmd") [ "$DRY_RUN" -eq 1 ] && flags+=(--dry-run) log "rsync: $src -> $dst" - rsync "${flags[@]}" "$src" "$dst" 2>&1 | tee -a "$logfile" + + # Plain output when not on a terminal, parallel jobs share the screen, or dry-run. + if [ ! -t 1 ] || [ "$JOBS" -gt 1 ] || [ "$DRY_RUN" -eq 1 ]; then + rsync "${flags[@]}" --info=progress2 "$src" "$dst" 2>&1 | tee -a "$logfile" + return + fi + + log "scanning $src ..." + local total_bytes + total_bytes="$(rsync "${flags[@]}" --dry-run --stats "$src" "$dst" 2>/dev/null \ + | awk -F': ' '/^Total transferred file size/{gsub(/[^0-9]/,"",$2); print $2}')" + total_bytes="${total_bytes:-0}" + + rsync "${flags[@]}" --progress "$src" "$dst" 2>&1 | progress_ui "$total_bytes" "$logfile" +} + +# Reads rsync --progress output; draws current-file bar, total bar and the rolling filename. +progress_ui() { + local total="$1" logfile="$2" cols + cols="$(tput cols 2>/dev/null || echo 80)" + awk -v total="$total" -v logf="$logfile" -v cols="$cols" ' + function human(b, u, i) { + split("B KB MB GB TB", u, " "); i = 1 + while (b >= 1024 && i < 5) { b /= 1024; i++ } + return sprintf("%.1f%s", b, u[i]) + } + function bar(p, w, n, s, i) { + if (p > 100) p = 100 + n = int(p * w / 100); s = "" + for (i = 0; i < w; i++) s = s (i < n ? "#" : "-") + return "[" s "]" + } + function render( tp, shown) { + tp = (total > 0) ? (done + curb) * 100 / total : 0 + shown = substr(name, 1, cols - 4) + printf "\033[3A\r\033[2K File %s %3d%% %s\n", bar(cp, 30), cp, rate + printf "\033[2K Total %s %3d%% %s / %s, %d files\n", bar(tp, 30), tp, human(done + curb), human(total), files + printf "\033[2K > %s\n", shown + } + BEGIN { RS = "[\r\n]"; printf "\n\n\n" } + /^[ \t]+[0-9,]+[ \t]+[0-9]+%/ { + b = $1; gsub(",", "", b); curb = b + 0; cp = $2 + 0; rate = $3 + if (cp >= 100 && !counted) { done += curb; counted = 1; curb = 0 } + render(); next + } + /^(sending|building|receiving|sent |total size|created)/ || $0 == "" { next } + { name = $0; print name >> logf; counted = 0; curb = 0; cp = 0; files++; render() } + END { if (total > 0) { done = total; curb = 0 } cp = 100; render() } + ' } # ---------- SSH method ---------- diff --git a/nas_list.conf.example b/nas_list.conf.example index 26c7b7a..8e37e7b 100644 --- a/nas_list.conf.example +++ b/nas_list.conf.example @@ -1,19 +1,19 @@ -# QNAP -> TrueNAS migration inventory -# One line per QNAP NAS. Fields are whitespace separated (use quotes for values with spaces). -# Copy this file to nas_list.conf and edit it for your environment. -# -# name method host user auth shares -# ------ ------- -------------- ------- --------------------------- ----------------- -# name : short identifier, used for dest folder + log file names (no spaces) -# method : ssh | smb | nfs -# host : hostname or IP of the QNAP NAS -# user : username to connect with (SMB/SSH). Use "-" for NFS. -# auth : ssh -> path to SSH private key, or "-" to use ssh-agent/default key -# smb -> path to a credentials file (username=.. / password=..), or "-" to be prompted -# nfs -> "-" (not used) -# shares : "ALL" to auto-discover every share, or a comma separated list of share names -# -qnap1 ssh 192.168.1.10 admin /root/.ssh/id_qnap1 ALL -qnap2 smb 192.168.1.11 admin /root/.smbcreds_qnap2 ALL -qnap3 nfs 192.168.1.12 - - ALL -# qnap4 ssh 192.168.1.13 admin - Public,Multimedia,Backups +# QNAP -> TrueNAS migration inventory +# One line per QNAP NAS. Fields are whitespace separated (use quotes for values with spaces). +# Copy this file to nas_list.conf and edit it for your environment. +# +# name method host user auth shares +# ------ ------- -------------- ------- --------------------------- ----------------- +# name : short identifier, used for dest folder + log file names (no spaces) +# method : ssh | smb | nfs +# host : hostname or IP of the QNAP NAS +# user : username to connect with (SMB/SSH). Use "-" for NFS. +# auth : ssh -> path to SSH private key, or "-" to use ssh-agent/default key +# smb -> path to a credentials file (username=.. / password=..), or "-" to be prompted +# nfs -> "-" (not used) +# shares : "ALL" to auto-discover every share, or a comma separated list of share names +# +qnap1 ssh 192.168.1.10 admin /root/.ssh/id_qnap1 ALL +qnap2 smb 192.168.1.11 admin /root/.smbcreds_qnap2 ALL +qnap3 nfs 192.168.1.12 - - ALL +# qnap4 ssh 192.168.1.13 admin - Public,Multimedia,Backups