800 GB 数据极限救援!机械硬盘突然掉电后……
怎么说呢,刚刚的心情像是坐了过山车之后去开高铁的感觉。
看我之前文章的都知道,我用树莓派搭建了一个时间胶囊,目前来看效果不错,平稳运行两个多月。然而怪我啊!之前提前通知了今天 06:30 到 17:30 断电,我把可能的数据都保存了。
但是!我唯独忘了那个扔在角落一直吃灰的树莓派!我的机械硬盘还挂在树莓派上!
来电了之后我就懵了,Time Machine 一直报错 Error 30。我也没当回事,随后重启 Mac 和树莓派,结果依旧。
到这里我还是没意识到问题有多严重,问题出在哪里也不知道。于是上网找了找相关信息,结果少的可怜,不过还好我找到了这篇文章。作者说他也遇到了 Error 30。在这里他提到(或是根据我的理解),在树莓派不正常关机后,外置硬盘可能会变成只读状态。
到这里我还是没觉得问题严重在哪里。
他的解决方案是使用 Mac 上的 Disk Utility 对硬盘进行急救即可。
我 umount 掉了接在树莓派上的硬盘,连接到 Mac,弹出的对话框告诉我我没有权限写入文件,macOS 已经尝试修复我的硬盘,然而并不成功,如果有可能,备份文件然后重新格式化硬盘。(大意如此)

其实到这里这篇文章就可以结束了,但是我的数据有 800 GB,我虽然可以把数据拷贝出来,但是我手里也没有另一个 1 TB 的硬盘,怎么办呢?

731.72 GB 的备份文件。
尝试进入磁盘工具手动急救,然而无法进行急救!我甚至无法挂载我的硬盘分区!遂上网查询硬盘无法急救的解决方案。于是我找到了这篇文章。作者和我遇到了相同的问题,硬盘是灰色的无法被挂载。然而这位作者受此链接影响直接进入了单用户模式使用 fsck(File System Check)命令来手动修复他的磁盘。
他是成功了,而我如法炮制却失败了,提示 disk is not readable。
这可麻烦大了。我又回想起手动急救时提示的报错信息,看起来磁盘工具执行了
fsck_hfs -fy -x /dev/disk2s1
命令失败。
而我执行了
fsck_hfs -fy /dev/disk2s1
提示 disk is not readable。也就是说硬盘一直保持不可读状态。

我又回到了报错信息,“键混乱”,“无效的索引键”引起了我的注意。
我猜想应该是断电的时候我的 HDD 目录或者是索引被破坏了。而文件是没有太大问题的。直到我看到了这句话:
文件系统检查退出代码为 8。
我朦朦胧胧的记得我在 Single User Mode 里面看到了这句话。
File System Check Exit Code 8.
于是我在想,这里有没有可能是一个突破口。
搜索了一下这句话,很快找到了 MacRumors 上的这篇帖子。往下翻了翻,用户 Tygernoot 这段很长的话与我的情况有很多相似的地方。我将原文贴上来。
I had a similar issue recently, and it’s a bit worrying.
Two WD HDs (one Mirror and one Elements) were suddenly corrupted. The disks could only be mounted in read-only mode, as Yosemite said they couldn’t be repaired and had to be formatted.
After trying a disk repair, I was only able to (un)mount the disks again by rebooting. They were sort of ‘stuck’ in repair mode in Disk Utility. It also took ages for them to appear after the reboot. I could hear the disk ‘rattling’ (being accessed) for half an hour or so. Once they appeared, the popup came back saying they needed to be formatted.
I moved all the data and formatted them, but I had the same issue come back on the Mirror version! I had another popup that the disk was read-only and needed to be formatted. After a reboot it seemed to work again, but then TM wouldn’t back up the Mirror version any more at random times. Only a reboot would help that (for a short while).
There were some issues with data loss on WD drives in Mavericks if you had the WD software installed. I never had that installed myself though.
So now I’m no longer using the WD Mirror. I used it as a precaution in raid1 to store all my photos, but if the drives keep getting corrupted and TM stops working as well, then it’s not a safe option any more.
I bought an external HD from another manufacturer and stopped using WDs drives with Yosemite.
I reused the other (Elements) drive for a Windows PC now and that seems to be OK so far.
I really don’t know what happened, but it seems quite worrying that two drives were lost at the same time, and that apparently I’m not the only one. I thought it was a rare corruption due to a power surge (although I use a UPS) or perhaps an incorrect disconnect/shut down. But it might as well be Yosemite corrupting the drives…
大意是说他也碰到了相同的情况,硬盘只能以只读模式装载。他能听到硬盘的“咔哒声”(数据被访问的声音),一旦硬盘被推出就无法重新装载,只能通过重新插拔硬盘来重新装载。
这位用户并没有提出实质的解决方案,但是我知道我走对了方向。
到这里我还是不知道应该怎么去修复它。我又往上翻了翻,mikecwest 提议使用 DiskWarrior 这款软件尝试修复一下。
说实话我是不信任各种数据恢复工具的,但是还能怎么办啊,死马当活马医吧。
使用之后发现可以针对目录进行修复,而我前文也提到了有很大几率是目录的问题。
果断重建目录。

软件很贴心的允许在重建目录之前 Preview,结果发现我的 sparsebundle 没丢。

软件提示成功重建目录。并生成了一份报告以应对未来可能的排查。

重建中。
重新在 Disk Utility 里查看,发现已经能正常显示!!!

连接到树莓派
sudo mount /dev/sda1 /mnt/timecapsule
正常装载。
手动执行时间机器备份。
成功开始备份!!!

成功开始备份。
问题解决。
反思与总结:
如果有重要数据在电脑里,还是有个 UPS 更保险。
DiskWarrior 是个神器!然而去软件官网时,那停留在上个世纪的设计让我一度以为丫是个坑钱的软件。(不过看到了支持 macOS Mojave 让我稍稍安心,一开始还在担心兼容问题,这才有了掏钱的动力。)
机械硬盘一定不要突然断电!对潜在断电影响做好准备!