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

Function doAppBackup

agent/app/service/backup_app.go:354–390  ·  view source on GitHub ↗
(install *model.AppInstall, parentTask *task.Task, backupDir, fileName, excludes, secret string)

Source from the content-addressed store, hash-verified

352}
353
354func doAppBackup(install *model.AppInstall, parentTask *task.Task, backupDir, fileName, excludes, secret string) error {
355 fileOp := files.NewFileOp()
356 tmpDir := fmt.Sprintf("%s/%s", backupDir, strings.ReplaceAll(fileName, ".tar.gz", ""))
357 if !fileOp.Stat(tmpDir) {
358 if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
359 return fmt.Errorf("mkdir %s failed, err: %v", backupDir, err)
360 }
361 }
362 defer func() {
363 _ = os.RemoveAll(tmpDir)
364 }()
365
366 remarkInfo, _ := json.Marshal(install)
367 remarkInfoPath := fmt.Sprintf("%s/app.json", tmpDir)
368 if err := fileOp.SaveFile(remarkInfoPath, string(remarkInfo), fs.ModePerm); err != nil {
369 return err
370 }
371
372 appPath := install.GetPath()
373 parentTask.LogStart(i18n.GetMsgByKey("TaskBackup"))
374 if err := fileOp.TarGzCompressPro(true, appPath, path.Join(tmpDir, "app.tar.gz"), "", excludes); err != nil {
375 return err
376 }
377
378 resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
379 for _, resource := range resources {
380 if err := backupDatabaseWithTask(parentTask, resource.Key, tmpDir, install.Name, resource.ResourceId); err != nil {
381 return err
382 }
383 }
384 parentTask.LogStart(i18n.GetMsgByKey("CompressDir"))
385 if err := fileOp.TarGzCompressPro(true, tmpDir, path.Join(backupDir, fileName), secret, ""); err != nil {
386 return err
387 }
388 parentTask.Log(i18n.GetWithName("CompressFileSuccess", fileName))
389 return nil
390}
391
392func reCreateDB(dbID uint, database model.Database, envMap map[string]interface{}) (*model.DatabaseMysql, error) {
393 mysqlService := NewIMysqlService()

Callers 2

handleAppMethod · 0.85
handleAppBackupFunction · 0.85

Calls 11

StatMethod · 0.95
SaveFileMethod · 0.95
TarGzCompressProMethod · 0.95
backupDatabaseWithTaskFunction · 0.85
MkdirAllMethod · 0.80
RemoveAllMethod · 0.80
GetByMethod · 0.65
WithAppInstallIdMethod · 0.65
GetPathMethod · 0.45
LogStartMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected