googleapis/mcp-toolbox · error

error creating backup: %w

Error message

error creating backup: %w

What it means

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.

Source

Thrown at internal/sources/cloudsqladmin/cloud_sql_admin.go:399

}

func (s *Source) InsertBackupRun(ctx context.Context, project, instance, location, backupDescription, accessToken string) (any, error) {
	backupRun := &sqladmin.BackupRun{}
	if location != "" {
		backupRun.Location = location
	}
	if backupDescription != "" {
		backupRun.Description = backupDescription
	}

	service, err := s.GetService(ctx, string(accessToken))
	if err != nil {
		return nil, err
	}

	resp, err := service.BackupRuns.Insert(project, instance, backupRun).Do()
	if err != nil {
		return nil, fmt.Errorf("error creating backup: %w", err)
	}

	return resp, nil
}

func (s *Source) RestoreBackup(ctx context.Context, targetProject, targetInstance, sourceProject, sourceInstance, backupID, accessToken string) (any, error) {
	request := &sqladmin.InstancesRestoreBackupRequest{}

	// There are 3 scenarios for the backup identifier:
	// 1. The identifier is an int64 containing the timestamp of the BackupRun.
	//    This is used to restore standard backups, and the RestoreBackupContext
	//    field should be populated with the backup ID and source instance info.
	// 2. The identifier is a string of the format
	//    'projects/{project-id}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}/backups/{backup-uid}'.
	//    This is used to restore BackupDR backups, and the BackupdrBackup field
	//    should be populated.
	// 3. The identifer is a string of the format
	//    'projects/{project-id}/backups/{backup-uid}'. In this case, the Backup

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped error for the Google API cause (e.g. 403 permissionDenied, 404 notFound) and address it directly
  2. Verify the project ID and instance name are correct and the instance exists and is RUNNABLE
  3. Ensure the caller's access token / service account has roles/cloudsql.admin and the SQL Admin API is enabled
  4. Retry the backup; transient API errors are common

Example fix

// before
resp, err := service.BackupRuns.Insert(project, instance, backupRun).Do()
// after
if project == "" || instance == "" {
    return nil, fmt.Errorf("project and instance are required")
}
resp, err := service.BackupRuns.Insert(project, instance, backupRun).Do()
Defensive patterns

Strategy: try-catch

Validate before calling

if project == "" || instance == "" {
    return fmt.Errorf("project and instance must be non-empty before creating a backup")
}

Try / catch

resp, err := InsertBackupRun(ctx, project, instance, accessToken)
if err != nil {
    var apiErr *googleapi.Error
    if errors.As(err, &apiErr) {
        log.Printf("backup insert failed: code=%d body=%s", apiErr.Code, apiErr.Message)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/27613677586806c3. Report an issue: GitHub.