cockroachdb

Copying data from one CockroachDB cluster to another


I’m looking to copy the data from a production CockroachDB database to a development server. I know that in Postgres, I can directly connect the database servers through pg_dump and psql. What's the quickest, easiest way of doing this in CockroachDB?


Solution

  • The easiest way is probably to just create a dump through cockroach dump, and then import the SQL file it generates onto the new server:

    cockroach dump --host=prodhost dbname > backup.sql
    cockroach sql --host=devhost -e 'CREATE DATABASE dbname'
    cockroach sql --host=devhost --database=dbname < backupsql
    

    If all you really care to copy is the database's schema (e.g. if you’re moving from dev to production), you can do so by adding the --dump-mode=schema option to the cockroach dump command.