MCPcopy
hub / github.com/lxc/incus / GetInstanceBackupFile

Method GetInstanceBackupFile

client/incus_instances.go:2975–3040  ·  view source on GitHub ↗

GetInstanceBackupFile requests the instance backup content.

(instanceName string, name string, req *BackupFileRequest)

Source from the content-addressed store, hash-verified

2973
2974// GetInstanceBackupFile requests the instance backup content.
2975func (r *ProtocolIncus) GetInstanceBackupFile(instanceName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
2976 path, _, err := r.instanceTypeToPath(api.InstanceTypeAny)
2977 if err != nil {
2978 return nil, err
2979 }
2980
2981 if !r.HasExtension("container_backup") {
2982 return nil, errors.New("The server is missing the required \"container_backup\" API extension")
2983 }
2984
2985 // Build the URL
2986 uri := fmt.Sprintf("%s/1.0%s/%s/backups/%s/export", r.httpBaseURL.String(), path, url.PathEscape(instanceName), url.PathEscape(name))
2987 if r.project != "" {
2988 uri += fmt.Sprintf("?project=%s", url.QueryEscape(r.project))
2989 }
2990
2991 // Prepare the download request
2992 request, err := http.NewRequest("GET", uri, nil)
2993 if err != nil {
2994 return nil, err
2995 }
2996
2997 if r.httpUserAgent != "" {
2998 request.Header.Set("User-Agent", r.httpUserAgent)
2999 }
3000
3001 // Start the request
3002 response, doneCh, err := cancel.CancelableDownload(req.Canceler, r.DoHTTP, request)
3003 if err != nil {
3004 return nil, err
3005 }
3006
3007 defer logger.WarnOnError(response.Body.Close, "Failed to close response body")
3008 defer close(doneCh)
3009
3010 if response.StatusCode != http.StatusOK {
3011 _, _, err := incusParseResponse(response)
3012 if err != nil {
3013 return nil, err
3014 }
3015 }
3016
3017 // Handle the data
3018 body := response.Body
3019 if req.ProgressHandler != nil {
3020 body = &ioprogress.ProgressReader{
3021 ReadCloser: response.Body,
3022 Tracker: &ioprogress.ProgressTracker{
3023 Length: response.ContentLength,
3024 Handler: func(percent int64, speed int64) {
3025 req.ProgressHandler(ioprogress.ProgressData{Text: fmt.Sprintf("%d%% (%s/s)", percent, units.GetByteSizeString(speed, 2))})
3026 },
3027 },
3028 }
3029 }
3030
3031 size, err := util.SafeCopy(req.BackupFile, body)
3032 if err != nil {

Callers

nothing calls this directly

Calls 9

instanceTypeToPathMethod · 0.95
HasExtensionMethod · 0.95
CancelableDownloadFunction · 0.92
WarnOnErrorFunction · 0.92
GetByteSizeStringFunction · 0.92
SafeCopyFunction · 0.92
incusParseResponseFunction · 0.85
StringMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected