Last Updated: February 25, 2016
· erebusbat

Dump All Bitcoin Addresses to a GPG Protected Backup

I use the following script to periodically backup my bitcoin private keys in an OOB backup incase my wallet.dat decides to no longer work.

# Unlock Wallet for 1 min
read WP
bitcoind walletpassphrase "$WP" 60

# Dump Addresses to a dated GPG protected file
bitcoind listaddressgroupings \
  | ruby -e '$^\s+"(1[a-z0-9]{30,})"/i).each{|m| pubKey = m[0]; privKey = `bitcoind dumpprivkey #{m[0]}`; puts "Address: #{pubKey}\nPrivkey: #{privKey}\n" }' \
  |  gpg -e -r -o /var/backups/bitcoin/PrivateKeys-$(date +%Y%m%d-%H%M%S).txt.asc

bitcoind walletlock
unset WP