Tuesday, June 29, 2010

iPhone OS 4.0 upgrade. Lost my data and got it back

I recently tried to upgrade my iPhone 3Gs to iPhone OS4.0 using windows

Here's what happened

1. iTunes updated itself.
2. iTunes Backed up iPhone
3. iTunes attempted to upgrade phone.
4. iTunes hung half way through install
5. I rebooted and restarted iTunes and the install completed.
6. iTunes attempted to restore the old backup.
Result: all my data was gone. (texts, emails, notes, photos)... very disappointed.

Next:
I repeated the process.... and tried to reinstall an old backup....

Result:
No luck, turns out the new iTunes update deleted all my old backups ... not happy

How i fixed my phone:
Luckily I use Windows 7 and used the Previous Versions functionality to retrieve old backups.

1. I located the backup folder (usually C:\Documents and Settings\USERNAME\Application Data\Apple Computer\MobileSync\Backup)
2. Right click the backup folder, goto properties>Previous Versions
3. Hopefully you'll see a old version of the backup from a time before you started the process (it should be a large file, mine was 185MB).
4. Copy this file into the Backup folder.
5. Open iTunes and attempt to Restore the backup.

Result:
My phone was updated to OS4 and all my contacts,photos,texts and notes were restored :)

Friday, June 18, 2010

Add a URL to google search

Go to the following page and enter your details:
http://www.google.com/addurl/?continue=/addurl

Hopefully you'll see your site in a few days.

Tuesday, June 15, 2010

Measuring Execution time with powershell

This is an easy one - use measure-command CommandLet

measure-command {
# do your long running action in here, like loading a file
@file = get-content "c:\MyFile.txt"
}

Output Looks like this:
Days : 0
Hours : 0
Minutes : 0
Seconds : 1
Milliseconds : 638
Ticks : 16386148
TotalDays : 1.89654490740741E-05
TotalHours : 0.000455170777777778
TotalMinutes : 0.0273102466666667
TotalSeconds : 1.6386148
TotalMilliseconds : 1638.6148

You can also format the output by piping the output into the Filter-Table commandlet

measure-command {
# do your long running action in here, like loading a file
@file = get-content "c:\MyFile.txt"
} | ft -Property Hours, Minutes, Seconds, Milliseconds

Output Looks like this:
Hours Minutes Seconds Milliseconds
----- ------- ------- ------------
0 0 1 567

PowerShell and Large Files

I recently needed to write a script to get some data from a XML file, in this case all IDs of Topic Elements. Decided to use Powershell but quickly ran into an issue due to the size of the uncompressed file... 127MB. Here's my initial script:

# Get the ids
$File = .\myFile.xml
[xml]$topic = get-content $File
$arrayTopicIds = $topic.TopicResults.Topic | %{$_.Authors.Author} | %{$_.Id}

Needless to say, it consumed all my memory and froze my machine.

Undeterred, I turned to the -FilterScript. Rather than use an XML object, I used the get-content commandlet to load the file into an array of end-line-delimited strings. And since i knew the pattern i was looking for i was able to use the -FilterScript command to filter the processed lines. At the same time also formatted the string to how i wanted it:

# Get the ids
#$topic = get-content $File | Where-Object -FilterScript { $_ -ilike “*Author id=*” } | %{ $_ - replace "" } | %{ $_.Trim() }

Simple and ended up running in under 4 minutes. Which was nice.