GetStorageVolumeBackupFile requests the custom volume backup content.
(pool string, volName string, name string, req *BackupFileRequest)
| 1053 | |
| 1054 | // GetStorageVolumeBackupFile requests the custom volume backup content. |
| 1055 | func (r *ProtocolIncus) GetStorageVolumeBackupFile(pool string, volName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) { |
| 1056 | if !r.HasExtension("custom_volume_backup") { |
| 1057 | return nil, errors.New("The server is missing the required \"custom_volume_backup\" API extension") |
| 1058 | } |
| 1059 | |
| 1060 | // Build the URL |
| 1061 | uri := fmt.Sprintf("%s/1.0/storage-pools/%s/volumes/custom/%s/backups/%s/export", r.httpBaseURL.String(), url.PathEscape(pool), url.PathEscape(volName), url.PathEscape(name)) |
| 1062 | |
| 1063 | // Add project/target |
| 1064 | uri, err := r.setQueryAttributes(uri) |
| 1065 | if err != nil { |
| 1066 | return nil, err |
| 1067 | } |
| 1068 | |
| 1069 | // Prepare the download request |
| 1070 | request, err := http.NewRequest("GET", uri, nil) |
| 1071 | if err != nil { |
| 1072 | return nil, err |
| 1073 | } |
| 1074 | |
| 1075 | if r.httpUserAgent != "" { |
| 1076 | request.Header.Set("User-Agent", r.httpUserAgent) |
| 1077 | } |
| 1078 | |
| 1079 | // Start the request |
| 1080 | response, doneCh, err := cancel.CancelableDownload(req.Canceler, r.DoHTTP, request) |
| 1081 | if err != nil { |
| 1082 | return nil, err |
| 1083 | } |
| 1084 | |
| 1085 | defer logger.WarnOnError(response.Body.Close, "Failed to close response body") |
| 1086 | defer close(doneCh) |
| 1087 | |
| 1088 | if response.StatusCode != http.StatusOK { |
| 1089 | _, _, err := incusParseResponse(response) |
| 1090 | if err != nil { |
| 1091 | return nil, err |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // Handle the data |
| 1096 | body := response.Body |
| 1097 | if req.ProgressHandler != nil { |
| 1098 | body = &ioprogress.ProgressReader{ |
| 1099 | ReadCloser: response.Body, |
| 1100 | Tracker: &ioprogress.ProgressTracker{ |
| 1101 | Length: response.ContentLength, |
| 1102 | Handler: func(percent int64, speed int64) { |
| 1103 | req.ProgressHandler(ioprogress.ProgressData{Text: fmt.Sprintf("%d%% (%s/s)", percent, units.GetByteSizeString(speed, 2))}) |
| 1104 | }, |
| 1105 | }, |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | size, err := util.SafeCopy(req.BackupFile, body) |
| 1110 | if err != nil { |
| 1111 | return nil, err |
| 1112 | } |
nothing calls this directly
no test coverage detected