Home

Awesome

spanner-dump run-tests

spanner-dump is a command line tool for exporting a Cloud Spanner database in text format.

Exported databases can be imported to Cloud Spanner with spanner-cli.

# Export
$ spanner-dump -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE} > data.sql

# Import
$ spanner-cli -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE} < data.sql

Please feel free to report issues and send pull requests, but note that this application is not officially supported as part of the Cloud Spanner product.

Use cases

This tool can be used for the following use cases.

For production databases, you should use an officially-provided export, which should be stable and much faster.

Limitations

Install

go install github.com/cloudspannerecosystem/spanner-dump@latest

Usage

Usage:
  spanner-dump [OPTIONS]

Application Options:
  -p, --project=   (required) GCP Project ID. [$SPANNER_PROJECT_ID]
  -i, --instance=  (required) Cloud Spanner Instance ID. [$SPANNER_INSTANCE_ID]
  -d, --database=  (required) Cloud Spanner Database ID. [$SPANNER_DATABASE_ID]
      --tables=    comma-separated table names, e.g. "table1,table2"
      --no-ddl     No DDL information.
      --no-data    Do not dump data.
      --timestamp= Timestamp for database snapshot in the RFC 3339 format.
      --bulk-size= Bulk size for values in a single INSERT statement.

Help Options:
  -h, --help       Show this help message

This tool uses Application Default Credentials to connect to Cloud Spanner. Please make sure to get credentials via gcloud auth application-default login before using this tool.

Also, you need to have a roles/spanner.databaseReader IAM role to use this tool.

Disclaimer

This tool is still ALPHA quality. Do not use this tool for production databases.