Spanner import and export overview

You can import and export a large amount of data into or out ofSpanner using any of the following methods:

  • Import or export any Spanner database usingDataflow.
  • Export any Spanner database into a Cloud Storagebucket using either Avro or CSV file formats.
  • Import data from Avroor CSV files into a new Spanner database.
Note: If you export a Spanner database to Cloud Storage, thenimport it back to Spanner, make sure you import the database intoa Spanner instance with the same (or higher-tier)Spanner edition as the source instance. Otherwise, the importmight fail. For more information, see theSpanner editions overview.

Use cases

You can use Spanner import and export for the following use cases:

  • Bulk loading: You can import data in bulk into Spanner.
  • Long-term backup and archiving: You can export your database at any timeand store it in a Cloud Storage bucket location of your choice for long-termbackup or archiving. In addition, you can usepoint-in-timerecovery to export a database from a specific past timestamp.If you are looking for disaster recovery techniques that offer quickerrestoration but have a shorter retention periods,consider usingbackupsorpoint-in-time recovery (PITR).

  • Copying databases to development or test projects: You can export adatabase from a production project and then import it into your development ortest project to use for integration tests or other experiments.

  • Ingesting for analytics: You can export a database to ingest youroperational data in bulk to analytics services such as BigQuery.BigQuery can automatically ingest data in Avro formatfrom a Cloud Storage bucket, making it easier for you to run analyticson your operational data.If you want to use BigQuery for real-time analysis ofSpanner data without copying or moving the data, you can useSpanner federated queries instead.

Compare import and export to back up and restore

Spanner import and export is similar to back up and restorein many ways. The following table describes similarities and differencesbetween them to help you decide which one to use.

Back up and restoreImport and export
Data consistencyBoth backups and exported databases are transactionally and externally consistent.
Performance impactBackups have no impact on an instance's performance. Spanner performs backups using dedicated jobs that don't draw upon an instance's server resources.Export runs as a medium-priority task to minimize impact on database performance. For more information, seetask priority.
Storage formatUses a proprietary, encrypted format designed for fast restore.Supports both CSV andAvro file formats.
PortabilityYoucreate backups in the same instance as their source database.

After a backup is created, you cancopy the backup to an instance in a different region or project if you need a cross-region or cross-project backup. You can thenrestore from a backup as a new database to any instance in the same project. The instance that you are restoring to should have the same instance configuration as the instance where the backup is stored.
Exported databases reside inCloud Storage and the data can be migrated to any system that supports CSV or Avro.
RetentionBackups can be retained for up to one year.Exported databases are stored in Cloud Storage where, by default, they are retained until they are deleted. You can customizelifecycle andretention policies.
PricingBackups are billed to your Spanner project based on the storage used per unit time. For more details, see thePricing section.Billing for import and export is more complicated due to its use ofCloud Storage andDataflow. For more information, seeDatabase export and import pricing.
Restore timeRestore happens in two operations: restore and optimize. The restore operation offers fast time-to-first-byte because the database directly mounts the backup without copying the data. After the restore operation completes, the database is ready for use, though read latency might be slightly higher while it is optimizing. For more information, seeHow restore works.Import is slower. You need to wait for all the data to be written into the database.

Compare file formats

The following table compares the capability differences between Avro and CSVfile formats when importing and exporting Spanner data.

CapabilityAvro formatCSV format
Import or export an entire databaseYesNo
Ability to export only selected tables in a databaseYesYes
Ability to import previously exported tablesYesYes
Export at a past timestampYesYes
Import or export using Google Cloud CLIYesYes
Import or export using DataflowYesYes
Import or Export using SpannerYesNo

Avro files

When exporting to Avro format, you can specify alist of tables toexport. Anychild tablesexported this way need to be accompanied by their parent tables.Spanner maintains the entire database schema in the exportedfiles.

When importing from Avro format, Spanner recreates the exporteddatabase's whole schema, including all tables. Tables included in the originalexport receive all their exported data; all other tables remain empty.

The Spanner page of the Google Cloud console offers limitedAvro-format import and export options. For example, you can't set network andsubnetwork options. For a wider set of options, useDataflow instead.

Limitations

You can't export and importlocality groupsto the Avro format.

CSV files

You can export only a single Spanner table in the CSV format ata time. When you export, the schema is not exported, only the datais exported.

Before importing from CSV files, you need tocreate a JSON manifestfile.

Pricing

There are no additional charges from Spanner for using theexport or import tools; you pay the standard rates for data storage when youimport a database to Spanner. However, there are other potentialcharges associated with importing and exporting databases. For more information,seeDatabase export and import pricing.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.