Categorygithub.com/cloudspannerecosystem/spanner-dump
modulepackage
0.2.2
Repository: https://github.com/cloudspannerecosystem/spanner-dump.git
Documentation: pkg.go.dev

# README

spanner-dump CircleCI

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.

  • Export a database schema and/or data in text format for testing purposes
  • Export a database running on Cloud Spanner Emulator

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

Limitations

  • This tool does not ensure consistency between database schema (DDL) and data. So you should avoid making changes to the schema while you are running this tool.
  • This tool does not consider data order constrained by Foreign Keys.

Install

go get -u github.com/cloudspannerecosystem/spanner-dump

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.

# Functions

DecodeColumn decodes a single column value into a string.
DecodeRow decodes column values in spanner.Row into strings.
FetchTables fetches all table information in the database from Spanner.
NewBufferedWriter creates BufferedWriter with specified configs.
NewDumper creates Dumper with specified configurations.

# Structs

BufferedWriter is a writer to write table records in bulk.
Dumper is a dumper to export a database.
Table represents a Spanner table.
TableIterator is an iterator to get tables in the database one by one.