{"record":{"id":"27613677586806c3","repo":"googleapis/mcp-toolbox","slug":"error-creating-backup-w","errorCode":null,"errorMessage":"error creating backup: %w","messagePattern":"error creating backup: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":399,"sourceCode":"}\n\nfunc (s *Source) InsertBackupRun(ctx context.Context, project, instance, location, backupDescription, accessToken string) (any, error) {\n\tbackupRun := &sqladmin.BackupRun{}\n\tif location != \"\" {\n\t\tbackupRun.Location = location\n\t}\n\tif backupDescription != \"\" {\n\t\tbackupRun.Description = backupDescription\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.BackupRuns.Insert(project, instance, backupRun).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating backup: %w\", err)\n\t}\n\n\treturn resp, nil\n}\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","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L381-L417","documentation":"This error wraps any failure from the Cloud SQL Admin API's BackupRuns.Insert call when creating an on-demand backup of a Cloud SQL instance. It indicates the Google Cloud API rejected or failed the backup creation request; the underlying Google API error is preserved via %w so the specific cause (permissions, instance state, quota) can be inspected.","triggerScenarios":"Calling InsertBackupRun for a project/instance where the BackupRuns.Insert RPC returns an error: invalid project or instance name, instance not running, missing cloudsql.admin scope or IAM permission, or a transient API failure.","commonSituations":"Mistyped project or instance IDs in tool parameters; the service account lacks the Cloud SQL Admin role; the instance is in a failed/maintenance state; backup quota exceeded or API not enabled in the project.","solutions":["Read the wrapped error for the Google API cause (e.g. 403 permissionDenied, 404 notFound) and address it directly","Verify the project ID and instance name are correct and the instance exists and is RUNNABLE","Ensure the caller's access token / service account has roles/cloudsql.admin and the SQL Admin API is enabled","Retry the backup; transient API errors are common"],"exampleFix":"// before\nresp, err := service.BackupRuns.Insert(project, instance, backupRun).Do()\n// after\nif project == \"\" || instance == \"\" {\n    return nil, fmt.Errorf(\"project and instance are required\")\n}\nresp, err := service.BackupRuns.Insert(project, instance, backupRun).Do()","handlingStrategy":"try-catch","validationCode":"if project == \"\" || instance == \"\" {\n    return fmt.Errorf(\"project and instance must be non-empty before creating a backup\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := InsertBackupRun(ctx, project, instance, accessToken)\nif err != nil {\n    var apiErr *googleapi.Error\n    if errors.As(err, &apiErr) {\n        log.Printf(\"backup insert failed: code=%d body=%s\", apiErr.Code, apiErr.Message)\n    }\n    return err\n}","preventionTips":["Validate project and instance names before invoking the backup tool","Grant the service account roles/cloudsql.admin before running backups","Check instance state is RUNNABLE (no active maintenance/failed operation) first"],"tags":["gcp","cloudsql","api-error","backup"],"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"}