Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,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 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[16,863 views]  

10.5: A script to fix Time Machine after hardware repairs | 20 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 whomever 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 Fri, Dec 19 2008 at 8:08AM PST
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 Fri, Dec 19 2008 at 11:57AM PST
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: p4ul13 on Fri, Dec 19 2008 at 9:19AM PST
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 Tue, Dec 23 2008 at 1:28PM PST
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 Tue, Dec 23 2008 at 8:21PM PST
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 Thu, Dec 25 2008 at 3:18PM PST
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 Fri, Jan 23 2009 at 10:24PM PST
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 Sat, Jan 24 2009 at 10:27AM PST
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 Sat, Jan 24 2009 at 12:35PM PST
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 Mon, Jan 26 2009 at 7:55AM PST
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 Sat, Apr 11 2009 at 5:00PM PDT
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 Thu, Sep 3 2009 at 6:56PM PDT
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 Tue, Sep 8 2009 at 10:14AM PDT
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 Tue, Sep 8 2009 at 10:35AM PDT
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 Tue, Sep 8 2009 at 11:03AM PDT
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 Tue, Oct 6 2009 at 7:43PM PDT
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 Tue, Oct 6 2009 at 7:55PM PDT
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 Sat, Dec 5 2009 at 6:45PM PST
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 Sat, Dec 5 2009 at 6:51PM PST
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 Sat, Dec 5 2009 at 6:54PM PST by rkusa


[ Reply to This | # ]
10.5: A script to fix Time Machine after hardware repairs
Authored by: massimo57 on Sun, Jan 17 2010 at 7:23AM PST
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 | # ]