diff --git a/builder/exector/groupapp_restore.go b/builder/exector/groupapp_restore.go index 227b1badc..125067b0e 100644 --- a/builder/exector/groupapp_restore.go +++ b/builder/exector/groupapp_restore.go @@ -229,6 +229,11 @@ func (b *BackupAPPRestore) restoreVersionAndData(backup *dbmodel.AppBackup, appS } err := util.Rename(tmpDir, util.GetParentDirectory(app.Service.HostPath)) if err != nil { + if strings.Contains(err.Error(), "file exists") { + if err := util.MergeDir(tmpDir, util.GetParentDirectory(app.Service.HostPath)); err != nil { + return err + } + } return err } if err := os.Chmod(app.Service.HostPath, 0777); err != nil { diff --git a/util/comman.go b/util/comman.go index 9c123d2cf..397e6fb87 100644 --- a/util/comman.go +++ b/util/comman.go @@ -513,6 +513,20 @@ func Rename(old, new string) error { return os.Rename(old, new) } +//MergeDir MergeDir +func MergeDir(fromdir, todir string) error { + files, err := ioutil.ReadDir(fromdir) + if err != nil { + return err + } + for _, f := range files { + if err := os.Rename(path.Join(fromdir, f.Name()), path.Join(todir, f.Name())); err != nil { + return err + } + } + return nil +} + //CreateVersionByTime create version number func CreateVersionByTime() string { now := time.Now() diff --git a/util/comman_test.go b/util/comman_test.go index cb6dce77d..68fd0f3a9 100644 --- a/util/comman_test.go +++ b/util/comman_test.go @@ -74,3 +74,9 @@ func TestGetDirList(t *testing.T) { } t.Log(list) } + +func TestMergeDir(t *testing.T) { + if err := MergeDir("/tmp/ctr-944254844/", "/tmp/cache"); err != nil { + t.Fatal(err) + } +}