Edit on Github

Migration and Backup

Migration or Backup by Copying

One method to migrate data across TypeDB distributions is by copying the data directory between servers. To do this, simply shut down the servers, and copy the database you wish to migrate from the server/data/ directory into the server/data/ directory in the destination distribution (or just update the server configuration for data directory path).

TypeDB will prevent you from moving data across incompatible database encoding versions.

Database encoding Version Compatible TypeDB Versions
0 2.0.0 - 2.5.0
1 2.6.0 - 2.7.1
2 2.8.0 -

Migration or Backup using Export/Import

TypeDB offers a way to export all data into a binary format, and then re-import it elsewhere. Using the export feature is the best way to migrate to a version of TypeDB that is not backward compatible.

Migration or backup using the export/import features is a two-step process: schema migration, followed by data migration.

Note that this binary file is often two times larger than the original database. Please ensure your disk has sufficient free capacity to store a file of this size. If your have to migrate data that will not fit onto disk, please reach out to us on our Discord community or Forum where we can advise you further.

Schema Migration

The first step of migration is to migrate your schema. The command database schema my-database-name in Console allows you to get the current schema of a database as a single define query. This schema query can then be loaded via the Console to the new server.

Export the old schema using console (the old server must be running for this):

old/typedb console
> database schema [database]

Copy the schema into a file named schema.tql.

You can skip the step of exporting schema if you already have a copy of your schema to import.

You may need to update your schema syntax if the TypeQL language definitions have changed between TypeDB versions.

We then load the schema into the new TypeDB distribution:

new/typedb console
> database create <database> 
> transaction <database> schema write
[database]::schema::write> source <path to schema.tql>
[database]::schema::write> commit

Data Migration

To create a binary export of a data from a TypeDB database, make sure that the TypeDB server you wish to export from is running. After the server is running, use the following command that ships with typedb:

typedb server export --database=[database] --port=[server rpc port] --file=[filename].typedb

Note that this will NOT export the schema, only data. This file contains a complete copy of the data of the source database.

After the import completes, you can import the exported binary data into the prepared database containing your schema:

typedb server import --database=[database] --port=[server rpc port] --file=[filename].typedb
In versions previous to 2.6.0, the "--database=" and "--file=" named arguments are not used, and you should simply use positional arguments like this: "old/typedb server export {database} data.typedb" or "old/typedb server import --database={database} --file=data.typedb"

Dealing With Export/Import Errors

If you encounter migration errors, follow this checklist:

  • Ensure that you are running the correct typedb command (the binary in the TypeDB directory of the server you are exporting from or importing to.)
  • Ensure that the schema has been imported correctly to the new database.
  • Ensure that the correct data import path was specified.

If you have any further errors, please join one of our communities and ask for assistance.