Sign In

SurrealDB CLI

/

CLI commands

export

A command to export data from a SurrealDB database server into a SurrealQL file format.

Export an existing database as a SurrealQL script, either to a file or to stdout.

Note

Before you start - make sure you’ve installed SurrealDB.

Usage
surreal export [OPTIONS] --namespace <NAMESPACE> --database <DATABASE> [FILE]

Arguments

NameDefaultDescription
[FILE]
-Path to the SurrealQL file to write. Use a dash (-) to write into stdout, which is the default and can be redirected using >.

Options

NameDefaultEnvironment variableDescription
--endpoint, -e<ENDPOINT>
http://localhost:8000NoneDatabase endpoint to export from. Alias: --conn.
--username, -u<USERNAME>
NoneSURREAL_USERDatabase authentication username to use when connecting. Alias: --user.
--password, -p<PASSWORD>
NoneSURREAL_PASSDatabase authentication password to use when connecting. Alias: --pass.
--token, -t<TOKEN>
NoneSURREAL_TOKENAuthentication token in JWT format, used instead of a username and password.
--auth-level<AUTH_LEVEL>
rootSURREAL_AUTH_LEVELLevel on which the authenticating user is defined. Possible values: root, namespace (ns), database (db).
--namespace<NAMESPACE>
required
NoneSURREAL_NAMESPACEThe namespace to export from. Alias: --ns.
--database<DATABASE>
required
NoneSURREAL_DATABASEThe database to export from. Alias: --db.
--log, -l<LOG>
infoSURREAL_LOGThe logging level for the command-line tool. Possible values: none, full, error, warn, info, debug, trace.

Authenticate with either --username and --password, or with --token. Neither is needed against a server started with --unauthenticated.

By default an export contains everything in the database. These flags narrow it down.

Export options

NameDescription
--only
Whether only specific resources should be exported. When provided, only the resources named by the flags below are exported.
--users[<USERS>]
Whether system users should be exported. Possible values: true, false.
--accesses[<ACCESSES>]
Whether access methods (record or JWT) should be exported. Possible values: true, false.
--params[<PARAMS>]
Whether database parameters 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 SurrealKV versioned records should be exported. Possible values: true, false.
--records[<RECORDS>]
Whether records should be exported. Possible values: true, false.

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 secret --ns main --db main export.surql

Using token-based authentication:

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

Most of the flags above have a corresponding environment variable.
For example, the --username flag can be configured with the SURREAL_USER environment variable instead.

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.

To export from a SurrealDB Cloud instance by name, surrealctl resolves the endpoint and credentials for you and then runs this command. The flags and file-format notes on this page still apply.

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.

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:

Export an existing database as a SurrealQL script

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>      Database endpoint to export from [default: http://localhost:8000]
  -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]
      --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

Logging:
  -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]
      --log-format <LOG_FORMAT>                The format for terminal log output [env: SURREAL_LOG_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-socket <LOG_SOCKET>                Send logs to the specified host:port [env: SURREAL_LOG_SOCKET=]
      --log-file-level <LOG_FILE_LEVEL>        Override the logging level for file output [env: SURREAL_LOG_FILE_LEVEL=] [possible values:
                                               none, full, error, warn, info, debug, trace]
      --log-otel-level <LOG_OTEL_LEVEL>        Override the logging level for OpenTelemetry output [env: SURREAL_LOG_OTEL_LEVEL=] [possible
                                               values: none, full, error, warn, info, debug, trace]
      --log-socket-level <LOG_SOCKET_LEVEL>    Override the logging level for unix socket output [env: SURREAL_LOG_SOCKET_LEVEL=] [possible
                                               values: none, full, error, warn, info, debug, trace]
      --log-socket-format <LOG_SOCKET_FORMAT>  The format for socket output [env: SURREAL_LOG_SOCKET_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-file-enabled                       Whether to enable log file output [env: SURREAL_LOG_FILE_ENABLED=]
      --log-file-path <LOG_FILE_PATH>          The directory where log files will be stored [env: SURREAL_LOG_FILE_PATH=] [default: logs]
      --log-file-name <LOG_FILE_NAME>          The name of the log file [env: SURREAL_LOG_FILE_NAME=] [default: surrealdb.log]
      --log-file-format <LOG_FILE_FORMAT>      The format for log file output [env: SURREAL_LOG_FILE_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-file-rotation <LOG_FILE_ROTATION>  The log file rotation interval [env: SURREAL_LOG_FILE_ROTATION=] [default: daily] [possible
                                               values: daily, hourly, never]

Was this page helpful?