Back up the database nightly with a timer
CI / tests (Python 3.10) (pull_request) Successful in 23s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 24s
CI / tests (Python 3.13) (pull_request) Successful in 24s
CI / lint (pull_request) Successful in 3s
CI / tests (Python 3.10) (pull_request) Successful in 23s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 24s
CI / tests (Python 3.13) (pull_request) Successful in 24s
CI / lint (pull_request) Successful in 3s
kernelwatch scheduled-backup writes kernelwatch-YYYY-MM-DD.db into backup_dir and prunes dated copies backup_keep_days or older, only after the new backup succeeded and only files with exactly that name. kernelwatch-backup.timer runs it at about 03:30 as the unprivileged service user with no network, and server/install.sh enables it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3624f0e5d9
commit
4a9bc77a08
10 files changed
+281
-3
No files matched your search
@@ -54,6 +54,17 @@ def cmd_backup(cfg, args) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_scheduled_backup(cfg, args) -> int:
|
||||
db.init(cfg.db_path)
|
||||
try:
|
||||
dest = db.rotate_backups(cfg.db_path, cfg.backup_dir, cfg.backup_keep_days)
|
||||
except (OSError, ValueError, sqlite3.Error) as exc:
|
||||
print(f"kernelwatch: scheduled backup failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
print(f"Backed up to {dest}")
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_add_host(cfg, args) -> int:
|
||||
token = auth.new_token()
|
||||
conn = _conn(cfg)
|
||||
@@ -168,6 +179,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
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)
|
||||
sub.add_parser("scheduled-backup", help="back up to backup_dir and prune old backups "
|
||||
"(run by kernelwatch-backup.timer)").set_defaults(func=cmd_scheduled_backup)
|
||||
|
||||
for name, func, help_ in (
|
||||
("add-host", cmd_add_host, "register a host and print its token"),
|
||||
|
||||
Reference in new issue
Block a user