如何通过Rest API导出Orient DB(2.2.x)数据库架构及数据?
Hey there! Let's walk through how to get a complete export of your demo2 database—including both schema and all your data—using OrientDB 2.2.x's HTTP API. Here are the key steps and tweaks to make this work smoothly:
1. Update Your GET Request with Critical Parameters
Your initial request is a good start, but you need to add parameters to ensure data is included alongside the schema. Here's the adjusted request:
GET http://localhost:2480/export/demo2?includeRecords=true&includeSchema=true&format=json
Let's break down what each parameter does:
includeRecords=true: This forces the export to pull in all your database records (documents, vertices, edges—everything stored in your classes)includeSchema=true: Explicitly ensures the export includes class definitions, properties, indexes, and other schema details (while this is often enabled by default, setting it explicitly avoids any unexpected omissions)format: Choose your output format.jsonis great for readability and manual edits,odbis a binary format optimized for fast imports, andxmlis another option if you need it for specific workflows.
2. Don't Skip Authentication
OrientDB's HTTP API requires valid credentials unless you've disabled security (which is not recommended for production). You have two main options:
- Basic Auth: Add an
Authorizationheader to your request. Encode your username:password as Base64, then use:
For example, if your username isAuthorization: Basic <base64-encoded-credentials>adminand password isadmin, the encoded string isYWRtaW46YWRtaW4=, so the header becomesAuthorization: Basic YWRtaW46YWRtaW4=. - Session Auth: First send a POST request to
http://localhost:2480/sessionwith your credentials to get a session ID, then include aCookieheader in your export request:Cookie: OSESSIONID=<your-session-id>
3. Handle Large Databases Gracefully
If your demo2 database is large, you might run into timeouts or memory issues. Fix this with:
batchSize=1000: Add this parameter to export records in smaller batches (adjust the number based on your database size)- Enable streaming downloads in your HTTP client: This prevents your client from trying to load the entire export file into memory at once.
4. Verify Your Export Worked
After the export completes, double-check the output to make sure everything is included:
- For JSON/XML exports: Open the file and confirm you see a
schemasection (with class definitions) followed by arecordssection (with your data entries) - For ODB exports: Test the import using OrientDB's console tool. Run
console.sh(orconsole.baton Windows), then execute:
This will confirm the schema and data are intact.import database /path/to/your/export.odb
5. Troubleshooting Common Snags
- 401 Unauthorized: Double-check your credentials and make sure your user has the
EXPORTpermission (the defaultadminuser has this by default) - 404 Not Found: Confirm the database name
demo2is spelled correctly and that the database is running in your OrientDB server - Empty Export: Ensure you added
includeRecords=true—without it, you'll only get the schema. Also, check that your database actually has data to export! - Request Timeout: Increase the
network.http.maxLengthsetting in yourorientdb-server-config.xmlfile to allow larger payloads, or use thebatchSizeparameter to split the export into chunks.
内容的提问来源于stack exchange,提问作者BonieZat

