SurrealDB Docs Logo

Enter a search query

Export command

The export command exports a SurrealQL script file from a local or remote SurrealDB database server.

BEFORE YOU START

Make sure you’ve installed SurrealDB — it should only take a second!

Syntax

Export a database as a SurrealQL script
surreal export [OPTIONS] --namespace <NAMESPACE> --database <DATABASE> [FILE]

Command options

ArgumentsDescription

-e / --endpoint / --conn

optional

Sets the url of the database server to connect to. Defaults to http://127.0.0.1:8000 if not specified

-u / --user

required

Sets master username for the database

-p / --pass

required

Sets master password for the database

-t / --token

optional

Sets the authentication token to use when connecting to the server. Connect to SurrealDB using a JWT instead of user credentials

--ns

required

Sets the desired namespace in which to export data

--db

required

Sets the desired database into which to export data

Export options

ArgumentsDescription

--only

optional

Whether only specific resources should be exported. When provided, only the resources specified will be exported.

--users

optional

Whether system users should be exported [possible values: true, false].

--accesses

optional

Whether access methods (Record or JWT) should be exported [possible values: true, false]

--params

optional

Whether databases parameters should be exported [possible values: true, false]

--functions

optional

Whether functions should be exported [possible values: true, false]

--analyzers

optional

Whether analyzers should be exported [possible values: true, false]

--tables [tables]

optional

Whether tables should be exported, optionally providing a list of tables

--versions

optional

Whether SurrealKV versioned records should be exported [possible values: true, false]

--records

optional

Whether records should be exported [possible values: true, false]

-l / --log

optional

The logging level for the command-line tool [default: info] [possible values: none, full, error, warn, info, debug, trace]

Positional argument

ArgumentsDescription

file

optional

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.

surreal export --conn http://localhost:8000 --user root --pass root --ns test --db test export.surql

Using token based authentication

surreal export --conn http://localhost:8000 --token <token> --ns test --db test export.surql

OPTION IMPORT

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.

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.

surreal export --help

The output of the above command :

Usage: surreal export [OPTIONS] --namespace <NAMESPACE> --database <DATABASE> [FILE] Arguments: [FILE] Path to the SurrealQL file to export. Use dash - to write into stdout. [default: -] Options: -e, --endpoint <ENDPOINT> Remote database server url to connect to [default: ws://localhost:8000] [aliases: conn] -u, --username <USERNAME> Database authentication username to use when connecting [env: SURREAL_USER=] [aliases: user] -p, --password <PASSWORD> Database authentication password to use when connecting [env: SURREAL_PASS=] [aliases: pass] -t, --token <TOKEN> Authentication token in JWT format to use when connecting [env: SURREAL_TOKEN=] --auth-level <AUTH_LEVEL> Level on which the authenticating user is defined [env: SURREAL_AUTH_LEVEL=] [default: root] [possible values: root, namespace, ns, database, db] --namespace <NAMESPACE> The namespace selected for the operation [env: SURREAL_NAMESPACE=] [aliases: ns] --database <DATABASE> The database selected for the operation [env: SURREAL_DATABASE=] [aliases: db] --only Whether only specific resources should be exported --users [<USERS>] Whether users should be exported [possible values: true, false] --accesses [<ACCESSES>] Whether access methods should be exported [possible values: true, false] -l, --log <LOG> The logging level for the command-line tool [env: SURREAL_LOG=] [default: info] [possible values: none, full, error, warn, info, debug, trace] --params [<PARAMS>] Whether params should be exported [possible values: true, false] --functions [<FUNCTIONS>] Whether functions should be exported [possible values: true, false] --analyzers [<ANALYZERS>] Whether analyzers should be exported [possible values: true, false] --tables [<TABLES>] Whether tables should be exported, optionally providing a list of tables --versions [<VERSIONS>] Whether versions should be exported [possible values: true, false] --records [<RECORDS>] Whether records should be exported [possible values: true, false] -h, --help Print help

Using environment variables

When using the surreal export command, you can also use environment variables to set the values for the command-line flags.

Important

Most of the flags mentioned in the command output above also mention a corresponding environment variables.

For example, the --username flag can be configured with the SURREAL_USER environment variable instead.

For more on the environment variables available for CLI commands or SurrealDB instances in general, see the environment variables page.