Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: A script to fix Time Machine after hardware repairs System 10.5
Apparently I have bad luck with MacBooks, because I have found myself going through this Time Machine repair guide with shocking frequency. The process of migrating an old Time Machine backup to a new machine is pretty involved and prone to errors, so I wrote a shell script that gets the job done automatically:
#!/bin/bash
if [[ "$USER" != "root" ]]; then
  echo "You must run this script as root."
  exit 1
fi

VOLUME=`find /Volumes -mindepth 1 -maxdepth 2 -name 'Backups.backupdb' | head -n1 | sed 's/\/Backups.backupdb$//'`
if [[ -z "$VOLUME" ]]; then
  echo "Could not find a Time Machine drive. Please connect a drive and try again."
  exit 1
fi

BACKUP=`ls -d "$VOLUME/Backups.backupdb/"* | head -n1`
if [[ -z "$BACKUP" ]]; then
  echo "Could not find a Time Machine backup on the volume."
  exit 1
fi

OLDMAC=`xattr -p com.apple.backupd.BackupMachineAddress "$BACKUP"`
if [[ -z "$OLDMAC" ]]; then
  echo "Could not discover old MAC."
  exit 1
fi

NEWMAC=`ifconfig en0 | egrep -o 'ether ([0-9a-f]{2}:){5}[0-9a-f]{2}' | cut -c7-`
if [[ -z "$NEWMAC" ]]; then
  echo "Could not discover new MAC."
  exit 1
fi
if [[ "$NEWMAC" = "$OLDMAC" ]]; then
  echo "Found a Time Machine backup, but it's already bound to this machine."
  exit 1
fi

echo "Discovered a Time Machine backup at $BACKUP for MAC: $OLDMAC. Your new MAC is: $NEWMAC."
echo "Press enter to bind this backup to this machine, or Ctrl+C to cancel."
read

fsaclctl -p "$VOLUME" -d && \
mv "$VOLUME/.`echo "$OLDMAC" | sed s/://g`" "$VOLUME/.`echo "$NEWMAC" | sed s/://g`" && \
xattr -w com.apple.backupd.BackupMachineAddress "$NEWMAC" "$BACKUP" && \
OK=1
fsaclctl -p "$VOLUME" -e

if [[ -z "$OK" ]]; then
  echo "Something terrible happened while restoring the backup."
  echo "You're probably worse off now than you were before."
  echo "Sorry. :("
  exit 1
fi

echo "Time Machine backup successfully rebound to this machine. Please eject and reconnect the volume."
echo "Your first Time Machine backup after the restore process may take a really really long time."
echo "Like it might take a day or something, seriously."

It's simple to use:
  1. Copy and paste the entire script to a text file on your Desktop.
  2. Open a terminal, type sudo sh, then press the Space Bar, but do not press Enter/Return yet.
  3. Drag the text file where you saved the script into your Terminal, and then press Enter/Return.
This script will ask you for your password, and then if it discovers an old Time Machine backup, it will ask you if you want to automatically restore it.

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.54 / 5
  You rated: 1 / 5 (13 votes cast)
 
[42,277 views]  

10.5: A script to fix Time Machine after hardware repairs | 24 comments | Create New Account
Click here to return to the '10.5: A script to fix Time Machine after hardware repairs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: A script to fix Time Machine after hardware repairs
Authored by: Russ Brown on Dec 19, '08 08:08:40AM

I do not think you need to do this. They just changed my logic board and I had the Time Machine problem. After searching, I found that all I needed to do was open Time Machine preferences and select Change Disk and re-select the drive that I used before. Did it yesterday and it is running fine.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: makemineamac on Dec 19, '08 11:57:45AM

Unless there has been a change in 10.5.6, choosing another disk only allowed you to do just that. It would build a whole new backup from scratch, not use your existing Time Machine backup.

I too had the logic board failure and could not select the old backup without modifying a number of things. Anyway, if they updated this that's great news. If not, then this script will be a real time saver for people that's for certain.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: marcusology on Jul 15, '11 04:34:31AM

damn it,i did exactly what you said right away,and then found your later reply.
Now I have no chance to get my earlier backups.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: p4ul13 on Dec 19, '08 09:19:33AM

I agree. This seems to just add something else to troubleshoot (the script) if a problem pops up. Better off just following a restore how-to guide.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: Russ Brown on Dec 23, '08 01:28:40PM

MY PREVIOUS COMMENT WAS WRONG! It was based on a posting somewhere else. It looked like it worked if you used "Change Disk", but that made a new folder and new backup and did not continue the old backup, though it is still there.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: Russ Brown on Dec 23, '08 08:21:49PM

THIS WORKS and saved me after being misled by a posting on another blog. Thank you so much, and so easy. My backups now go back to February not just 18 Dec when I got my Mac back.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: V.K. on Dec 25, '08 03:18:37PM

Thanks a lot for the hint! It will certainly help non unix savvy people who had trouble with the original hint that you mentioned. One request for you. Could you modify the script so that it also works with remote TM backups that use sparse bundles?

P.S.
I love this code :)

echo "Something terrible happened while restoring the backup."
echo "You're probably worse off now than you were before."
echo "Sorry. :("



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: ClunkClunk on Jan 23, '09 10:24:12PM

It seems to have worked for me (at least the rebinding of my new MAC address). I didn't have a repair, but I did get a new MacBook Pro and cloned my system to my new machine. I'll update if/when it completes.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: ClunkClunk on Jan 24, '09 10:27:51AM

It only took about an hour for its first successful backup, and has kept my history intact (back to February 13th, 2008).



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: palahala on Jan 24, '09 12:35:38PM

You don't even need to back up first to see how much history your re-paired Time Machine disk gives you. Simply start Time Machine after applying the above hint :-)

(by the way: until recently I did not know how brilliant Time Machine integrates with Apple Mail. Start Time Machine when Mail is active and presto: read emails, even from accounts you've completely deleted. Just back up more often than purging your deleted items...)



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: tinb on Jan 26, '09 07:55:14AM

Great hint!
This worked for me, too. I had to move the HD of my mini into my MacBook Pro - and Time Machine complained.
Luckily the first new back up took only minutes!



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: Zaphod42 on Apr 11, '09 05:00:03PM

This worked great for me, I bought a new MBP and transferred my old HD into the new machine.

running this script re-attached the backup volume.

although, there was an invisible file called ".00224124e6ac" at the root of my time machine HD. Every time i clicked backup now, it would say it couldn't find the backup volume, choosing change disk and reselecting the external HD would result in an error saying that I didn't have permission to edit ".00224124e6ac".

sure enough, after making invisible files visible and getting info on .00224124e6ac, only the system group had write access. I added my user, gave it read/write, re-choose the backup volume and now all is well.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: FightingEntropy on Sep 03, '09 06:56:59PM

Worked great. I had first used Time Machine preferences and ended up with a duplicate back up of my comp. Once I deleted the duplicate backup and ran the script, my Time Machine history stretched back to when I installed Leopard. Nice script!



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: AveryH on Sep 08, '09 10:14:00AM

Thanks for the script. I'm reaching an error that I hope someone can help me out with.

After following the instructions given, once I type in my password and press enter, Terminal gives me the following message:

/Users/avery/Desktop/Repair Time Machine.rtf: line 1: {rtf1ansiansicpg1252cocoartf949cocoasubrtf540: command not found
/Users/avery/Desktop/Repair Time Machine.rtf: line 2: syntax error near unexpected token `}'
/Users/avery/Desktop/Repair Time Machine.rtf: line 2: `{\fonttbl\f0\fnil\fcharset0 Monaco;}'

(Repair Time Machine is what I named the text file with the code.)

Any thoughts to help? Thanks in advance!



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: palahala on Sep 08, '09 10:35:08AM

Seems to me you saved it in Rich Text Format (RTF), which allows for formatting like bold and italic. It should be plain text instead.

In TextEdit, choose menu Format » Make Plain Text. (If the menu says "Make Rich Text", then your file is already plain text.)



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: AveryH on Sep 08, '09 11:03:53AM

Thank you very much, everything is working perfectly now!



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: tlehmann on Oct 06, '09 07:43:32PM

I am having trouble with this script. Any suggestions? I forgot to write down the prompt but it was an sh#3 I think with possibly another # and a 5 maybe. Sorry that is not much help.

The first time I dragged the script I did an all copy and dragged it in which included a "return" at the bottom of the script. This automatically prompted the password but saw it as incorrect and would not allow me to enter the correct password. I believe I got the same prompt.

Any help would be appreciated. I am not a programmer and the terminal is foreign to me. Thanks so much.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: tlehmann on Oct 06, '09 07:55:35PM

Sorry, Here is the prompt I received after running it again.

if [[ -z "Sorry, try again. (this is the end of the script)
Password:
Sorry, try again.
Password: (Unable to enter a password - hit return and got this)
sh-3.2#



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: rkusa on Dec 05, '09 06:45:50PM

Same thing happened to me, but that was because I didn't follow the instructions. I had copied and pasted the script/dragged the script from inside a text file to the Terminal. That's the reason for the error. You have to save the script alone in a file, then drag the actual file icon into the Terminal window. Then it will work as shown. Aside from that, I have another issue I'll post separately.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: rkusa on Dec 05, '09 06:51:24PM

For some reason, mine comes up with the comment that it is already bound to this Mac, but it still tries to create a separate backup. I end up with an inProgress file on the TM drive every time it fails. It still shows the last correct backups. I don't know if this has something to do with the fact that early on when I had this problem I had clicked the Change Disk button and reselected the TM drive, but cancelled the backup while it was preparing, thinking I needed to research it some more.

I've trashed the inProgress files that were leftover from the failed backups and rerun the script, but I still get the same notice that it's already bound, yet still get the fail error for too little space (seemingly because it's trying to do an additional full backup). About half the hard drive's space is available according to TM Pref panel.

Is it thinking that it's already bound to the NEW Mac I might have created when I clicked that Change Disk button, and if so, is there a way to get it to forget that the new Mac backup entity it created? Any ideas? Thanks.

Edited on Dec 05, '09 06:54:50PM by rkusa



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: massimo57 on Jan 17, '10 07:23:51AM

GREAT!

Thank you so much for the script. After I was getting lost with another hint, I finally adopted yours and everything is running just fine. Backing up now. Let's see how long it will take.

Just one little further hint for the unexperienced (like me):

Having tried to backup BEFORE reading this thread, I had a second folder in my Backups.backupdb folder. Since I wasn't just able to trash this folder, I used this procedure in the terminal to disable ACLs temporarily:

1) $ sudo fsaclctl -p /Volumes/the-name-of-your-backup-disk -d

2) I went to the Finder and trashed the second folder as usual and

3) went back to terminal and enabled ACLs again with

$ sudo fsaclctl -p /Volumes/the-name-of-your-backup-disk -e


thank you again for the hint and good luck everybody!

Massimo




[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: shapiro on Mar 28, '10 09:50:11AM

This doesn't work in 10.6 Snow Leopard. Does anyone know how to fix it?



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: llee on Sep 13, '10 09:36:30AM

You might have to get the fsaclctl executable from a Leopard system.



[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: wannatinker on Mar 27, '12 02:04:20AM

It may be a little late, but maybe someone knowledgeable is still around.

I put my old HD into a new mac, tried the script, and it worked. THANK YOU! But I had tried unsuccessfully some other stuff I don't remember clearly, and now there is a funny situation:

TM continues to back up to the old backup as it should (no full backup, only incremental).

But when I go into Time Machine I only get to see the backups since the day the script ran. When i search other Time Machine volumes, however, I get to see them all -- old and new ones together in the timeline. That is really puzzling me.



[ Reply to This | # ]