{"record":{"id":"22207497ab489773","repo":"googleapis/mcp-toolbox","slug":"source-project-and-instance-are-required-when-rest","errorCode":null,"errorMessage":"source project and instance are required when restoring via backup ID","messagePattern":"source project and instance are required when restoring via backup ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":421,"sourceCode":"}\n\nfunc (s *Source) RestoreBackup(ctx context.Context, targetProject, targetInstance, sourceProject, sourceInstance, backupID, accessToken string) (any, error) {\n\trequest := &sqladmin.InstancesRestoreBackupRequest{}\n\n\t// There are 3 scenarios for the backup identifier:\n\t// 1. The identifier is an int64 containing the timestamp of the BackupRun.\n\t//    This is used to restore standard backups, and the RestoreBackupContext\n\t//    field should be populated with the backup ID and source instance info.\n\t// 2. The identifier is a string of the format\n\t//    'projects/{project-id}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}/backups/{backup-uid}'.\n\t//    This is used to restore BackupDR backups, and the BackupdrBackup field\n\t//    should be populated.\n\t// 3. The identifer is a string of the format\n\t//    'projects/{project-id}/backups/{backup-uid}'. In this case, the Backup\n\t//    field should be populated.\n\tif backupRunID, err := strconv.ParseInt(backupID, 10, 64); err == nil {\n\t\tif sourceProject == \"\" || sourceInstance == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"source project and instance are required when restoring via backup ID\")\n\t\t}\n\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()","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L403-L439","documentation":"RestoreBackup supports restoring either by numeric backup run ID or by a backup resource name. When a numeric backup ID is given, the API needs to know which project and instance originally hold that backup run; this library throws this error when either sourceProject or sourceInstance is empty in that case, because the RestoreBackupContext cannot be populated correctly.","triggerScenarios":"Calling RestoreBackup with backupID parseable as an int64 (e.g. \"12345\") while leaving sourceProject or sourceInstance as empty strings. Restoring by full backup resource name ('projects/{p}/backups/{uid}') does not trigger this check.","commonSituations":"Tool configs or invocations that pass only the backup ID and target instance, forgetting the source project/instance; programmatic callers that derive parameters from user input where optional source fields were dropped.","solutions":["Pass both sourceProject and sourceInstance of the original backup when restoring via numeric backup ID","Alternatively, restore using the full backup resource name ('projects/{project}/backups/{backup-uid}') as backupID so source fields are not required","Check the tool configuration to ensure source_project and source_instance parameters are supplied"],"exampleFix":"// before\nRestoreBackup(ctx, targetProject, targetInstance, \"\", \"\", \"12345\", token)\n// after\nRestoreBackup(ctx, targetProject, targetInstance, \"source-project\", \"source-instance\", \"12345\", token)","handlingStrategy":"validation","validationCode":"if backupIDMatchesInt64(backupID) {\n    if sourceProject == \"\" || sourceInstance == \"\" {\n        return errors.New(\"numeric backupID requires sourceProject and sourceInstance\")\n    }\n}\n\nfunc backupIDMatchesInt64(id string) bool {\n    _, err := strconv.ParseInt(id, 10, 64)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always populate source_project and source_instance when restoring by numeric backup run ID","Prefer full backup resource names ('projects/{p}/backups/{uid}') which carry the source project implicitly","Add a preflight check in scripts that calls RestoreBackup with a numeric ID"],"tags":["validation","cloudsql","missing-parameter","restore"],"backgroundTag":"missing-required-argument","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"}