Repairing a Time Machine backup

Apple’s Time Machine can be considered a revolution in creating backups for average users. Plug in a hard drive, set it for Time Machine and it just works. When Apple introduced the Time Capsule routers, they brought this ease of use to devices that didn’t have a dedicated external hard drive for backups. For the most part, this worked as well but there are sometimes issues.

When using Time Machine connecting to a Time Capsule, NAS, or other file server, a disc image in the form of a sparse bundle is created for each machine that is connected to the server. The sparse bundle is basically a wrapper that contains the hard drive. Inside of the wrapper are many files called bands that contain the data. This bundle grows as more data is added which is great. Unfortunately if something happens such as unplugging a computer from the network or closing the computer while the disc image is in use, the entire image can become corrupt.

Yesterday I disconnected my Mac from my Thunderbolt Display which was connected to Ethernet during a Time Machine backup. This caused the disc image to become corrupt. Up until now I had just accepted that I’d have to start over with the backup. I spent last week getting a new backup strategy in place and didn’t want to start over again. I did some searching and found a few articles on repairing corrupted sparse bundles. I started with this article but instead of trying to perform the repair on the network, I screen shared to my Mac Pro and attempted to do the recovery locally. Unfortunately the steps outlined failed to repair my disc image. Another article had similar commands but didn’t quite work either. Combining information from the two, I came up with my own steps to repair the image:

Attach to the disc image, but don’t verify it or attempt to mount it. Note the readwrite option as this was key for my repair.

sudo hdiutil attach -nomount -noverify -noautofsck -readwrite /Volumes/Backups/Shared\ Items/Backups/Scott’s\ MacBook\ Pro.sparsebundle

Look at the output that will be something like:

/dev/disk6 Apple_partition_scheme
/dev/disk6s1 Apple_partition_map
/dev/disk6s2 Apple_HFS

Make a note of the disk for the last entry that has HFS in it.

Perform the verification and repair using:

sudo fsck_hfs -drfy /dev/disk6s2

I had to do the above item twice to get a message that the volume was repaired successfully. This will take awhile depending on the damage and size of the disc image.

Once the volume has been repaired, issue the final command

sudo hdiutil detach /dev/disk6s2

After that I did a Time Machine backup and everything worked again! I tested out restoring a file and that worked as well. Now I have a way to fix the disc images when this happens in the future. Apple really needs to do something about this issue as the articles I referenced are 6 and 9 years old meaning this isn’t a new problem.

9 Replies to “Repairing a Time Machine backup”

  1. If you look online you’ll note that numerous Time Capsule people have this happen and are not only forced to start over, they aren’t given a way to get the original and now corrupt and unusable sparse bundle file off the HD. If it gets corrupted after numerous years of backups, it’s quite big. Starting over without getting rid of it is a problem. As far as I know, starting over doesn’t automatically delete the old and useless file.

    As you may remember, I had a “home made Time Capsule” running here for while until this happened to me, then I switched to a local time machine backup and things worked better although were a lot less convenient. I posted about making that setup here:

    https://richardsnotes.org/2016/01/09/home-made-time-capsule/

    and here:

    https://richardsnotes.org/2016/02/21/update-on-home-made-time-capsule/

    Last week I had problems with my first upgrade to High Sierra and so, decided to do a clean install of the OS and migrate my data from my Time Machine backup disk.

    All seemed to go well but after the migration I found that not all of my files were in place and I had hundreds of lines of error messages in the migration assistant application telling me my Time Machine file(s) were corrupt.

    I have no idea if all of this was because of the new file system in High Sierra or what. But, I re-initialized the SSD and did another clean install and then assembled my old setup from scratch and a CCC backup SSD. It was a pain in the ass and I’m not done with it yet and High Sierra still is running badly on my Mac Pro.

    I’ve been on the phone with Apple support (bumped way up) and they’ve pulled lots of data out of my machine to see if they can figure it out.

    In short, I’m not happy at all with this update. My setup was working flawlessly with Sierra and this is the first time I’ve had a major problem with a system update like this. In the future I will avoid doing system updates until the bugs are worked out.

    🙁

    1. Hi Richard,

      I’m sorry to hear about your High Sierra woes. I just finished upgrading a third machine to it and haven’t had any problems. Two of the machines were headless servers which may have not been the best idea at least on the second one that is located about a thousand miles away!

      I definitely don’t recommend that people use Time Machine as their only backup method. I consider it as a secondary, nice to have but if it blew up and I had to start over I only lose the ability to recover an old file. I can probably count on one hand the number of times I’ve had to use Time Machine to recover a file.

      Regular backups using SuperDuper! or Carbon Copy Cloner are a necessity, but sometimes a bit too complex for the average user. In addition having an offsite backup is crucial. I have 3 drives that I rotate for my main machine’s offsite backup and every few weeks take one drive to a safe deposit box. With more and more data automatically being stored in the cloud, a personal backup would save me time in case of a loss but copies of most of my important data resides somewhere else.

      Good luck sorting out your upgrade!

  2. Scott: I too rotate two CCC SSDs with backups (in and out of a firebox in the basement). I use Time Machine as a secondary backup but for a year or so the only way to migrate onto a clean install of Mac OS was Time Machine, SuperDuper didn’t work. Now things seem better.

    I’m not sure what happened during my High Sierra update but something is definitely not right. Time will tell.

  3. Just a FYI, this was very helpful for me, but my backup required a slightly different set of switches to correct. Using only -drfy, fsck_hfs could not repair the volume. I had to use -Ra -Re instead of the -r (aka -Rc) to get the filesystem sufficiently repaired that I could access my data. The way my backup was corrupted was something that MacOS does not handle at all – any attempt to access the volume through the OS resulted in an instant kernel panic. Bad enough that Apple support eventually had me take the machine in for service. When I nuked two other Macs trying to access the volume it became clear it was an issue with the backup. Anyway, thanks!

  4. Hi, thanks for these instructions. They worked once before for me but this time I am getting an error:

    Unable to open block device /dev/disk5s2: Operation not permittedjournal_replay(/dev/disk5s2) returned 1
    ** /dev/rdisk5s2 (NO WRITE)
    Can’t open /dev/rdisk5s2: Operation not permitted

    Is there anything I can do to correct this?

    1. I found the answer here:

      https://apple.stackexchange.com/questions/18482/repair-time-machine-sparsebundle-that-will-no-longer-mount

      On macOS Catalina (10.15) I would get an error message like Unable to open block device” /dev/disk2s2: Operation not permitted when running fsck_hfs. Looking in dmesg showed messages like Sandbox: fsck_hfs(2311) System Policy: deny(1) file-read-data /dev/disk2s2. To solve this I went to System Preferences -> Security & Privacy -> Privacy | Full Disk Access and added Terminal. – Anon Jan 1 at 12:02

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.