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.


1 Answer 1


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
  • 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
    Commented Oct 31, 2020 at 1:02
  • @Vanderlow: see additional suggestions at end of answer. Commented Oct 31, 2020 at 9:36
  • 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
    Commented Nov 1, 2020 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.