Export command
The export command exports a SurrealQL script file from a local or remote SurrealDB database server.
BEFORE YOU START
Syntax
Command options
| Arguments | Description |
|---|---|
-e / --endpoint / --conn
| Sets the url of the database server to connect to. Defaults to http://127.0.0.1:8000 if not specified |
-u / --user
| Sets master username for the database |
-p / --pass
| Sets master password for the database |
-t / --token
| Sets the authentication token to use when connecting to the server. Connect to SurrealDB using a JWT instead of user credentials |
--ns
| Sets the desired namespace in which to export data |
--db
| Sets the desired database into which to export data |
Export options
| Arguments | Description |
|---|---|
--only
| Whether only specific resources should be exported. When provided, only the resources specified will be exported. |
--users
| Whether system users should be exported [possible values: true, false]. |
--accesses
| Whether access methods (Record or JWT) should be exported [possible values: true, false] |
--params
| Whether databases parameters should be exported [possible values: true, false] |
--functions
| Whether functions should be exported [possible values: true, false] |
--analyzers
| Whether analyzers should be exported [possible values: true, false] |
--tables [tables]
| Whether tables should be exported, optionally providing a list of tables |
--versions
| Whether SurrealKV versioned records should be exported [possible values: true, false] |
--records
| Whether records should be exported [possible values: true, false] |
-l / --log
| The logging level for the command-line tool [default: info] [possible values: none, full, error, warn, info, debug, trace] |
Positional argument
| Arguments | Description |
|---|---|
file
|
Sets the path to the file which should be exported. If not provided, export data will be printed to stdout (and can thus be redirected using >).
|
Example usage
To perform a SurrealQL database export into a local file, in a terminal run the surreal export command with the required arguments.
Using token-based authentication:
Using environment variables
Important
When using the surreal export command, you can also use environment variables to set the values for the command-line flags.
For more on the environment variables available for CLI commands or SurrealDB instances in general, see the environment variables page.
OPTION IMPORT keyword
The output of a database export includes a line that contains the keywords OPTION IMPORT. This command is used internally to ensure that side effects do not run when the data is imported, such as events and table views.
As of SurrealDB 3.0.4, imports via the surreal import and /import HTTP endpoint require the automatically generated OPTION IMPORT line to be present in order to disable events, live queries, field processing, and result output for optimal import performance. If side effects are desired when importing data, remove the line and use the /sql endpoint instead.
Command help
To see the help information and usage instructions, in a terminal run the surreal export --help command without any further arguments. This command gives general information on the arguments, inputs, and additional options for the export command.
The output of the above command :