I suggest to copy the storage (file system and database) and restore it against the new Alfresco 4.2.
If you are using the Enterprise edition, then contact the Alfresco Support for the official upgrade path and follow the migration path.
In this way you will have the same noderef of your contents and you will have the same structure of the repo.
If you are using the Community edition you have to consider that each step of the upgrade path is every Community release: 3.4.a->3.4.b, etc…. but anyway the upgrade process is not supported so this means that you could have some issues that you should solve alone or with the help of the Alfresco Community members (forums, mailing list, IRC, etc…).
Another way to do this is to implement a batch application that read contents from your old repo and drop in the new one.
But this requires an important effort. I suggest to follow the first approach.
Hope this helps.