{"record":{"id":"9e038d14c8a13a52","repo":"googleapis/mcp-toolbox","slug":"error-restoring-backup-w","errorCode":null,"errorMessage":"error restoring backup: %w","messagePattern":"error restoring backup: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":441,"sourceCode":"\t\trequest.RestoreBackupContext = &sqladmin.RestoreBackupContext{\n\t\t\tProject:     sourceProject,\n\t\t\tInstanceId:  sourceInstance,\n\t\t\tBackupRunId: backupRunID,\n\t\t}\n\t} else if backupDRRegex.MatchString(backupID) {\n\t\trequest.BackupdrBackup = backupID\n\t} else {\n\t\trequest.Backup = backupID\n\t}\n\n\tservice, err := s.GetService(ctx, string(accessToken))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresp, err := service.Instances.RestoreBackup(targetProject, targetInstance, request).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error restoring backup: %w\", err)\n\t}\n\n\treturn resp, nil\n}\n\nfunc generateCloudSQLConnectionMessage(ctx context.Context, source *Source, logger log.Logger, opResponse map[string]any, connectionMessageTemplate string) (string, bool) {\n\toperationType, ok := opResponse[\"operationType\"].(string)\n\tif !ok || operationType != \"CREATE_DATABASE\" {\n\t\treturn \"\", false\n\t}\n\n\ttargetLink, ok := opResponse[\"targetLink\"].(string)\n\tif !ok {\n\t\treturn \"\", false\n\t}\n\n\tmatches := targetLinkRegex.FindStringSubmatch(targetLink)\n\tif len(matches) < 4 {","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L423-L459","documentation":"This error wraps a failure from the Cloud SQL Admin API Instances.RestoreBackup call, which starts an asynchronous restore of a backup into a target instance. The restore operation was rejected or failed at submission time; the original Google API error is preserved for diagnosis.","triggerScenarios":"Calling RestoreBackup when the Instances.RestoreBackup RPC errors: target instance not found, backup ID does not exist in the source project/instance, insufficient IAM permissions, target instance state does not allow restore, or the point-in-time/backup context is invalid.","commonSituations":"Restoring into a misnamed target instance; referencing a backup run ID that was deleted or belongs to another project; service account lacking cloudsql.admin; target instance currently undergoing maintenance or with incompatibilities (e.g. different database flags/disk size).","solutions":["Inspect the wrapped Google API error for the specific cause (404 backup not found, 403 permission denied, 400 failedPrecondition)","Confirm targetProject/targetInstance exist and are in a state that accepts restores (not under maintenance)","Verify the source project/instance/backupRunId triple points to an existing backup (list BackupRuns to check)","Ensure the access token has Cloud SQL Admin permissions and retry; the restore is a long-running operation so poll the returned operation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the backup exists before restoring\nsrv, _ := sqladmin.NewService(ctx)\nruns, err := srv.BackupRuns.List(sourceProject, sourceInstance).Do()\nif err != nil || !containsBackupRun(runs, backupID) {\n    return fmt.Errorf(\"backup run %d not found in %s/%s\", backupID, sourceProject, sourceInstance)\n}","typeGuard":null,"tryCatchPattern":"resp, err := RestoreBackup(ctx, targetProject, targetInstance, srcProject, srcInstance, backupID, token)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) && (gerr.Code == 429 || gerr.Code >= 500) {\n        // retry with backoff\n    }\n    return err\n}","preventionTips":["List BackupRuns beforehand to confirm the backup ID exists in the source instance","Ensure the target instance is RUNNING and not under maintenance before restoring","Grant roles/cloudsql.admin to the caller; restore is an admin-level operation"],"tags":["gcp","cloudsql","api-error","restore"],"backgroundTag":"cloudsql-admin-api-error","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}