Handling migration errors and saving the correct pos at each step.

Handling possible migration errors and saving the correct migration position so that after the migration file is fixed, migration can be resumed.