前言 需求很简单,将绿联 NAS 内的东西都备份到极空间内,我先尝试了将硬盘取下来放到极空间,挂载不上
然后就是通过 webdav/ftp/smb 等协议来备份,但是最后我开始尝试用 rsync,这样同步二者的时间戳可以保留,然后我更相信这个命令一点
经过之前的教训,我不相信绿联以及极空间任何 UI 上提供的功能
用 rsync 来完成 绿联 NAS 到极空间的备份,中途我在极空间用 FTP 从绿联备份了一些文件,用 rsync 应该能继续备份
就是中途用 FTP,感觉慢得不行,特别到了一些小文件的时候,感觉 rsync 要快很多
准备工作 绿联和极空间都需要开启 ssh
极空间是 ubuntu,绿联是 debian,绿联连清华源都没设置
绿联 apt install neofetch 需要执行 apt –fix-broken install
然后极空间默认更换了清华的源
极空间相关信息 ssh 登录后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Welcome to ZOS (GNU/Linux 6.8.1-z4pro+-generic x86_64) ZZZZZZZ OOO SSSSS ZZ O O SS ZZ O O SSSS ZZ O O SS ZZ O O SS ZZZZZZZ OOO SSSS --------------------------------- System: "V1.0.0440020" Service: "V1.0.0440102" --------------------------------- The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Could not chdir to home directory /home/${phone} : No such file or directory To run a command as administrator (user "root" ), use "sudo <command>" . See "man sudo_root" for details. ${phone} @Z4ProPlus-MEDO:/$
然后输入 sudo passwd 可以设置极空间 root 密码
随后可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ➜ ~ ssh -p 10000 root@192.168.31.64 root@192.168.31.64's password: Welcome to ZOS (GNU/Linux 6.8.1-z4pro+-generic x86_64) ZZZZZZZ OOO SSSSS ZZ O O SS ZZ O O SSSS ZZ O O SS ZZ O O SS ZZZZZZZ OOO SSSS --------------------------------- System: "V1.0.0440020" Service: "V1.0.0440102" --------------------------------- Last login: Sun Aug 17 05:27:33 2025 from 127.0.0.1 root@Z4ProPlus-MEDO:~#
apt 版本和源
1 2 3 4 root@Z4ProPlus-MEDO:~# apt -v apt 2.8.3 (amd64) root@Z4ProPlus-MEDO:~# cat /etc/apt/sources.list deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble main
neofetch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 root@Z4ProPlus-MEDO:~ GPU: Intel Graphics] Memory: 1481MiB / 15771MiB
1 2 root@Z4ProPlus-MEDO:~# uname -a Linux Z4ProPlus-MEDO 6.8.1-z4pro+-generic #13 SMP PREEMPT_DYNAMIC Thu Jun 5 15:03:23 CST 2025 x86_64 x86_64 x86_64 GNU/Linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 root@Z4ProPlus-MEDO:~# hostnamectl Static hostname: Z4ProPlus-MEDO Icon name: computer-desktop Chassis: desktop 🖥️ Machine ID: a251d735b2c44028b37bda6e9fddb2f7 Boot ID: de28c0eeb73e45608d22b5d1efe46031 Operating System: zos Kernel: Linux 6.8.1-z4pro+-generic Architecture: x86-64 Hardware Vendor: Default string Hardware Model: Default string Firmware Version: 5.27 Firmware Date: Thu 2025-04-10 Firmware Age: 4month 1w
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 root@Z4ProPlus-MEDO:~# cat /etc/os-release NAME="ZOS" VERSION="GNU/Linux ZOS" ID="zos" ID_LIKE="debian" PRETTY_NAME="zos" VERSION_ID="zos" ZOS_VERSION="V1.0.0440020" root@Z4ProPlus-MEDO:~# lsb_release -a No LSB modules are available. Distributor ID: ZOS Description: zos Release: zos Codename: n/a root@Z4ProPlus-MEDO:~#
绿联 NAS 相关信息 绿联 ssh 登录后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ➜ ~ ssh nightmare@192.168.31.70 nightmare@192.168.31.70's password: nightmare@DXP2800-JECT:~$ apt -v apt 2.6.1 (amd64) nightmare@DXP2800-JECT:~$ cat /etc/apt/sources.list deb https://deb.debian.org/debian/ bookworm contrib main non-free non-free-firmware deb-src https://deb.debian.org/debian/ bookworm contrib main non-free non-free-firmware deb https://deb.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware deb-src https://deb.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware deb https://deb.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware deb-src https://deb.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware deb https://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware deb-src https://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware deb https://deb.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware deb-src https://deb.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 nightmare@DXP2800-JECT:~$ neofetch _,met$$$$$gg . nightmare@DXP2800-JECT ,g$$$$$$$$$$$$$$$P . ---------------------- ,g$$P " " "" Y$$.". OS: Debian GNU/Linux 12 (bookworm) x86_64 ,$$P ' `$$$. Host: DXP2800 EM_DXP2800_V1.0.25 ',$$P ,ggs. `$$b : Kernel: 6.1.27 `d$$' ,$P " ' . $$$ Uptime: 9 hours, 44 mins $$P d$' , $$P Packages: 1225 (dpkg) $$: $$. - ,d$$' Shell: bash 5.2.15 $$; Y$b._ _,d$P' Terminal: /dev/pts/0 Y$$. `.`"Y$$$$P " ' CPU: Intel N100 (4) @ 3.400GHz `$$b "-.__ GPU: Intel Alder Lake-N [UHD Graphics] `Y$$ Memory: 1248MiB / 7684MiB `Y$$. `$$b. `Y$$b. `"Y$b._ `"""
1 2 3 4 5 6 7 8 9 10 11 nightmare@DXP2800-JECT:~$ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" OS_VERSION=1.7.0.3125
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 nightmare@DXP2800-JECT:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 12 (bookworm) Release: 12 Codename: bookworm nightmare@DXP2800-JECT:~$ hostnamectl Static hostname: DXP2800-JECT Icon name: computer-desktop Chassis: desktop 🖥️ Machine ID: 986ee82ffb1876a93eee9ea5bbeab5a5 Boot ID: 14170c1f5dee40c89519b3b4ef3e6926 Operating System: Debian GNU/Linux 12 (bookworm) Kernel: Linux 6.1.27 Architecture: x86-64 Firmware Version: EM_DXP2800_V1.0.25 nightmare@DXP2800-JECT:~$ cat /etc/*release cat /etc/issue PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" OS_VERSION=1.7.0.3125 UGOSPRO Linux \n \l
1 2 nightmare@DXP2800-JECT:~$ uname -a Linux DXP2800-JECT 6.1.27 #36 SMP PREEMPT_DYNAMIC Mon Apr 14 23:38:49 CST 2025 x86_64 GNU/Linux
绿联 sudo passwd 设置 root 密码,然后执行 su
仍然进不到 root
开始尝试 找到极空间的磁盘路径 /data_s001/data/udata/real/${phone}
在极空间上执行
1 rsync -avhP nightmare@192.168.31.70:/home/nightmare/ /data_s001/data/udata/real/${phone}/rsync_test
尝试将绿联的文件往本地拉
总是跑不通,home/nightmare/
文件夹是存在的
1 2 3 4 5 6 ug_start_server, check access user: 1000, group: 10 getuid(): 1000 geteuid(): 1000 login group is admin, set euid as root cannot set euid as root receiving incremental file list rsync: [sender] change_dir "nightmare" (in home) failed: No such file or directory (2)
但是极空间是可以设置 root 密码的
最后方案 在绿联上
1 2 screen -S backup rsync -avhP -e "ssh -p 10000" /home/nightmare/ root@192.168.31.64:/data_s001/data/udata/real/${phone}/rsync_test/
用 screen 命令是为了断开 ssh 还能继续拷贝
TODO ssh-copy-id nightmare@192.168.31.70 作用?
rsync 备份核心命令(绿联 → 极空间) 一些 QA
推送: rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
含义: -a 等价 -rlptgoD,保留权限/时间戳/符号链接等 -v 显示传输文件 -h 人类可读大小 -P 显示进度并支持断点续传(含 –partial –progress)
加删除同步(镜像,谨慎): rsync -avhP –delete -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
后台(screen): screen -S backup rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/ Ctrl+A D 分离 screen -r backup 重新进入
后台(nohup 日志): nohup rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/ > /home/nightmare/rsync_$(date +%Y%m%d_%H%M%S).log 2>&1 &
时间戳保证 -a 已包含 -t,完成后用 stat 对比: stat /home/nightmare/某文件 stat /data_s001/data/udata/real/${phone}/rsync_test/某文件 Modify 行一致即成功。
若看到 failed to set times 说明目标权限或挂载阻止设置时间。
差异判定机制 默认判定:文件大小 + 修改时间 两者都相同直接跳过,不读取文件内容。 需要内容级别核对时临时用 –checksum(-c)。
一次性内容校验 首次全量同步完成后执行(不写入,仅验证,慢): rsync -avhP -e “ssh -p 10000” –dry-run -ic /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/ 如果没有出现以 >f 开头的文件行,表示内容一致。
之后日常继续用不带 -c 的命令(快): rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
快速差异演练(不做内容哈希) rsync -avhP -e “ssh -p 10000” –dry-run -i /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
-i 与 -c 解释 -i 输出变化标志:
f.st…… 文件大小和时间变 f+++++++++ 新文件 f..t…… 仅时间不同
-c 基于内容校验和决定是否需要同步,需读取两端所有文件,慢。
组合 –dry-run -ic 用于严格一次性内容验证。
已传文件列表格式化 仅列出真正传输的文件(时间 + 标志 + 名字): rsync -aP -e “ssh -p 10000” -i –out-format=’%t %i %n’ /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
写日志: rsync -aP -e “ssh -p 10000” -i –out-format=’%t %i %n’ –log-file=/home/nightmare/rsync_transfer.log /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
排除示例 排除缓存与无意义文件: rsync -avhP -e “ssh -p 10000” –exclude ‘.cache/‘ –exclude ‘.DS_Store’ /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
后台脚本 /home/nightmare/push_backup.sh: #!/usr/bin/env bash rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
后台版本 /home/nightmare/push_backup_bg.sh: #!/usr/bin/env bash LOG=”/home/nightmare/rsync_$(date +%Y%m%d_%H%M%S).log” echo “Log => $LOG” nohup rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/ > “$LOG” 2>&1 & echo “PID=$!”
校验抽样 stat /home/nightmare/Release.zip stat /data_s001/data/udata/real/${phone}/rsync_test/Release.zip
何时使用 –delete 需要让目标与源完全一致(删除目标多余文件)时再加: rsync -avhP –delete -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/ 先用 –dry-run 演练: rsync -avhP –dry-run –delete -i -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
典型流程总结 1 初次同步: rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
2 一次性内容验证: rsync -avhP –dry-run -ic -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
3 日常增量: rsync -avhP -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
4 定期快速检查: rsync -avhP –dry-run -i -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/
5 需要镜像: rsync -avhP –delete -e “ssh -p 10000” /home/nightmare/ root@192.168.31.64 :/data_s001/data/udata/real/${phone}/rsync_test/