本帖最后由 fejich 于 2019-8-5 18:29 编辑
开始之前
于 DSM 6.1.7 系统测试通过
最优方式应该是原生程序运行,期待未来会有人编译做出 spk 安装包我是弄不来了。
SnapRAID 这软件我也是刚刚开始使用,据说适合存有大量大文件并很少改动的家庭媒体中心。
详细优缺点,自行搜索了解
SnapRAID 是什么
SnapRAID 是一个目录级别的冗余存储方案,它与 RAID 的原理有相似的地方,但它并不是 RAID。
SnapRAID 与 RAID 的主要区别有:
SnapRAID 不会对数据进行条带化存储。RAID 通常会使用数据条带化,一个文件可能会被分散存储到多块磁盘上,这样的优点是读取的时候可以加速(多块磁盘同时读取),但条带化也是上节所说的 data lock-in 的根源——你不能拆出一块盘单独读写。
SnapRAID 是工作于文件系统之上的。RAID 工作于文件系统之下,直接对磁盘区块进行操作,用磁盘区块上的比特计算校验数据,而 SnapRAID 是通过读取文件系统里的文件之后再进行计算的。
SnapRAID 是非实时的。RAID 每时每刻都在工作,磁盘区块上的数据一旦发生变更就会重新计算校验数据,而 SnapRAID 可以在用户选择的时间进行重新计算。
SnapRAID 相比 RAID 的优点主要有:
数据独立。不需要对磁盘做特殊处理,可以直接将已有数据的磁盘(甚至可以是不同文件系统的)加入 SnapRAID,SnapRAID 也不会改变这些已有的数据;一个文件不会被分散到多个磁盘,随时可以拆下来一块磁盘正常读写里面的数据;当磁盘阵列收到文件读写请求时,也只需要一块磁盘响应,而不是所有的磁盘全部从待机状态启动,开始寻道。
抗灾能力。当磁盘列阵中同时损坏的磁盘数量超出预期而无法修复数据时,SnapRAID 的抗灾能力更强。例如:在 3 + 1 的 RAID 场景下,坏一块没事,如果同时坏了两块,所有的磁盘上的数据都将无法读取(因为条带化);但如果是 3 + 1 的 SnapRAID,就算同时坏两块,剩下两块里的数据依然可以正常读取。
配置灵活。标准的 RAID 等级中,RAID 5 最多承受 1 块磁盘同时损坏,RAID 6 最多承受 2 块磁盘同时损坏;而 SnapRAID 可以配置 1 到 6 块校验盘,最多承载 6 块磁盘同时损坏,因此可以组建更大的磁盘阵列而不提升风险(维持数据盘与校验盘的比例不变)。更重要的是,无论是增加还是减少磁盘,SnapRAID 都可以无痛完成,无需清空磁盘数据。
恢复误删文件。由于 RAID 是实时计算校验数据的,当文件被删除时,这一改动立刻就会被同步到校验数据里;而 SnapRAID 在用户请求的时候才进行同步,因此用户可以用 SnapRAID 从校验数据重新构建被误删除的文件。当然了,更可靠、更持久的的误删除防护还是应该用增量备份来完成。
空间利用率高。在磁盘阵列中,校验盘的大小应大于等于数据盘中最大的那块。使用 SnapRAID 时,你可以「超售」。比如数据盘是 6 TB 的但是只装了一半(3 TB),你把 4 TB 的磁盘作为校验盘也是可以的(因为此时校验数据最多只有 3 TB),只要在校验文件膨胀到接近 4 TB 的时候将校验文件挪到更大的磁盘里即可。同样的,校验盘里未被校验文件填满的剩余空间也可以用来存储一些「丢了也无所谓」的不重要数据。此外,由于 SnapRAID 工作于文件系统之上,你可以选择性地排除掉一些不想做冗余的目录和文件,以节省空间。
摘录自:wzyboy’s blog 目录级别的冗余存储:SnapRAID
使用经验可以参考此博文,非常受用
安装
Docker 注册表里边搜索 snapriad ,选择xagaba/snapraid项目
Docker.png (57.63 KB, 下载次数: 0)
2019-8-5 18:11 上传
1)需要配置一个 /config 目录存放 snapraid.conf , snapraid-runner.conf 两个配置文件(见帖子最后)
2)需要保护的目录挂载到 /mnt 下
3)按挂载的路径配置好 snapraid.conf 文件, snapraid-runner.conf 按需改动,我默认配置了校验完成后进行数据擦洗同时开启了 log。
4)环境变量 PUID ,PGID 用 SSH 登陆机器,输入 id 命令可以得知。应该都是统一的数字,跟图片设置就行
这个设置事关文件读写权限,配置好减少隐患与后续可能的麻烦
ID.png (2.96 KB, 下载次数: 0)
2019-8-5 18:11 上传
使用
软件需要使用 docker exec 参数传递命令来操作
sync 命令建立校验数据,视乎硬盘数据量所需的时间可能要数小时
sudo docker exec SnapRAID snapraid sync复制代码
sync.png (42.65 KB, 下载次数: 3)
2019-8-5 18:18 上传
常用的 SnapRAID 命令:
snapraid sync:根据数据盘生成校验盘;
snapraid diff:查看有哪些数据需要 sync;
snapraid status:查看磁盘阵列的状态;
snapraid scrub:进行数据擦洗,提早发现磁盘阵列中的错误。SnapRAID 首次同步完成之后,可以将 snapraid sync 和 snapraid scrub 加入 cron / systemd timer,定时运行。后者默认配置下每次运行擦洗全部数据的 8%,并且会挑选最近 10 天内没有被擦洗过的数据进行擦洗。如果每天运行一次 snapraid scrub 的话,每 12.5 天所有数据都会被擦洗一遍,形成一个健康的循环。
当擦洗发现有数据损坏,或是更糟糕地,某天整块磁盘挂了(不转了),就需要修复数据了。这时候应该做的是停掉所有的定时任务,然后换上新的磁盘,然后用 snapraid fix -d name_of_disk 命令,根据健在磁盘的内容,在新磁盘里重建坏掉磁盘里的内容。只要坏掉的磁盘数量小于等于校验盘的数量,SnapRAID 都能完整地修复数据。
由于 snapraid sync 是定期执行的,这意味着在下次同步之前,磁盘阵列是有机会恢复到上次同步的状态的,因此 snapraid fix 除了可以重建整个磁盘,也可以重建单个文件,也就是反删除。如果你误删除了文件,可以用 snapraid fix -f path/to/file 来恢复文件到上次同步时的状态。摘录自:wzyboy’s blog 目录级别的冗余存储:SnapRAID
计划任务
1)这个项目自带的 corntab 计划任务,默认每天北京时间 08:30 定时运行(容器是 UTC 时间)
想更灵活的自定时间可以用
sudo docker exec SnapRAID crontab -r复制代码命令把容器的 corntab 计划删了,改用群晖自带的任务计划手动运行的效果
fejich@PVE-DSM:~$ sudo docker exec SnapRAID /usr/bin/python /app/snapraid-runner/snapraid-runner.py -c /config/snapraid-runner.conf
2019-08-05 00:51:03,168 [INFO ] ============================================================
2019-08-05 00:51:03,169 [INFO ] Run started
2019-08-05 00:51:03,169 [INFO ] ============================================================
2019-08-05 00:51:03,169 [INFO ] Running diff…
2019-08-05 00:51:03,175 [OUTPUT] Loading state from /config/snapraid.content…
2019-08-05 00:51:03,175 [OUTPUT] Comparing…
2019-08-05 00:51:03,176 [OUTPUT] add F06中孔铁油缸-4.0s.PDF.pdf
2019-08-05 00:51:03,176 [OUTERR] WARNING! UUID is unsupported for disks: 'mnt1', 'mnt2', 'mnt3'. Noons.
2019-08-05 00:51:03,176 [OUTPUT]
2019-08-05 00:51:03,177 [OUTPUT] 14 equal
2019-08-05 00:51:03,177 [OUTPUT] 1 added
2019-08-05 00:51:03,177 [OUTPUT] 0 removed
2019-08-05 00:51:03,178 [OUTPUT] 0 updated
2019-08-05 00:51:03,178 [OUTPUT] 0 moved
2019-08-05 00:51:03,178 [OUTPUT] 0 copied
2019-08-05 00:51:03,178 [OUTPUT] 0 restored
2019-08-05 00:51:03,178 [OUTPUT] There are differences!
2019-08-05 00:51:03,479 [INFO ] ************************************************************
2019-08-05 00:51:03,479 [INFO ] Diff results: 1 added, 0 removed, 0 moved, 0 modified
2019-08-05 00:51:03,480 [INFO ] Running sync…
2019-08-05 00:51:03,482 [OUTPUT] Self test…
2019-08-05 00:51:03,858 [OUTPUT] Loading state from /config/snapraid.content…
2019-08-05 00:51:03,859 [OUTPUT] Scanning disk mnt1…
2019-08-05 00:51:03,859 [OUTPUT] Scanning disk mnt2…
2019-08-05 00:51:03,860 [OUTPUT] Scanning disk mnt3…
2019-08-05 00:51:03,860 [OUTPUT] Using 0 MiB of memory for the file-system.
2019-08-05 00:51:03,860 [OUTERR] WARNING! UUID is unsupported for disks: 'mnt1', 'mnt2', 'mnt3'. Noons.
2019-08-05 00:51:05,860 [OUTPUT] Initializing…
2019-08-05 00:51:05,860 [OUTPUT] Resizing…
2019-08-05 00:51:05,860 [OUTPUT] Saving state to /config/snapraid.content…
2019-08-05 00:51:05,860 [OUTPUT] Saving state to /mnt1/snapraid.content…
2019-08-05 00:51:05,870 [OUTPUT] Verifying /config/snapraid.content…
2019-08-05 00:51:05,870 [OUTPUT] Verifying /mnt1/snapraid.content…
2019-08-05 00:51:05,871 [OUTPUT] Syncing…
2019-08-05 00:51:06,093 [OUTPUT] Using 32 MiB of memory for 32 cached blocks.
2019-08-05 00:51:06,095 [OUTPUT] 100% completed, 1 MB accessed in 0:00
2019-08-05 00:51:06,102 [OUTPUT]
2019-08-05 00:51:06,102 [OUTPUT] mnt1 0% |
2019-08-05 00:51:06,102 [OUTPUT] mnt2 0% |
2019-08-05 00:51:06,103 [OUTPUT] mnt3 0% |
2019-08-05 00:51:06,103 [OUTPUT] parity 0% |
2019-08-05 00:51:06,103 [OUTPUT] raid 28% | *****************
2019-08-05 00:51:06,103 [OUTPUT] hash 9% | *****
2019-08-05 00:51:06,103 [OUTPUT] sched 60% | *************************************
2019-08-05 00:51:06,103 [OUTPUT] misc 0% |
2019-08-05 00:51:06,104 [OUTPUT] |______________________________________________________________
2019-08-05 00:51:06,104 [OUTPUT] wait time (total, less is better)
2019-08-05 00:51:06,104 [OUTPUT]
2019-08-05 00:51:06,104 [OUTPUT] Everything OK
2019-08-05 00:51:06,108 [OUTPUT] Saving state to /config/snapraid.content…
2019-08-05 00:51:06,109 [OUTPUT] Saving state to /mnt1/snapraid.content…
2019-08-05 00:51:06,111 [OUTPUT] Verifying /config/snapraid.content…
2019-08-05 00:51:06,111 [OUTPUT] Verifying /mnt1/snapraid.content…
2019-08-05 00:51:06,413 [INFO ] ************************************************************
2019-08-05 00:51:06,413 [INFO ] All done
2019-08-05 00:51:06,430 [ERROR ] Failed to send email because smtp host is not set
2019-08-05 00:51:06,430 [INFO ] Run finished successfully复制代码
2)群晖计划任务
用户自定义脚本.png (73.14 KB, 下载次数: 0)
2019-8-5 18:25 上传
docker exec SnapRAID /usr/bin/python /app/snapraid-runner/snapraid-runner.py -c /config/snapraid-runner.conf复制代码没权限上传附件直接把配置文件贴出来
snapraid.conf
# 校验文件的位置
# 显然,校验文件不能放在数据盘上,否则就没有意义了
parity /config/snapraid.parity
#3-parity G:\SnapRaid\snapraid.3.parity
# 如需添加更多的校验文件则继续添加
# 最多是 6 份校验,承受磁盘磁盘阵列中最多同时坏掉 6 块盘的情况
#2-parity /media/disk4/snapraid.2-parity
#3-parity /media/disk5/snapraid.3-parity
# 重要的索引文件,建议保存多份(内容是一样的)
# 我在系统盘(SSD)上存了一份,然后在三块磁盘上都各存一份
# 系统盘上的这份同时又会被 BorgBackup 异地备份
content /config/snapraid.content
content /mnt1/snapraid.content
#content /mnt3/snapraid.content
#content /media/disk2/snapraid.content
#content /media/disk3/snapraid.content
# 指定数据盘及其挂载点
# 这里不一定要写确切的挂载点,可以是这块盘上的任意目录
# 目录以外的内容会被完全忽略
data mnt1 /mnt1
data mnt2 /mnt2
data mnt3 /mnt3
# 忽略所有隐藏文件和目录(不做冗余)
# 在 Unix-like 里就是 . 开头的文件和目录
# 在 Windows 里就是带隐藏属性的文件和目录
nohidden
# 排除列表与包含列表,注意顺序!下文详解
exclude *.unrecoverable
exclude *.nobackup
exclude *.nobackup/
exclude /tmp/
exclude /lost+found/
#include /foo
#include /bar/
# 生成校验数据时,每处理 10 GiB 数据自动保存一次,方便断点继续
autosave 10复制代码snapraid-runner.conf
[snapraid]
; path to the snapraid executable (e.g. /bin/snapraid)
; 全部需要写绝对路径
executable = /usr/bin/snapraid
; path to the snapraid config to be used
config = /config/snapraid.conf
; abort operation if there are more deletes than this, set to -1 to disable
deletethreshold = 40
[logging]
; logfile to write to, leave empty to disable
file = /config/snapraid.log
; maximum logfile size in KiB, leave empty for infinite
maxsize = 5000
[email]
; when to send an email, comma-separated list of [success, error]
sendon = success,error
; set to false to get full programm output via email
short = true
subject = [SnapRAID] Status Report:
from =
to =
; maximum email size in KiB
maxsize = 500
[smtp]
host =
; leave empty for default port
port =
; set to "true" to activate
ssl = false
user =
password =
[scrub]
; set to true to run scrub after sync
enabled = true
percentage = 12
older-than = 10复制代码
原文链接:https://blog.csdn.net/weixin_39793794/article/details/110775599?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522c970f0594cfc65f19845f12fd809ba4f%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=c970f0594cfc65f19845f12fd809ba4f&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-27-110775599-null-null.nonecase&utm_term=%E7%BE%A4%E6%99%96%E9%83%A8%E7%BD%B2