ParseBackupRestorePath parse the BackupPath in spec of DataBackup or the RestorePath in spec of Dataset
(backupRestorePath string)
| 68 | |
| 69 | // ParseBackupRestorePath parse the BackupPath in spec of DataBackup or the RestorePath in spec of Dataset |
| 70 | func ParseBackupRestorePath(backupRestorePath string) (pvcName string, path string, err error) { |
| 71 | if backupRestorePath == "" { |
| 72 | err = errors.New("DataBackupRestorePath is empty, cannot parse") |
| 73 | return |
| 74 | } |
| 75 | if strings.HasPrefix(backupRestorePath, common.VolumeScheme.String()) { |
| 76 | path = strings.TrimPrefix(backupRestorePath, common.VolumeScheme.String()) |
| 77 | split := strings.Split(path, "/") |
| 78 | pvcName = split[0] |
| 79 | path = strings.TrimPrefix(path, pvcName) |
| 80 | } else if strings.HasPrefix(backupRestorePath, common.PathScheme.String()) { |
| 81 | path = strings.TrimPrefix(backupRestorePath, common.PathScheme.String()) |
| 82 | } else { |
| 83 | err = errors.New("DataBackupRestorePath is not in supported formats, cannot parse") |
| 84 | return |
| 85 | } |
| 86 | if !strings.HasPrefix(path, "/") { |
| 87 | path = "/" + path |
| 88 | } |
| 89 | if !strings.HasSuffix(path, "/") { |
| 90 | path = path + "/" |
| 91 | } |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | // GetBackupUserDir generate the temp dir of backup user |
| 96 | func GetBackupUserDir(namespace string, name string) string { |