|
1 | 1 | = Database Export & Import
|
2 | 2 |
|
3 |
| -[placeholder] |
4 |
| -Export and import TypeDB databases. |
| 3 | +Use TypeDB's built-in export functionality to export a database as a complete TypeQL schema file and a binary containing the instances in the database. |
| 4 | + |
| 5 | +The built-in import functionality can be used to create a database from an exported data binary and a complete schema. |
| 6 | + |
| 7 | +Exported binary data is designed to be identical across any version of TypeDB. This means you can reload your database in versions of TypeDB that are no longer compatible on the data layer (such as moving from TypeDB 2.x to 3.x). |
| 8 | + |
| 9 | +[IMPORTANT] |
| 10 | +==== |
| 11 | +This feature is introduced in TypeDB 3.4.0. If you want to export or import a database from earlier versions of TypeDB 3.x, simply update your server and client and follow this manual. |
| 12 | +
|
| 13 | +You can import your databases exported from TypeDB 2.x following xref:{page-version}@manual::migration/2_to_3/process.adoc[this guide]. |
| 14 | +==== |
| 15 | + |
| 16 | +== Understanding export and import |
| 17 | + |
| 18 | +TypeDB database can be represented as two files: |
| 19 | + |
| 20 | +[#_files] |
| 21 | +1. A text file with its TypeQL schema description: a complete `define` query for the whole schema. |
| 22 | +2. A binary file with its data. |
| 23 | + |
| 24 | +An exported database can be imported into another version of TypeDB using these two files. |
| 25 | +This is the best tool you can use to migrate a database between two incompatible versions of TypeDB (e.g., a migration xref:{page-version}@manual::migration/2_to_3/process.adoc[from TypeDB 2.x to TypeDB 3.x]). |
| 26 | + |
| 27 | +Both operations are performed through the network, but the server and the client can be used on the same host. |
| 28 | + |
| 29 | +Examples below use xref:{page-version}@new_home::install/console-cli.adoc[TypeDB Console] as the most accessible client for these operations. |
| 30 | +Please check the xref:{page-version}@new_reference::typedb-grpc-drivers/index.html[gRPC Drivers API] to explore available programmatic commands. |
| 31 | + |
| 32 | +[#_export] |
| 33 | +== Export |
| 34 | + |
| 35 | +Database export allows a client to download xref:#_files[database schema and data files] from a TypeDB server for future import to the same or higher TypeDB version. |
| 36 | + |
| 37 | +The files are created on the client side. |
| 38 | +The exported binary file might be up to two times larger than the original database. |
| 39 | +If the client connects to a remote host, the server's disk remains unchanged, thus introducing zero risks to the stability of the server. |
| 40 | +Please ensure the client's disk has enough free capacity to store a file of this size. |
| 41 | + |
| 42 | +While the database data is being exported, parallel transactions are allowed, but none of them will affect the exported data thanks to TypeDB's xref:{page-version}@new_core_concepts::typedb/transactions.adoc[transactional nature]. |
| 43 | +However, the database will not be available for operations such as deletion. |
| 44 | + |
| 45 | +[NOTE] |
| 46 | +==== |
| 47 | +The files can be incomplete and corrupted if the export operation is interrupted by the user. Please restart and obtain a complete data file in one attempt. |
| 48 | +==== |
| 49 | + |
| 50 | +=== Using TypeDB Console |
| 51 | + |
| 52 | +1. Make sure that your TypeDB Server is running. |
| 53 | + |
| 54 | +2. Follow xref:{page-version}@new_tools::console.adoc[Console page] to set up a connection. |
| 55 | + |
| 56 | +3. Execute `database export database-name schema.typeql data.typedb`, where |
| 57 | + |
| 58 | +- `database-name` is the name of the exported database; |
| 59 | +- `schema.typeql` is the exported schema definition file path; |
| 60 | +- `data.typedb` is the exported data file path. |
| 61 | + |
| 62 | +4. The result (either `Successfully exported database` or an error) will be printed to the Console. |
| 63 | + |
| 64 | +== Import |
| 65 | + |
| 66 | +Database import allows a client to upload previously exported xref:#_files[database schema and data files] to a TypeDB server. |
| 67 | + |
| 68 | +For your safety, the imported database should not exist on the target server. |
| 69 | +It is possible to assign any new name to the imported database. |
| 70 | + |
| 71 | +[NOTE] |
| 72 | +==== |
| 73 | +The database will be incomplete (and thus not recommended for usage) if the import operation is interrupted. |
| 74 | +It is expected to be automatically removed from the disk, but a small number of unexpected technical issues can prevent this from happening. |
| 75 | +A server restart will resolve any related issues. |
| 76 | +==== |
| 77 | + |
| 78 | +=== Using TypeDB Console |
| 79 | + |
| 80 | +1. Make sure that your TypeDB Server is running. |
| 81 | + |
| 82 | +2. Follow xref:{page-version}@new_tools::console.adoc[Console page] to set up a connection. |
| 83 | + |
| 84 | +3. Execute `database import database-name schema.typeql data.typedb`, where |
| 85 | + |
| 86 | +- `database-name` is the new name of the imported database; |
| 87 | +- `schema.typeql` is the imported schema definition file path; |
| 88 | +- `data.typedb` is the imported data file path. |
| 89 | + |
| 90 | +4. The result (either `Successfully imported database` or an error) will be printed to the Console. |
| 91 | + |
| 92 | +== Troubleshooting |
| 93 | + |
| 94 | +Follow this checklist if any errors occur: |
| 95 | + |
| 96 | +* Ensure that you use xref:{page-version}@new_tools::console.adoc#version-compatibility[compatible] TypeDB Server and TypeDB Console. |
| 97 | +* Ensure that the correct file paths were specified for the operations. |
| 98 | +* If you import a TypeDB 2.x database, some errors may be expected. |
| 99 | +Check out xref:{page-version}@manual::migration/2_to_3/process.adoc[this page] for a detailed guide. |
| 100 | + |
| 101 | +If any errors persist, please join one of our communities and ask for assistance. |
0 commit comments