horizon-server: backups, restore and automatic backups

`backup [NAME]` zips the world and the settings into backups/; on a running server it turns saving
off, flushes, zips and turns saving back on, so the game stays up. `restore BACKUP` puts a backup's
world in place and keeps the current one in backups/replaced-<time>/; a running server restarts with
it. `[backups] every = "6h"`, `keep = 12` in server.toml back up on a schedule and prune the
automatic backups only. The control API gains GET/POST /api/v1/backups and POST /api/v1/restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-16 20:10:58 +02:00
parent e8832190d1
commit 3510764cc6
8 changed files with 611 additions and 15 deletions
+13
View File
@@ -2,6 +2,7 @@
//! runs the game headless as the engine, and manages the vanilla files around it.
mod api;
mod backup;
mod cli;
mod config;
mod engine;
@@ -31,6 +32,12 @@ Usage: horizon-server [--dir DIR] <command>
Run a console command on the running server and print what it answers
logs [-f] [-n N]
The last N lines of the log (default 50); -f follows it
backup [NAME]
Zip the world and the settings into backups/ (a running server saves first and stays up)
backups List the backups
restore BACKUP [--yes]
Put a backup's world in place (the current one is kept in backups/); a running
server restarts with it
import FILE Write server.toml from a vanilla server.properties
op NAME, deop NAME
whitelist on|off|list, whitelist add|remove NAME
@@ -69,6 +76,12 @@ fn main() -> ExitCode {
Some("status") => cli::status(&dir, args[1..].iter().any(|a| a == "--json")),
Some("cmd") => cli::command(&dir, &args[1..]),
Some("logs") => logs(&dir, &args[1..]),
Some("backup") => cli::backup(&dir, args.get(1).map(String::as_str)),
Some("backups") => cli::backups(&dir),
Some("restore") => match args.get(1) {
Some(name) => cli::restore(&dir, name, args[2..].iter().any(|a| a == "--yes")),
None => Err("restore needs a backup (`horizon-server backups` lists them)".into()),
},
Some("import") => import(&dir, &args[1..]),
Some(command @ ("op" | "deop" | "whitelist")) => lists::run(&dir, command, &args[1..]),
Some(other) => Err(format!(