ZFS – 从备份中恢复或修复快照中的损坏文件?

池已经遭受永久数据损坏,文件数据是快照的一部分.如果文件数据是文件系统的一部分(而不是任何快照的一部分),我可以简单地从合适的备份副本中恢复文件.如何从快照副本或池的(部分1)副本中恢复或修复(并清除ZFS报告的错误)快照中的文件?

1部分副本至少包含受影响的快照以及受影响的池上的上一个快照.

这是一个易于重现的非常人为的例子:

从(bash)shell提示符:

cd
mkdir zfs-test
for i in {1..2}; do dd if=/dev/zero of=zfs-test/tank-file$i bs=1G count=1 &> /dev/null; done

sudo zpool create tank1 ~/zfs-test/tank-file1
sudo zpool create tank2 ~/zfs-test/tank-file2

sudo zfs snapshot tank1@snapshot1
sudo sh -c 'zfs send tank1@snapshot1 | zfs receive -F tank2'

创建一个文本文件/ tank1 / test-text-file,其中包含可在十六进制编辑器中轻松找到的内容.这是我用过的东西:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.

再次从shell提示符:

sudo zfs snapshot tank1@snapshot2
sudo sh -c 'zfs send -i tank1@snapshot1 tank1@snapshot2 | zfs receive -F tank2'

现在您需要破坏文件数据.我使用ht并搜索“dui”并将其更改为“duh”.

您可以确认数据已损坏:

sudo zpool scrub tank1; sudo zpool status -v tank1
  pool: tank1
 state: ONLINE
status: One or more devices has experienced an error resulting in data
        corruption.  Applications may be affected.
action: Restore the file in question if possible.  Otherwise restore the
        entire pool from backup.
   see: http://zfsonlinux.org/msg/ZFS-8000-8A
  scan: scrub repaired 0 in 0h0m with 1 errors on Sun Jan 11 20:16:30 2015
config:

        NAME                               STATE     READ WRITE CKSUM
        tank1                              ONLINE       0     0     1
          /home/kenny/zfs-test/tank-file1  ONLINE       0     0     2

errors: Permanent errors have been detected in the following files:

        tank1@snapshot2:/test-text-file
最佳答案
使用冗余池而不是非冗余池总是更好(尽管并非总是可行).上面的问题不太可能发生在冗余池上.
克隆快照(从中获取文件)比在某处重新创建快照更快(如果你当然没有对错误硬件的抱怨).

转载注明原文:ZFS – 从备份中恢复或修复快照中的损坏文件? - 代码日志