Recovering a broken Time Machine backup

Hopefully I will never need to look at this again, but I went through a lot of trouble making it work, so here it is.

Prep/Intro?

  1. Set up a VM (or physical box) with Ubuntu 14.04.6. I used 4c/16GB with a 100GB root drive and a 600GB data drive. Probably should have made that 800GB for the size of my backup. You can use NFS to augment disk space as necessary but your speeds will suffer greatly. And this process is already pretty slow.
  2. My .sparsebundle file was just shy of 300GB, generated in el Capitan, backed up to a synology NAS, then that was tar.gz'd and thrown into an archive
  3. Copied that tar.gz to the /data (600GB) partition, decompressed, and sync'd
  4. Software! You use two tools for this: sparsebundlefs to mount the sparsebundle and tmfs (timemachine filesystem) to deal with all the crazy hardlinks that time machine generates
  5. Sparsebundlefs is here but I've uploaded it here, tmfs is currently in the Ubuntu repos but I've put the deb here
  6. A numbered list didn't make sense for this section, but whatever

Do it

  • Bullets!
  • Shamelessly ripped from here: https://superuser.com/a/1361335
  • Verify that tmfs and sparsebundlefs are which-able (tmfs will install /usr/bin or whatever, I threw sparsebundlefs there as well)
  • #!/bin/bash
    SB="/path/to/your/Backup.sparsebundle"
    TM_MNT="/path/to/where/to/mount"
    
    # Make directories
    mkdir -p "$TM_MNT"
    SB_MNT=`mktemp --tmpdir -d sparsebundle_mnt.XXX`
    SB_DMG="$SB_MNT/sparsebundle.dmg"
    HFS_MNT=`mktemp --tmpdir -d hfsx_mnt.XXX`
    
    # Mount the sparse bundle
    sudo `which sparsebundlefs` "$SB" "$SB_MNT"
    
    # Mount the HFS+ partition
    OFF=`sudo parted "$SB_DMG" unit B print | tr 'B' ' ' | awk '/hfsx/ {print $2}'`
    SZ=`sudo parted "$SB_DMG" unit B print | tr 'B' ' ' | awk '/hfsx/ {print $4}'`
    LO=`sudo losetup -f "$SB_DMG" --offset $OFF --sizelimit $SZ --show`
    sudo mount -t hfsplus -r "$LO" "$HFS_MNT"
    
    # Mount the Time Machine filesystem
    sudo `which tmfs` "$HFS_MNT" "$TM_MNT" -ouid=$(id -u $USER),gid=$(id -g $USER),allow_other
    
  • The above code block should just work straight up. If it didn't, I don't know, reboot or something. It took a couple of tries for me, and I never got it working in Ubuntu 16.04 or 18.04, but 14.04 worked fine.
  • When you copy the data out, sync after operation. I had some buggy behavior if I didn't - but that may just be configuration issues on my side. Regular syncing never hurt anything, though.
  • I did most of my copying to the local partition, but eventually ran out of space. I was able to do smaller directories as individual chunks, but for the big ones I ended up backing them up straight over NFS to my file server.
  • rsync had problems with the hard links, and often would get caught in weird backup loops and try and backup the same sets of files over and over. Good 'ol cp -R gave me no such problems.
  • When you're done (or after a failed attempt at running the above scripts) issue these commands to wipe out all the variables set by the script:
    sudo umount "$TM_MNT"
    sudo rmdir "$TM_MNT"
    sudo umount "$HFS_MNT"
    sudo rmdir "$HFS_MNT"
    sudo losetup -d "$LO"
    sudo umount "$SB_MNT"
    sudo rmdir "$SB_MNT"

What did we learn?

Time Machine may be fine for one-off file recovery on a working system, but it SUCKS as an archival method. Don't do it.

timemachine_recovery.txt · Last modified: 2019/09/19 09:12 by admin
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0