Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Redis cannot save dump.rdb because it is not allowed to write there

ErrorFailed opening .rdb for saving: Permission denied

Short answer

Redis writes its snapshot into the directory set by dir, using the account the server runs as. Permission denied means that account cannot write there. Ask the server for its dir, then fix the owner of that folder, or point dir at a folder the redis user owns. Under systemd, also check the unit's sandbox rules.

  • Applies to Redis 7.4, Redis 8, Ubuntu 24.04, systemd 255
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Redis where it writes, and which user the process runs as. The two together show the mismatch.

    redis-cli CONFIG GET dir
    ps -o user= -p "$(pgrep -x redis-server | head -n1)"
  2. 2Match what you see, then jump to its fix

    1. 1The Redis log names the directory it tried to write todir points at a folder the redis user cannot writeFix
    2. 2dir is ./ or the folder you launched redis-server fromRedis was started by hand and dir defaulted to the current folderFix
    3. 3Ownership looks right but the write is still refused under systemdThe systemd unit makes the folder read-only for the serviceFix

What does the error look like?

  • Failed opening .rdb for saving: Permission denied
  • Permission denied

Cause 1 of 3

dir points at a folder the redis user cannot write

1Check

The snapshot goes to the folder named by dir, under the name in dbfilename (default dump.rdb). If dir is a folder the server account does not own, the write is refused.

redis-cli CONFIG GET dir
ls -ld "$(redis-cli CONFIG GET dir | tail -n1)"

2Fix

Make the folder writable for the account Redis runs as, or set dir in redis.conf to a folder that account owns and restart.

sudo chown -R redis:redis /path/from/CONFIG-GET-dir

3Verify

Force a snapshot and read the status.

redis-cli BGSAVE
redis-cli INFO persistence | grep rdb_last_bgsave_status

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

Redis was started by hand and dir defaulted to the current folder

1Check

The default of dir is ./, the working directory of the process. Start redis-server from a read-only or foreign folder and every save fails.

redis-cli CONFIG GET dir

2Fix

Set an explicit dir in the config file you start Redis with, and start Redis with that file.

# redis.conf
dir /var/lib/redis
dbfilename dump.rdb

redis-server /etc/redis/redis.conf

3Verify

The reported dir is the one you set.

redis-cli CONFIG GET dir

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

The systemd unit makes the folder read-only for the service

1Check

systemd can mount parts of the filesystem read-only for a service. Anything outside the paths the unit lists as writable stays blocked, whatever the file owner is. Read the unit's settings.

systemctl cat redis-server | grep -E 'ProtectSystem|ReadWritePaths|ProtectHome'

2Fix

If you moved dir outside the default data folder, add the new path to ReadWritePaths in a drop-in and restart the service.

sudo systemctl edit redis-server
# in the editor add:
# [Service]
# ReadWritePaths=/data/redis
sudo systemctl restart redis-server

3Verify

A snapshot now succeeds.

redis-cli BGSAVE
redis-cli INFO persistence | grep rdb_last_bgsave_status

Confirmed by freedesktop.org

Did this fix it?

How do I stop it coming back?

  • Always set dir and dbfilename explicitly in the config file instead of relying on ./.
  • When you move dir, change the owner and, under systemd, ReadWritePaths in the same change.
  • Alert on rdb_last_bgsave_status not being ok, so a failing save is seen before writes are refused.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.