Expand description
Backup / restore container support. See
backup::pack and backup::unpack.
kevy-cli backup / kevy-cli restore subcommands.
Backups bundle a kevy data_dir (snapshot + AOF) into a single
.kevybkp file using a tiny custom container format (std-only,
0-dep — no tar crate per project rule).
Container format:
magic : 8 bytes = b"KEVYBKP1"
for each file:
name_len : u16 big-endian
name : <name_len> bytes (UTF-8, relative to data_dir)
body_len : u64 big-endian
body : <body_len> bytes
eof marker : u16 = 0Backup ordering: typically the operator issues a BGSAVE first
against the live kevy via TCP, then runs kevy-cli backup once
the snapshot has flushed. (kevy-cli backup can do this in one
call too — see the --bgsave flag.)
use kevy_cli::backup::{pack, unpack};
let data = kevy_tmpdir::TmpDir::new("backup-data");
std::fs::write(data.path().join("aof-0.aof"), b"*1\r\n$4\r\nPING\r\n")?;
let files = kevy_tmpdir::TmpDir::new("backup-files");
let bundle = files.path().join("nightly.kevybkp");
pack(data.path(), &bundle)?;
let restored = kevy_tmpdir::TmpDir::new("backup-restored");
unpack(&bundle, restored.path())?;
assert_eq!(std::fs::read(restored.path().join("aof-0.aof"))?, b"*1\r\n$4\r\nPING\r\n");Functions§
- pack
- Pack every regular file under
data_dirintoout_path. Subdirectories are skipped, and the data dir stopped being flat when tiering landed:tier/<shard>/vlog-*.datholds demoted values andsegs-<shard>/holds cold index segments. Skipping them is correct because both are derived — a snapshot materialises cold values rather than referencing them, so the backup carries the data without the spill area and a restore rebuilds it — measured end to end against a store whose values had actually been demoted, not reasoned about. - unpack
- Unpack the container at
in_pathintotarget_dir(created if missing; refuses to overwrite an existing non-empty dir to avoid clobbering live data).