A friend on mine recently came to me asking for a solution. They had an old site which was being used by a lot of people, then they decided to move it. As they did not had any kind of custom solutions or any other kind of customizations, STSADM export and import seemed to the straight forward way and that’s what they did.
But what happened? They lost the alert settings that everyone had for themselves over those hundreds of lists in the site and their sub-sites !! That too it was noticed after a day or so when some content has already been changed in the the sites.
Now they wanted the alerts back but do not want to do their last days work again, which rules out a restore option from a day old backup. Finally, we settled that we will restore backup to a different sub-site in a farm and then write the code to copy over the alert information to the new site.
But where is the code?? Well, it is given below !! Just provide 2 SPWeb objects, giving the source and destination and it will copy over your alert information.
As always, Happy Coding