backup.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """``hermes backup`` subcommand parser."""
  2. from __future__ import annotations
  3. from argparse import ArgumentTypeError
  4. from typing import Callable
  5. def _non_negative_keep(value: str) -> int:
  6. # A negative keep would slice away the NEWEST archives instead of the oldest.
  7. if not value.isdecimal():
  8. raise ArgumentTypeError("must be a non-negative integer (0 keeps everything)")
  9. return int(value)
  10. def build_backup_parser(subparsers, *, cmd_backup: Callable) -> None:
  11. """Attach the ``backup`` subcommand to ``subparsers``."""
  12. backup_parser = subparsers.add_parser(
  13. "backup", help="Back up Hermes home directory to a zip file",
  14. description="Create a zip archive of your entire Hermes configuration, "
  15. "skills, sessions, and data (excludes the hermes-agent codebase). "
  16. "Use --quick for a fast snapshot of just critical state files.")
  17. backup_parser.add_argument(
  18. "-o",
  19. "--output", help="Output path for the zip file (default: ~/hermes-backup-<timestamp>.zip)")
  20. backup_parser.add_argument(
  21. "-q", "--quick", action="store_true",
  22. help="Quick snapshot: only critical state files (config, state.db, .env, auth, cron)")
  23. backup_parser.add_argument(
  24. "-l", "--label", help="Label for the snapshot (only used with --quick)")
  25. backup_parser.add_argument(
  26. "-k", "--keep", type=_non_negative_keep, default=3, metavar="N",
  27. help="After a full backup, delete older hermes-backup-*.zip files in the output "
  28. "directory beyond the newest N (default 3; 0 keeps everything)")
  29. backup_parser.set_defaults(func=cmd_backup)