mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix(host): bind mount regular file when backing up volume mount of pod (#20439)
This commit is contained in:
@@ -1520,12 +1520,26 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRuntimeMountHostPath containerId: %s, vol: %s", input.ContainerId, jsonutils.Marshal(vol))
|
||||
}
|
||||
// bind mount
|
||||
// mkdir tmpBackRootDir/subdirectory
|
||||
targetBindMntPath := filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
|
||||
if out, err := procutils.NewRemoteCommandAsFarAsPossible("mkdir", "-p", targetBindMntPath).Output(); err != nil {
|
||||
return nil, errors.Wrapf(err, "mkdir -p %s: %s", targetBindMntPath, out)
|
||||
isMntPathFile := false
|
||||
targetBindMntPath := tmpBackRootDir
|
||||
if vol.Disk.SubDirectory != "" {
|
||||
// mkdir tmpBackRootDir/subdirectory
|
||||
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
|
||||
}
|
||||
if vol.Disk.StorageSizeFile != "" {
|
||||
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.StorageSizeFile)
|
||||
isMntPathFile = true
|
||||
}
|
||||
if isMntPathFile {
|
||||
if out, err := procutils.NewRemoteCommandAsFarAsPossible("touch", targetBindMntPath).Output(); err != nil {
|
||||
return nil, errors.Wrapf(err, "touch %s: %s", targetBindMntPath, out)
|
||||
}
|
||||
} else {
|
||||
if out, err := procutils.NewRemoteCommandAsFarAsPossible("mkdir", "-p", targetBindMntPath).Output(); err != nil {
|
||||
return nil, errors.Wrapf(err, "mkdir -p %s: %s", targetBindMntPath, out)
|
||||
}
|
||||
}
|
||||
// do bind mount
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("mount", "--bind", mntPath, targetBindMntPath).Output()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "bind mount %s to %s: %s", mntPath, targetBindMntPath, out)
|
||||
@@ -1539,6 +1553,9 @@ func (s *sPodGuestInstance) DoSnapshot(ctx context.Context, params *SDiskSnapsho
|
||||
// unbind mount
|
||||
// umount
|
||||
targetBindMntPath := filepath.Join(tmpBackRootDir, vol.Disk.SubDirectory)
|
||||
if vol.Disk.StorageSizeFile != "" {
|
||||
targetBindMntPath = filepath.Join(tmpBackRootDir, vol.Disk.StorageSizeFile)
|
||||
}
|
||||
out, err := procutils.NewRemoteCommandAsFarAsPossible("umount", targetBindMntPath).Output()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "umount bind point %s: %s", targetBindMntPath, out)
|
||||
|
||||
Reference in New Issue
Block a user