I'm trying to create an inventory of my google cloud SQL instances and keep it in a separate MySQL database, so I can feed it into our existing on-premise inventory.
To get a list of gcloud instances, I can run the following:
$> gcloud sql instances list
Which will return something like:
NAME DATABASE_VERSION LOCATION TIER ADDRESS STATUS
inst3 MYSQL_5_7 europe-west4-b db-f1-micro xx.xx.xx.xx RUNNABLE
inst2 MYSQL_5_6 europe-west4-b db-f1-micro xx.xx.xx.xx RUNNABLE
zandra MYSQL_5_7 europe-west4-c db-f1-micro xx.xx.xx.xx RUNNABLE
In a bash script if I run this like:
$> allinstances=`gcloud sql instances list`
to set a variable called allinstances
, how do I then insert this into a mysql table called gcloudinv
I have tried this expecting an error:
$> mysql -uuser -ppassword gcloudinv < allinstances
I know this won't work, but what I would I need to do inbetween to turn the output into a format mysql can work with.
Ideally I will be overwriting this base inventory daily.
Thanks