| 350 | } |
| 351 | |
| 352 | func (f *Fs) restore(ctx context.Context, opt map[string]string) (any, error) { |
| 353 | req := objectstorage.RestoreObjectsRequest{ |
| 354 | NamespaceName: common.String(f.opt.Namespace), |
| 355 | RestoreObjectsDetails: objectstorage.RestoreObjectsDetails{}, |
| 356 | } |
| 357 | if hours := opt["hours"]; hours != "" { |
| 358 | ihours, err := strconv.Atoi(hours) |
| 359 | if err != nil { |
| 360 | return nil, fmt.Errorf("bad value for hours: %w", err) |
| 361 | } |
| 362 | req.RestoreObjectsDetails.Hours = &ihours |
| 363 | } |
| 364 | type status struct { |
| 365 | Object string |
| 366 | Status string |
| 367 | } |
| 368 | var ( |
| 369 | outMu sync.Mutex |
| 370 | out = []status{} |
| 371 | err error |
| 372 | ) |
| 373 | err = operations.ListFn(ctx, f, func(obj fs.Object) { |
| 374 | // Remember this is run --checkers times concurrently |
| 375 | o, ok := obj.(*Object) |
| 376 | st := status{Object: obj.Remote(), Status: "RESTORED"} |
| 377 | defer func() { |
| 378 | outMu.Lock() |
| 379 | out = append(out, st) |
| 380 | outMu.Unlock() |
| 381 | }() |
| 382 | if !ok { |
| 383 | st.Status = "Not an OCI Object Storage object" |
| 384 | return |
| 385 | } |
| 386 | if o.storageTier == nil || (*o.storageTier != "archive") { |
| 387 | st.Status = "Object not in Archive storage tier" |
| 388 | return |
| 389 | } |
| 390 | if operations.SkipDestructive(ctx, obj, "restore") { |
| 391 | return |
| 392 | } |
| 393 | bucket, bucketPath := o.split() |
| 394 | reqCopy := req |
| 395 | reqCopy.BucketName = &bucket |
| 396 | reqCopy.ObjectName = &bucketPath |
| 397 | var response objectstorage.RestoreObjectsResponse |
| 398 | err = f.pacer.Call(func() (bool, error) { |
| 399 | response, err = f.srv.RestoreObjects(ctx, reqCopy) |
| 400 | return shouldRetry(ctx, response.HTTPResponse(), err) |
| 401 | }) |
| 402 | if err != nil { |
| 403 | st.Status = err.Error() |
| 404 | } |
| 405 | }) |
| 406 | if err != nil { |
| 407 | return out, err |
| 408 | } |
| 409 | return out, nil |