Core backup and restore service for Agent Zero. Features: - JSON-based metadata with user-editable path specifications - Comprehensive system information collection - Checksum validation for integrity - RFC compatibility through existing file helpers - Git version integ
| 14 | |
| 15 | |
| 16 | class BackupService: |
| 17 | """ |
| 18 | Core backup and restore service for Agent Zero. |
| 19 | |
| 20 | Features: |
| 21 | - JSON-based metadata with user-editable path specifications |
| 22 | - Comprehensive system information collection |
| 23 | - Checksum validation for integrity |
| 24 | - RFC compatibility through existing file helpers |
| 25 | - Git version integration consistent with main application |
| 26 | """ |
| 27 | |
| 28 | def __init__(self): |
| 29 | self.agent_zero_version = self._get_agent_zero_version() |
| 30 | self.agent_zero_root = files.get_abs_path("") # Resolved Agent Zero root |
| 31 | |
| 32 | # Build base paths map for pattern resolution |
| 33 | self.base_paths = { |
| 34 | self.agent_zero_root: self.agent_zero_root, |
| 35 | } |
| 36 | |
| 37 | def get_default_backup_metadata(self) -> Dict[str, Any]: |
| 38 | """Get default backup patterns and metadata""" |
| 39 | timestamp = Localization.get().now_iso() |
| 40 | |
| 41 | default_patterns = self._get_default_patterns() |
| 42 | include_patterns, exclude_patterns = self._parse_patterns(default_patterns) |
| 43 | |
| 44 | return { |
| 45 | "backup_name": f"agent-zero-backup-{timestamp[:10]}", |
| 46 | "include_hidden": True, |
| 47 | "include_patterns": include_patterns, |
| 48 | "exclude_patterns": exclude_patterns, |
| 49 | "backup_config": { |
| 50 | "compression_level": 6, |
| 51 | "integrity_check": True |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | def _get_default_patterns(self) -> str: |
| 56 | """Get default backup patterns with resolved absolute paths. |
| 57 | |
| 58 | Only includes Agent Zero project directory patterns. |
| 59 | """ |
| 60 | # Ensure paths don't have double slashes |
| 61 | agent_root = self.agent_zero_root.rstrip('/') |
| 62 | |
| 63 | return f"""# User data |
| 64 | # All persistent user data is now centralized in /usr for easier backup and restore |
| 65 | {agent_root}/usr/** |
| 66 | """ |
| 67 | |
| 68 | def _get_agent_zero_version(self) -> str: |
| 69 | """Get current Agent Zero version""" |
| 70 | try: |
| 71 | # Get version from git info (same as run_ui.py) |
| 72 | gitinfo = git.get_git_info() |
| 73 | return gitinfo.get("version", "development") |
no outgoing calls