• Start

Methods

import

The .import() method for the SurrealDB Rust SDK restores the database from a file.

Restores the database from a file.

Note

WebSocket connections currently do not support exports and imports. Be sure to use an HTTP endpoint and the protocol-http feature when using this method.

Method Syntax
db.import(source)

The following example assumes the presence of a file called backup.surql in the same directory as the current project. To quickly create it, copy and paste the example for the .export() method.

use surrealdb::engine::any::connect;
use surrealdb::opt::auth::Root;

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
    let db = connect("http://localhost:8000").await?;
    db.signin(Root {
        username: "root".to_string(),
        password: "secret".to_string(),
    })
    .await?;
    db.use_ns("main").use_db("main").await?;
    db.import("backup.surql").await?;
    Ok(())
}

Was this page helpful?