MCPcopy Create free account
hub / github.com/agent0ai/agent-zero / create_backup

Method create_backup

helpers/backup.py:336–430  ·  view source on GitHub ↗

Create backup archive and return path to created file

(
        self,
        include_patterns: List[str],
        exclude_patterns: List[str],
        include_hidden: bool = True,
        backup_name: str = "agent-zero-backup"
    )

Source from the content-addressed store, hash-verified

334 return matched_files
335
336 async def create_backup(
337 self,
338 include_patterns: List[str],
339 exclude_patterns: List[str],
340 include_hidden: bool = True,
341 backup_name: str = "agent-zero-backup"
342 ) -> str:
343 """Create backup archive and return path to created file"""
344
345 # Create metadata for test_patterns
346 metadata = {
347 "include_patterns": include_patterns,
348 "exclude_patterns": exclude_patterns,
349 "include_hidden": include_hidden
350 }
351
352 # Get the complete matched file set. Preview and dry-run callers may
353 # cap their scans for UI responsiveness, but the archive itself must be
354 # complete.
355 matched_files = await self.test_patterns(metadata, max_files=None)
356
357 if not matched_files:
358 raise Exception("No files matched the backup patterns")
359
360 # Create temporary zip file
361 temp_dir = tempfile.mkdtemp()
362 zip_path = os.path.join(temp_dir, f"{backup_name}.zip")
363
364 try:
365 with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
366 # Add comprehensive metadata
367 metadata = {
368 # Basic backup information
369 "agent_zero_version": self.agent_zero_version,
370 "timestamp": Localization.get().now_iso(),
371 "backup_name": backup_name,
372 "include_hidden": include_hidden,
373
374 # Pattern arrays for granular control during restore
375 "include_patterns": include_patterns,
376 "exclude_patterns": exclude_patterns,
377
378 # System and environment information
379 "system_info": await self._get_system_info(),
380 "environment_info": await self._get_environment_info(),
381 "backup_author": await self._get_backup_author(),
382
383 # Backup configuration
384 "backup_config": {
385 "include_patterns": include_patterns,
386 "exclude_patterns": exclude_patterns,
387 "include_hidden": include_hidden,
388 "compression_level": 6,
389 "integrity_check": True
390 },
391
392 # File information
393 "files": [

Callers 2

processMethod · 0.95

Calls 12

test_patternsMethod · 0.95
_get_system_infoMethod · 0.95
_get_environment_infoMethod · 0.95
_get_backup_authorMethod · 0.95
_count_directoriesMethod · 0.95
PrintStyleClass · 0.90
now_isoMethod · 0.80
joinMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
warningMethod · 0.45
removeMethod · 0.45