Repair A Broken Time Machine Backup - 2020-01-05
Abstract
Over time a time machine backup will throw errors that either state that the backup cannot be done because of various reasons or the backup needs to be re-created.
I fixed all errors with the following steps and need to write them down to prevent me from searching for this information again in the future.
Error messages
Recreate backup
Time Machine completed a verification of your backups.
To improve reliability, Time Machine must create a new backup for you.
Backup cannot be done
Time Machine could not complete the backup. (error 45)
Solution
To speed things up it is recommended to copy the backupbundle
(formerly
sparsebundle
) file to your workstation, attach the volume and then run the
disk repair command.
Attach the volume
$ hdiutil attach -nomount -readwrite foobar.backupbundle
/dev/disk2 GUID_partition_scheme
/dev/disk2s1 EFI
/dev/disk2s2 Apple_HFS
Remember the value of the first column on the the Apple_HFS
line!
(/dev/disk2s2
)
This is the partition we’re going to repair.
Run the disk repair command
fsck_hfs -rf /dev/disk2s2
fsck_hfs
is the “HFS file system consistency check” tool.
-r
: Rebuild the catalog btree.-f
: Force fsck_hfs to check and repair journaled HFS+ file systems.
The command takes ages to complete and might look something like this:
$ fsck_hfs -rf /dev/disk2s2
** /dev/rdisk2s2
Executing fsck_hfs (version hfs-522.0.9).
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Rebuilding catalog B-tree.
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking multi-linked directories.
** Checking volume bitmap.
** Checking volume information.
Invalid volume file count
(It should be 10384127 instead of 10079428)
Invalid volume directory count
(It should be 1557312 instead of 1514027)
Invalid volume free block count
(It should be 370750423 instead of 376119386)
Volume header needs minor repair
(2, 0)
** Repairing volume.
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Detected a case-sensitive volume.
The volume name is Time Machine Backups
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking multi-linked directories.
** Checking volume bitmap.
** Checking volume information.
** Trimming unused blocks.
** The volume Time Machine Backups was repaired successfully.
$
Now you need to detach the volume and move it back to the location where it came from (external disk, NAS …).
Detach volume
$ hdiutil detach /dev/disk2
"disk2" ejected.
$
Reset plist
If your error message states that you need to create a new backup, you must also
change two files inside the backupbundle
/sparsebundle
file.
Inside the bundle file, you’ll find these files:
- com.apple.TimeMachine.MachineID.plist
- com.apple.TimeMachine.MachineID.bckup
In both files, you’ll need to remove the following two lines (if they’re present):
<key>RecoveryBackupDeclinedDate</key>
<date>2020-01-04T09:41:40Z</date>
You’ll also need to change the following line:
Before:
<key>VerificationState</key>
<integer>2</integer>
After:
<key>VerificationState</key>
<integer>0</integer>
Done
Good luck.