cloudspannerecosystem / spanner-dump

Command line tool for exporting a Cloud Spanner database in text format
Apache License 2.0
40 stars 13 forks source link

Is there a way to import to the emulator? #7

Closed rakyll closed 4 years ago

rakyll commented 4 years ago

I'd like to use the spanner-dump to migrate my schema and data from my production database to the emulator? I'd be great to be able to set the SPANNER_EMULATOR_HOST and be able to import to the emulator.

yfuruyama commented 4 years ago

Yes, you can.

spanner-dump already supports SPANNER_EMULATOR_HOST as an environment variable. So you can move data from Spanner service to emulator.

# export data from Spanner service
spanner-dump -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE} > dump.sql

# import data to emulator
SPANNER_EMULATOR_HOST=localhost:9010 spanner-cli -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE} < dump.sql

Note that second example uses spanner-cli for importing data.

rakyll commented 4 years ago

Great, thanks! Maybe it'd be great to mention it in the README.

yfuruyama commented 4 years ago

Will do! Thanks!