MISCONF Redis is configured to save RDB snapshots, but it’s currently unable to persist to disk 是线上最容易被搜索的 Redis 报错之一。网上的答案大多是“CONFIG SET stop-writes-on-bgsave-error no”,但这只是让报错消失。这篇在本机把它复现出来,看清楚触发条件、哪些命令受影响、该看哪份日志、怎么真正恢复。
起始: save = '3600 1',stop-writes-on-bgsave-error = yes
顺带:运行时想用 CONFIG SET dir 改目录 -> (error) ERR CONFIG SET failed (possibly related to argument 'dir') - can't set protected config
> BGSAVE
"Background saving started"
rdb_last_bgsave_status = err
> SET k after
(error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
> INCR counter
(error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
> DEL k
(error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
> GET k
"before"
> PING
(error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
> DBSIZE
(integer) 1写命令全部返回 MISCONF,读命令正常,PING 也被拒绝。顺带:运行时 CONFIG SET dir 默认被保护配置拒绝。
* Background saving started by pid 96718 # Failed opening the temp RDB file temp-96718.rdb (in server root dir <rdata>/o10_ro) for saving: Permission denied # Background saving error
客户端报错只说持久化失败;Redis 日志里有 Failed opening the temp RDB file … Permission denied 这样的具体原因。
配置了保存点(save 3600 1),stop-writes yes(默认):rdb_last_bgsave_status = err,SET -> (error) MISCONF Redis is configured to save RDB snapshots, b 没有保存点(save ""),stop-writes yes(默认):rdb_last_bgsave_status = err,SET -> "OK" 配置了保存点,CONFIG SET stop-writes-on-bgsave-error no:rdb_last_bgsave_status = err,SET -> "OK"
需要同时有保存点、上次 BGSAVE 失败、stop-writes-on-bgsave-error 为 yes。去掉任何一个都不会拒写,但去掉前两个意味着数据没有被持久化。
故障中: rdb_last_bgsave_status = err,SET -> (error) MISCONF Redis is configured to save RDB ...
CONFIG SET stop-writes-on-bgsave-error no 之后: SET -> "OK",rdb_last_bgsave_status 仍是 err
改回 yes: SET -> (error) MISCONF Redis is configured to save RDB ...
chmod 755 把目录改回可写(此时还没有重新 BGSAVE): SET -> (error) MISCONF Redis is configured to save RDB ...
> BGSAVE
"Background saving started"
BGSAVE 成功之后: rdb_last_bgsave_status = ok,SET -> "OK"临时放开 stop-writes-on-bgsave-error 只是掩盖问题;修好目录权限或磁盘后手动 BGSAVE 一次,状态变 ok,写命令就恢复。