Add more graph

This commit is contained in:
2026-10-02 11:42:03 +03:00
parent 604f0abfb0
commit b955356d7a
3 changed files with 129 additions and 81 deletions
+60 -60
View File
@@ -1,60 +1,60 @@
# QNAP → TrueNAS Migration # QNAP → TrueNAS Migration
Copies all shares from one or more QNAP NAS devices into TrueNAS SCALE datasets. 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). 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 ## 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. - **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. - **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. - **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 ## 2. Configure the NAS list
```bash ```bash
cp nas_list.conf.example nas_list.conf 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 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). (`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 For `ssh` entries, generate the key pair(s) referenced in the `auth` column and install them on
each QNAP: each QNAP:
```bash ```bash
chmod +x generate_ssh_keys.sh chmod +x generate_ssh_keys.sh
./generate_ssh_keys.sh --copy # creates missing keys, prompts once per QNAP to install them ./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. Run it again without `--copy` any time to just (re)generate missing keys without touching the QNAP.
## 3. Dry run first ## 3. Dry run first
```bash ```bash
chmod +x migrate.sh chmod +x migrate.sh
./migrate.sh --list-only # just show discovered shares per NAS ./migrate.sh --list-only # just show discovered shares per NAS
./migrate.sh --dry-run # simulate the full rsync, no files written ./migrate.sh --dry-run # simulate the full rsync, no files written
``` ```
## 4. Run for real ## 4. Run for real
```bash ```bash
./migrate.sh ./migrate.sh
``` ```
Data lands under `/mnt/stor0/qnap/<nas-name>/<share-name>/`. Per-share rsync logs are written to Data lands under `/mnt/stor0/qnap/<nas-name>/<share-name>/`. Per-share rsync logs are written to
`/mnt/stor0/qnap/_logs/`. `/mnt/stor0/qnap/_logs/`.
## Options ## Options
| Flag | Description | | Flag | Description |
|----------------|------------------------------------------------------------| |----------------|------------------------------------------------------------|
| `--config FILE`| Use a different NAS list (default `./nas_list.conf`) | | `--config FILE`| Use a different NAS list (default `./nas_list.conf`) |
| `--dest DIR` | Destination root (default `/mnt/stor0/qnap`) | | `--dest DIR` | Destination root (default `/mnt/stor0/qnap`) |
| `--only NAME` | Only process one NAS entry by name | | `--only NAME` | Only process one NAS entry by name |
| `--jobs N` | Number of NAS devices to process in parallel (default 1) | | `--jobs N` | Number of NAS devices to process in parallel (default 1) |
| `--dry-run` | Pass `--dry-run` to rsync, no changes made | | `--dry-run` | Pass `--dry-run` to rsync, no changes made |
| `--list-only` | Only discover and print shares, don't transfer | | `--list-only` | Only discover and print shares, don't transfer |
QNAP system folders (`@Recycle`, `.@__thumb`, `.system`, snapshots, etc.) are skipped automatically. 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. Re-running the script is safe/idempotent — rsync only copies new or changed files.
+50 -2
View File
@@ -79,11 +79,59 @@ run_rsync() {
mkdir -p "$dst" mkdir -p "$dst"
local -a excludes=() local -a excludes=()
mapfile -t excludes < <(rsync_exclude_args) 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") [ -n "$ssh_cmd" ] && flags+=(-e "$ssh_cmd")
[ "$DRY_RUN" -eq 1 ] && flags+=(--dry-run) [ "$DRY_RUN" -eq 1 ] && flags+=(--dry-run)
log "rsync: $src -> $dst" 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 ---------- # ---------- SSH method ----------
+19 -19
View File
@@ -1,19 +1,19 @@
# QNAP -> TrueNAS migration inventory # QNAP -> TrueNAS migration inventory
# One line per QNAP NAS. Fields are whitespace separated (use quotes for values with spaces). # 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. # Copy this file to nas_list.conf and edit it for your environment.
# #
# name method host user auth shares # name method host user auth shares
# ------ ------- -------------- ------- --------------------------- ----------------- # ------ ------- -------------- ------- --------------------------- -----------------
# name : short identifier, used for dest folder + log file names (no spaces) # name : short identifier, used for dest folder + log file names (no spaces)
# method : ssh | smb | nfs # method : ssh | smb | nfs
# host : hostname or IP of the QNAP NAS # host : hostname or IP of the QNAP NAS
# user : username to connect with (SMB/SSH). Use "-" for NFS. # user : username to connect with (SMB/SSH). Use "-" for NFS.
# auth : ssh -> path to SSH private key, or "-" to use ssh-agent/default key # 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 # smb -> path to a credentials file (username=.. / password=..), or "-" to be prompted
# nfs -> "-" (not used) # nfs -> "-" (not used)
# shares : "ALL" to auto-discover every share, or a comma separated list of share names # 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 qnap1 ssh 192.168.1.10 admin /root/.ssh/id_qnap1 ALL
qnap2 smb 192.168.1.11 admin /root/.smbcreds_qnap2 ALL qnap2 smb 192.168.1.11 admin /root/.smbcreds_qnap2 ALL
qnap3 nfs 192.168.1.12 - - ALL qnap3 nfs 192.168.1.12 - - ALL
# qnap4 ssh 192.168.1.13 admin - Public,Multimedia,Backups # qnap4 ssh 192.168.1.13 admin - Public,Multimedia,Backups