Authy has an opt-in feature that allows you to tie your phone number to your account and lock it with a password which makes it relatively easy to restore those 2FA codes as long as you have your original phone number to confirm your identity. You can find more information on how Authy works here.
Google authenticator is trickier as it does not allow you to tie your account to anything. Some suggestions to get around this would be to export your accounts into a QR code(s) and either save that QR code(s) in a safe place or scan it onto a backup phone if you have one. More information about Google Authenticator and alternative ways to back it up here.