<p>What you are looking for is the <code>restorewallet</code> 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.</p>
<pre><code>restorewallet &quot;wallet_name&quot; &quot;backup_file&quot; ( 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)
  &quot;name&quot; : &quot;str&quot;,       (string) The wallet name if restored successfully.
  &quot;warning&quot; : &quot;str&quot;     (string) Warning message if wallet was not loaded cleanly.
}

Examples:
&gt; bitcoin-cli restorewallet &quot;testwallet&quot; &quot;home\backups\backup-file.bak&quot;
&gt; curl --user myusername --data-binary '{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;: &quot;curltest&quot;, &quot;method&quot;: &quot;restorewallet&quot;, &quot;params&quot;: [&quot;testwallet&quot; &quot;home\backups\backup-file.bak&quot;]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
&gt; bitcoin-cli -named restorewallet wallet_name=testwallet backup_file='home\backups\backup-file.bak&quot;' load_on_startup=true
&gt; curl --user myusername --data-binary '{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;: &quot;curltest&quot;, &quot;method&quot;: &quot;restorewallet&quot;, &quot;params&quot;: {&quot;wallet_name&quot;:&quot;testwallet&quot;,&quot;backup_file&quot;:&quot;home\\backups\\backup-file.bak\&quot;&quot;,&quot;load_on_startup&quot;:true}}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

</code></pre>
<p>The <code>importwallet</code> RPC is used in a different scenario, to import a list of keys from a dumpfile (a plaintext list of keys generated by the <code>dumpwallet</code> RPC).</p>
<p>To restore a backup with v22 and below, simply:</p>
<ol>
<li>navigate to your <code>wallets/</code> directory in your bitcoin data directory</li>
<li>create a new directory inside <code>wallets/</code> with a unique name of your choice for the restored wallet.</li>
<li>Copy the wallet file into this newly created directory, and rename it to <code>wallet.dat</code></li>
<li>Start bitcoin core, and you should be able to load the wallet.</li>
</ol>

CC BY-SA 4.0
2022-02-02T05:34:37.467Z
I am getting this error: 

$ bitcoin-cli restorewallet "wallet1" "/home/user/wallet1.backup"
error code: -32601
error message:
Method not found

It seems restorewallet is not included in my version?

$ bitcoind  --version
Bitcoin Core version v22.0
aicastell
CC BY-SA 4.0
2022-02-02T06:27:10.397Z
Huh, good point. It was merged in August but only just missed the v22 release. I'll update my answer with an alternative method.
meshcollider
CC BY-SA 4.0
2022-02-02T17:01:27.963Z
That works! :-) This was really helpful both to understand why the "restorewallet" was not found and for the workaround to make this working. I'll check the next version in April. Thank you for the explanation!
aicastell
CC BY-SA 4.0
2022-02-01T22:11:45.780Z
2022-02-02T06:30:33.887Z
2022-02-02T06:30:33.887Z
meshcollider
<p>Just wanted to ask a question about &quot;importwallet&quot; bitcoin-cli command.</p>
<p>After starting my bitcoind daemon, created a wallet, protected with a passphrase and made a backup to a file:</p>
<pre><code>bitcoin-cli createwallet wallet1
bitcoin-cli encryptwallet mypassword
bitcoin-cli backupwallet ~/wallet1.backup
</code></pre>
<p>I want to test if I am able to recover my backuped wallet. This is what I am testing:</p>
<pre><code>bitcoin-cli stop
rm -Rf ~./bitcoin/wallets/wallet1
</code></pre>
<p>And then start again my bitcoind server. At this point I want to import my wallet. I try this:</p>
<pre><code>$ bitcoin-cli importwallet ~/wallet1.backup
error code: -18
error message:
No wallet is loaded. Load a wallet using loadwallet or create a new one with  createwallet. (Note: A default wallet is no longer automatically created)
</code></pre>
<p>But as you can see, the bitcoin-cli is requesting to create a new wallet. Just to import an existing one? I don't understand that point.</p>
<p>For this particular example, what should be the proper way to import the wallet? Tnks!</p>

<bitcoin-cli><wallet-import>
What is the proper way to import a wallet from a file after removing it completely
aicastell
# What is the proper way to import a wallet from a file after removing it completely

(Asked by: username_0 on 2022-02-01)

Just wanted to ask a question about "importwallet" bitcoin-cli command.

After starting my bitcoind daemon, created a wallet, protected with a passphrase and made a backup to a file:

```
bitcoin-cli createwallet wallet1
bitcoin-cli encryptwallet mypassword
bitcoin-cli backupwallet ~/wallet1.backup

```

I want to test if I am able to recover my backuped wallet. This is what I am testing:

```
bitcoin-cli stop
rm -Rf ~./bitcoin/wallets/wallet1

```

And then start again my bitcoind server. At this point I want to import my wallet. I try this:

```
$ bitcoin-cli importwallet ~/wallet1.backup
error code: -18
error message:
No wallet is loaded. Load a wallet using loadwallet or create a new one with  createwallet. (Note: A default wallet is no longer automatically created)

```

But as you can see, the bitcoin-cli is requesting to create a new wallet. Just to import an existing one? I don't understand that point.

For this particular example, what should be the proper way to import the wallet? Tnks!

**Tags:** bitcoin-cli, wallet-import


---

## 1 answers

### Answer by username_1 on 2022-02-01. Score: 3 | Accepted answer

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:

1. navigate to your `wallets/` directory in your bitcoin data directory
2. create a new directory inside `wallets/` with a unique name of your choice for the restored wallet.
3. Copy the wallet file into this newly created directory, and rename it to `wallet.dat`
4. Start bitcoin core, and you should be able to load the wallet.

> **Comments:**
> **username_0**: I am getting this error:   $ bitcoin-cli restorewallet "wallet1" "/home/user/wallet1.backup" error code: -32601 error message: Method not found  It seems restorewallet is not included in my version?  $ bitcoind  --version Bitcoin Core version v22.0  
> **username_1**: Huh, good point. It was merged in August but only just missed the v22 release. I'll update my answer with an alternative method.  
> **username_0**: That works! :-) This was really helpful both to understand why the "restorewallet" was not found and for the workaround to make this working. I'll check the next version in April. Thank you for the explanation!  

---

