<p>You need to check ownership and permissions for the files and folders involved. Your current user needs permissions to <em>read</em> <code>/home/bitcoin/.bitcoin/new_wallet/wallet.dat</code> and permissions to <em>write</em> to the current directory for <code>backup.dat</code></p>
<p>Try <code>ls -ld /home/bitcoin/.bitcoin/new_wallet/wallet.dat .</code> and <code>pwd</code> and <code>id</code>. The permissions will be shown as three triplets for owner, group and others shown as <code>rwxr-x--- 1 bitcoin pi</code> which means the owner (user &quot;bitcoin&quot;) has read, write and execute permissions (<code>rwx</code>), members of the group (&quot;pi&quot;) have only read and execute permission (<code>r-x</code>) and other people have no permissions at all (<code>---</code>). The <code>id</code> command will tell you which groups your current use is a member of. The <code>pwd</code> will tell you the full name of the current directory where you are trying to write your <code>backup.dat</code></p>
<hr />
<p>To further diagnose the problem try</p>
<p>see if the target already exists and can't be overwritten</p>
<pre><code>ls -l backup.dat
mv backup.dat backup.dat.old
echo test &gt; backup.dat
</code></pre>
<p>see if the source file is readable - look for messages <code>no read permission</code></p>
<pre><code>file /home/bitcoin/.bitcoin/new_wallet/wallet.dat
</code></pre>
<p>try to copy it directly</p>
<pre><code>cp /home/bitcoin/.bitcoin/new_wallet/wallet.dat backup.dat
</code></pre>

CC BY-SA 4.0
2020-10-31T01:02:39.757Z
Thanks,  


`ls -ld /home/bitcoin/.bitcoin/new_wallet/wallet.dat` returns "-rw------- 1 bitcoin bitcoin 1462272". 

So the owner (user bitcoin) has read & write permissions, but the group (bitcoin) has no permissions?  

`pwd` returns /home/bitcoin, and `ls -ld /home/bitcoin` returns "drwxr-xr-x 6 bitcoin bitcoin". 


So for the destination folder, user bitcoin has all permissions, but group has r & x only.  

`Id` returns "uid=1001(bitcoin) gid=1001(bitcoin) groups=1001(bitcoin),27(sudo)"
Vanderlow
CC BY-SA 4.0
2020-10-31T09:36:19.417Z
@Vanderlow: see additional suggestions at end of answer.
RedGrittyBrick
CC BY-SA 4.0
2020-11-01T07:44:26.123Z
No filename / overwrite conflicts.

I am able to copy the file using `cp`, so I've tested a backup that way and it works fine.  It's strange that I can read and write using `cp` but am unable to do `backupwallet` from within bitcoind.  Could it be something about bitcoind's permissions??

To backup using `cp` I have to stop the bitcoind server running otherwise the wallet file doesn't get backed up properly.  

That's why I wanted to be able to do it using `backupwallet` so I could do it while bitcoind is still running.  Nevermind.

Thanks for your help @RedGrittyBrick
Vanderlow
CC BY-SA 4.0
2020-10-30T09:47:29.297Z
2020-10-31T09:35:45.463Z
2020-10-31T09:35:45.463Z
RedGrittyBrick
<p>When I call <code>bitcoin@raspberrypi:~ $ bitcoin-cli backupwallet &quot;backup.dat&quot;</code>, I get the following error:</p>
<p>error code: -4</p>
<p>error message:</p>
<p>Error: Wallet backup failed!</p>
<p>~/.bitcoin/debug.log shows the following:</p>
<blockquote>
<p>error copying wallet.dat to backup.dat - boost::filesystem::copy_file: Permission denied: &quot;/home/bitcoin/.bitcoin/new_wallet/wallet.dat&quot;, &quot;backup.dat&quot;</p>
</blockquote>
<p>Is it something I'm doing wrong?  Do I need to give permissions to user &quot;bitcoin&quot;?</p>
<p>The wallet is not encrypted.</p>
<p>Thanks</p>

<bitcoind><wallet><bitcoin-cli><backup>
Permission denied when attempting to backup wallet using backupwallet
Vanderlow
# Permission denied when attempting to backup wallet using backupwallet

(Asked by: username_0 on 2020-10-30)

When I call `bitcoin@raspberrypi:~ $ bitcoin-cli backupwallet "backup.dat"`, I get the following error:

error code: -4

error message:

Error: Wallet backup failed!

~/.bitcoin/debug.log shows the following:

> error copying wallet.dat to backup.dat - boost::filesystem::copy\_file: Permission denied: "/home/bitcoin/.bitcoin/new\_wallet/wallet.dat", "backup.dat"

Is it something I'm doing wrong? Do I need to give permissions to user "bitcoin"?

The wallet is not encrypted.

Thanks

**Tags:** bitcoind, wallet, bitcoin-cli, backup


---

## 1 answers

### Answer by username_1 on 2020-10-30. Score: 2

You need to check ownership and permissions for the files and folders involved. Your current user needs permissions to *read* `/home/bitcoin/.bitcoin/new_wallet/wallet.dat` and permissions to *write* to the current directory for `backup.dat`

Try `ls -ld /home/bitcoin/.bitcoin/new_wallet/wallet.dat .` and `pwd` and `id`. The permissions will be shown as three triplets for owner, group and others shown as `rwxr-x--- 1 bitcoin pi` which means the owner (user "bitcoin") has read, write and execute permissions (`rwx`), members of the group ("pi") have only read and execute permission (`r-x`) and other people have no permissions at all (`---`). The `id` command will tell you which groups your current use is a member of. The `pwd` will tell you the full name of the current directory where you are trying to write your `backup.dat`

---

To further diagnose the problem try

see if the target already exists and can't be overwritten

```
ls -l backup.dat
mv backup.dat backup.dat.old
echo test > backup.dat

```

see if the source file is readable - look for messages `no read permission`

```
file /home/bitcoin/.bitcoin/new_wallet/wallet.dat

```

try to copy it directly

```
cp /home/bitcoin/.bitcoin/new_wallet/wallet.dat backup.dat

```

> **Comments:**
> **username_0**: Thanks,     `ls -ld /home/bitcoin/.bitcoin/new_wallet/wallet.dat` returns "-rw------- 1 bitcoin bitcoin 1462272".   So the owner (user bitcoin) has read & write permissions, but the group (bitcoin) has no permissions?    `pwd` returns /home/bitcoin, and `ls -ld /home/bitcoin` returns "drwxr-xr-x 6 bitcoin bitcoin".    So for the destination folder, user bitcoin has all permissions, but group has r & x only.    `Id` returns "uid=1001(bitcoin) gid=1001(bitcoin) groups=1001(bitcoin),27(sudo)"  
> **username_1**: @username_0: see additional suggestions at end of answer.  
> **username_0**: No filename / overwrite conflicts.  I am able to copy the file using `cp`, so I've tested a backup that way and it works fine.  It's strange that I can read and write using `cp` but am unable to do `backupwallet` from within bitcoind.  Could it be something about bitcoind's permissions??  To backup using `cp` I have to stop the bitcoind server running otherwise the wallet file doesn't get backed up properly.    That's why I wanted to be able to do it using `backupwallet` so I could do it while bitcoind is still running.  Nevermind.  Thanks for your help @username_1  

---

