There is a lot easier way of doing this.
Please read from my previous post Update/restore - #7 by jhunyan