Skip to content
Redis CLI

RDB / AOF 영속성 & 백업

스냅샷을 트리거하고, AOF 리라이트를 관리하며, 안전한 백업을 캡처.

#persistence#rdb#aof#backup

Code

redis-cli
# Manual RDB snapshot (foreground, blocks briefly)
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379> LASTSAVE
(integer) 1748200000

# Inspect persistence status
127.0.0.1:6379> INFO persistence
# rdb_bgsave_in_progress:0
# rdb_last_save_time:1748200000
# aof_enabled:1
# aof_rewrite_in_progress:0

# AOF (append-only file) controls
127.0.0.1:6379> CONFIG SET appendonly yes
127.0.0.1:6379> BGREWRITEAOF           # compact the AOF
127.0.0.1:6379> CONFIG SET appendfsync everysec   # always|everysec|no

# Online backup without stopping Redis: BGSAVE then copy the dump file
$ redis-cli BGSAVE
$ while [ "$(redis-cli INFO persistence | grep rdb_bgsave_in_progress | tr -d '
')" != "rdb_bgsave_in_progress:0" ]; do sleep 1; done
$ cp /var/lib/redis/dump.rdb /backup/dump-$(date +%F).rdb

# DEBUG SLEEP (testing only) — blocks server for N seconds
127.0.0.1:6379> DEBUG SLEEP 2

# Shutdown options
127.0.0.1:6379> SHUTDOWN SAVE       # save then quit
127.0.0.1:6379> SHUTDOWN NOSAVE     # quit without saving