What is the best way to migrate old data to metadata

What is the best way to migrate old data to metadata

I have been migrate my devices to optimize data storage using metadata, all not relevant variable I add in metadata.
In some cases, some variables is not so much relevant, but we have widgets with this variables, and I have to keep the historic.
What is the best way to migrate old data to metadata to keep widget historic, but using "$METADATA.var$"?