12

I'm trying to perform a save or bgsave on my redis instance to run through the backup/restore process. I'm getting errors when I try to save however:

532:M 28 Jun 23:58:30.396 # Failed opening the RDB file backup.rdb (in server root dir /var/lib/redis) for saving: Read-only file system

Permissions on the /var/lib/redis folder:

$@/var/lib$ ls -artl | grep redis
drwxrwxrwx  3 redis    redis    4096 Jun 28 23:58 redis

Permissions on the /var/lib folder:

$@/var$ ls -artl | grep lib
drwxrwxrwx 31 root root  4096 Jun 28 23:44 lib

Permissions on the /var folder:

$@/$ ls -artl | grep var
drwxrwxrwx  11 root root  4096 Jul 18  2016 var

Redis CLI output for config get dir:

1) "dir"
2) "/var/lib/redis"

Redis CLI output for config get dbfilename:

1) "dbfilename"
2) "backup.rdb"

Error from redis:

532:M 28 Jun 23:58:30.396 # Failed opening the RDB file backup.rdb (in server root dir /var/lib/redis) for saving: Read-only file system

Any help would be much appreciated!

kaydanzie
  • 386
  • 3
  • 7
  • 17
Ben
  • 169
  • 1
  • 2
  • 8
  • Also, in case anyone is wondering, the /var/lib/redis/ folder is empty. – Ben Jun 29 '17 at 01:24
  • Just to comment that this can also happen if there is not enough memory. In my case, Redis was complaining about a read-only filesystem for /var/spool/cron which was in no configuration file at all. Increasing the VM from 1GB RAM to 2GB and rebooting made it work. Not really a solution, but maybe that saves someone else. – ywarnier Oct 16 '20 at 13:15

2 Answers2

26

You need to add the following to your /etc/systemd/system/redis-server unit file:

ReadWriteDirectories=-/var/lib/redis

Note that /var/lib/redis is the default, but if in your /etc/redis/redis.conf you set a different dir config option, you will need to set ReadWriteDirectories to that.

almel
  • 7,178
  • 13
  • 45
  • 58
  • 9
    In Ubuntu 16.04 the unit file is located at `/etc/systemd/system/redis.service` – Mario Sep 10 '18 at 10:39
  • Great tip, thanks! I did this and everything worked fine for a while, but then suddenly that line simply disappeared from the `/etc/systemd/system/redis.service` file. Any idea how that could have happened? Is this file automatically regenerated/overwritten in some cases? – Andrei O Dec 07 '18 at 12:55
  • 6
    I found out this issue, it turns out this solution is not entirely correct, please see this answer for the correct way to do this: https://serverfault.com/a/943335/498459 – Andrei O Dec 07 '18 at 22:17
  • 1
    Remember to run `sudo systemctl daemon-reload` after the editing the file. – Martin Dec 20 '18 at 13:18
  • 2
    Do not edit the default unit file. Instead create a drop-in with `sytemctl edit`. – OrangeDog May 22 '19 at 15:45
  • My config file already has "ReadWriteDirectories=-/var/lib/redis", what to do? – lucaswxp Aug 29 '19 at 15:03
0

Error says Read-only file system So, check the mounting (/ or /var) of file system, if it is read only, remount the FS with rw mode(read and write mode) Take backup of important data before mounting.

  • 1
    Thanks for the answer! Unfortunately, the mounting seems okay. Redis server is being run by the `redis` user, and when I `sudo su - redis` I can `touch /var/lib/redis/blah.blah` with no errors, and see the file get created. – Ben Jun 29 '17 at 12:55
  • I am always seeing this problem. I've verified by looking at /proc/mount that the directory's filesystem has the `rw` option. – almel Jun 20 '18 at 05:07