What you are looking for is the restorewallet
RPC. As of 2/2/2022, this has not been included in a release of Bitcoin Core (although it is in the master code branch on GitHub). It will be included in the v23 release, expected in April 2022.
restorewallet "wallet_name" "backup_file" ( load_on_startup )
Restore and loads a wallet from backup.
Arguments:
1. wallet_name (string, required) The name that will be applied to the restored wallet
2. backup_file (string, required) The backup file that will be used to restore the wallet.
3. load_on_startup (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
Result:
{ (json object)
"name" : "str", (string) The wallet name if restored successfully.
"warning" : "str" (string) Warning message if wallet was not loaded cleanly.
}
Examples:
> bitcoin-cli restorewallet "testwallet" "home\backups\backup-file.bak"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "restorewallet", "params": ["testwallet" "home\backups\backup-file.bak"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
> bitcoin-cli -named restorewallet wallet_name=testwallet backup_file='home\backups\backup-file.bak"' load_on_startup=true
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "restorewallet", "params": {"wallet_name":"testwallet","backup_file":"home\\backups\\backup-file.bak\"","load_on_startup":true}}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
The importwallet
RPC is used in a different scenario, to import a list of keys from a dumpfile (a plaintext list of keys generated by the dumpwallet
RPC).
To restore a backup with v22 and below, simply:
- navigate to your
wallets/
directory in your bitcoin data directory
- create a new directory inside
wallets/
with a unique name of your choice for the restored wallet.
- Copy the wallet file into this newly created directory, and rename it to
wallet.dat
- Start bitcoin core, and you should be able to load the wallet.