MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / stepBackupComposeFiles

Function stepBackupComposeFiles

agent/app/service/backup_compose.go:469–510  ·  view source on GitHub ↗
(composeCtx *composeBackupContext)

Source from the content-addressed store, hash-verified

467}
468
469func stepBackupComposeFiles(composeCtx *composeBackupContext) error {
470 for i, filePath := range composeCtx.composeFiles {
471 backupName := fmt.Sprintf("%02d_%s", i, path.Base(filePath))
472 backupPath := path.Join(composeCtx.tmpDir, "compose_files", backupName)
473 content, err := os.ReadFile(filePath)
474 if err != nil {
475 return err
476 }
477 if err := composeCtx.fileOp.SaveFile(backupPath, string(content), fs.ModePerm); err != nil {
478 return err
479 }
480 relativePath := path.Base(filePath)
481 if composeCtx.composeDir != "" {
482 rel, relErr := filepath.Rel(composeCtx.composeDir, filePath)
483 if relErr == nil {
484 rel = filepath.ToSlash(rel)
485 if rel != "" && rel != "." && !strings.HasPrefix(rel, "../") {
486 relativePath = rel
487 }
488 }
489 }
490 composeCtx.meta.Files = append(composeCtx.meta.Files, composeBackupFile{
491 OriginalPath: filePath,
492 FileName: path.Base(filePath),
493 RelativePath: relativePath,
494 BackupPath: path.Join("compose_files", backupName),
495 })
496 }
497 if len(composeCtx.composeFiles) != 0 {
498 envPath := path.Join(path.Dir(composeCtx.composeFiles[0]), ".env")
499 if composeCtx.fileOp.Stat(envPath) {
500 envContent, err := os.ReadFile(envPath)
501 if err != nil {
502 return err
503 }
504 if err := composeCtx.fileOp.SaveFile(path.Join(composeCtx.tmpDir, "compose_files", ".env"), string(envContent), fs.ModePerm); err != nil {
505 return err
506 }
507 }
508 }
509 return nil
510}
511
512func stepWriteComposeBackupMeta(composeCtx *composeBackupContext) error {
513 metaBytes, err := json.MarshalIndent(composeCtx.meta, "", " ")

Callers 1

handleComposeBackupFunction · 0.85

Calls 2

SaveFileMethod · 0.80
StatMethod · 0.45

Tested by

no test coverage detected