>_ IzzyLab

Hands-on task

This task is step 3 of the course “Redis in production”

RDB backup with BGSAVE

medium~10 min

Redis holds orders (order:*) and customers (customer:*) — 500 keys in total. Automatic snapshots are disabled on the server, and the dump.rdb in the data directory is stale.

Make a fresh backup:

  1. start a background snapshot with BGSAVE (not the blocking SAVE);
  2. wait until it finishes;
  3. copy the resulting file to /root/backup/dump.rdb.

Don't change the data in Redis.

What you'll practise:
  • redis
  • RDB
  • BGSAVE
  • LASTSAVE
  • redis-check-rdb
  • backup

Topic breakdown

RDB is a compact point-in-time snapshot of the whole dataset. SAVE writes it in the main thread and blocks all requests until the write is done, so in production you use BGSAVE: Redis calls fork(), and the child process writes the snapshot while the parent keeps serving clients (thanks to copy-on-write memory the copy is consistent as of the fork). The command returns right away, so a backup script must wait for completion — via INFO persistence or a change in LASTSAVE — and check the result. Otherwise it is easy to grab an old dump.rdb or a half-written temporary file. redis-check-rdb checks a snapshot's integrity without starting a server.

What's checked

  1. the copy is a valid RDB file
  2. the copy has all 500 keys
  3. a fresh snapshot was made with BGSAVE

What it looks like