make sure that only one process can enter the migration mode

This patch prohibit that multiple processes enter the migration mode which could lead to multiple encrypted files.

cc @FlorinPeter would be great if you could have a look at it!