To create a backup of your GPG Key, you may use one of the following commands
paperkey --secret-key my-secret-key.gpg --output to-be-printed.txt
Or using this if you have exported (not armored) GPG Key in file:
paperkey --secret-key my-secret-key.gpg --output to-be-printed.txt
To restore it you will need a paperkey data in file and you public key. The following command will take public key from public-key.gpg file and paperkey data from secret-paperkey.gpg file and will import it to ~/.gnupg.
$ paperkey --pubring public-key.gpg --secrets secret-paperkey.gpg | gpg --import
If you have armored gpg public key, you will need to dearmor it first by doing this:
$ gpg --dearmor public-key.gpg
To install it on your mac, you may use brew:
$ brew install paperkey
Paperkey by David Shaw
Thanks!