[Solved] Backup/Restore on CloudSQL instances


Here I address you questions:

1. Any way to check the size of existing databases in CloudSQL instances?

Yes, there is. This depends on the database engine you are using(mysql, postgres or mssql)

For mysql, you can run:

SELECT table_schema "DB Name",
        ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM information_schema.tables 
GROUP BY table_schema; 

For postgres, you can run:

SELECT pg_size_pretty(pg_database_size('Database Name'));

For mssql, you can run:

SELECT 
      database_name = DB_NAME(database_id)
    , log_size_mb = CAST(SUM(CASE WHEN type_desc="LOG" THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , row_size_mb = CAST(SUM(CASE WHEN type_desc="ROWS" THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
WHERE database_id = DB_ID() -- for current db 
GROUP BY database_id

2.Where the backup is stored? Is it Cloud Storage or the DB disk?

Cloud Storage. When you make a Cloud SQL export, the export file is
stored in Cloud Storage. From Cloud Storage, you can download/move
it to a different location.

3. Can we access the CloudSQL instance with a private IP from my desktop using IAP tunneling ?

No, the IAP tunneling aka IAP for TCP forwarding is intended to be used with Google Cloud compute engine instances.
Quoting the documentation:

IAP’s TCP forwarding feature allows users to connect to arbitrary TCP
ports on Compute Engine instances.

There is also this feature request to extend the capabilities of IAP TCP forwarding to cover Cloud SQL instances. I would recommend then to star the issue tracker and share your feedback so that the thread relevance increases.

An alternative to connect to a Cloud SQL instance with only private ip, would be to use a bastion host with an external public address that forwards all TCP traffic to your Cloud SQL instance.

I hope you find this useful.

2

solved Backup/Restore on CloudSQL instances