ZFS - Recover or repair a corrupted file in a snapshot from backup?
Solution 1:
It's always better to use redundant pools instead of non-redundant pools (though not always possible). The issue above is not likely to happen on a redundant pool. And it's faster to clone a snapshot (to get a file from it) than to recreate it somewhere (if you, of course, have no complaints about faulty hardware).
Solution 2:
Here's my slightly generalized solution:
sudo cp /tank2/test-text-file /tank1/test-text-file
sudo zfs snapshot tank1@snapshot3
sudo sh -c 'zfs send -i tank1@snapshot2 tank1@snapshot3 | zfs receive -F tank2'
sudo zfs rollback -r tank1@snapshot1
sudo sh -c 'zfs send -i tank2@snapshot1 tank2@snapshot3 | zfs receive -F tank1'
sudo zpool scrub tank1; sudo zpool status -v tank1
And assuming there are no other errors reported:
sudo zpool clear tank1
The reason why I created snapshot3
wasn't because it was needed for my (extremely contrived) example but because it's probably a good habit to develop (and I originally wanted to test that it would work, as I'd hoped). If there were any other changes on tank1
since snapshot2
, I'd ideally like to not lose them to recover test-text-file
.