Add kernelwatch backup command
Uses SQLite's online backup API, so it is consistent while the server is writing in WAL mode. Writes mode 0600 via a temp file and rename, and refuses to overwrite the live database. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c67a8e27a0
commit
4365ed56e1
3 files changed
+112
No files matched your search
@@ -43,6 +43,17 @@ def cmd_test_alert(cfg, args) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_backup(cfg, args) -> int:
|
||||
db.init(cfg.db_path)
|
||||
try:
|
||||
db.backup(cfg.db_path, args.path)
|
||||
except (OSError, ValueError, sqlite3.Error) as exc:
|
||||
print(f"kernelwatch: backup failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
print(f"Backed up to {args.path}")
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_add_host(cfg, args) -> int:
|
||||
token = auth.new_token()
|
||||
conn = _conn(cfg)
|
||||
@@ -154,6 +165,10 @@ def main(argv: list[str] | None = None) -> int:
|
||||
sub.add_parser("test-alert", help="send a test notification to the configured ntfy topic").set_defaults(
|
||||
func=cmd_test_alert)
|
||||
|
||||
p = sub.add_parser("backup", help="write a consistent copy of the database to PATH")
|
||||
p.add_argument("path")
|
||||
p.set_defaults(func=cmd_backup)
|
||||
|
||||
for name, func, help_ in (
|
||||
("add-host", cmd_add_host, "register a host and print its token"),
|
||||
("rotate-token", cmd_rotate_token, "issue a new token for a host"),
|
||||
|
||||
Reference in new issue
Block a user