Zend certified PHP/Magento developer

Magento 2 copy SKU value to custom attribute value

I have approx 50000 product in my store. I would like to copy the SKU value to the Custom attribute(custom_sku_field) value for all products.

I think going for SQL query might be risky. so can anyone suggest the programmatically way to update custom attribute value for all products?

I have tried these solutions but it’s not working
Refrance 1
Refrance 2

Any help would be appreciated. Thanks!