介绍
OrientDB是一个多模型,NoSQL数据库,支持图形和文档数据库. 它是一个Java应用程序,可以在任何操作系统上运行。 它也是完全ACID认证,支持多主复制。
在本文中,我们将使用 GratefulDeadConcerts数据库来展示如何导出和导入一个OrientDB数据库。
前提条件
要完成教程,您将需要以下内容:
- Ubuntu 14.04 Droplet (请参见 初始安装指南)
- 使用 [如何在 Ubuntu 14.04 上安装和配置 OrientDB 的最新版本安装(https://andsky.com/tech/tutorials/how-to-install-and-configure-orientdb-on-ubuntu-14-04)
如果你把所有这些东西放在地方,让我们开始。
步骤 1 — 导出现有 OrientDB 数据库
要导入 OrientDB 数据库,您必须首先导出要导入的 DB. 在此步骤中,我们将导出我们需要导入的数据库。
如果 OrientDB 不运行,请启动:
1sudo service orientdb start
如果您不确定它是否正在运行,您可以随时检查其状态:
1sudo service orientdb status
然后使用 OrientDB 控制台连接到服务器:
1sudo -u orientdb /opt/orientdb/bin/console.sh
产量应该是:
1[secondary_label Output]
2OrientDB console v.2.1.3 (build UNKNOWN@r; 2015-10-04 10:56:30+0000) www.orientdb.com
3Type 'help' to display all the supported commands.
4Installing extensions for GREMLIN language v.2.6.0
5
6orientdb>
在这里,我们使用数据库的默认用户 admin和其密码 admin连接到 GratefulDeadConcerts数据库:
1connect plocal:/opt/orientdb/databases/GratefulDeadConcerts admin admin
你应该看到这样的输出:
1[secondary_label Output]
2Connecting to database [plocal:/opt/orientdb/databases/GratefulDeadConcerts] with user 'admin'...OK
3orientdb {db=GratefulDeadConcerts}>
或者,您也可以使用远程模式连接到数据库,该模式允许多个用户访问相同的数据库。
1connect remote:127.0.0.1/GratefulDeadConcerts admin admin
连接输出应该是这样的:
1[secondary_label Output]
2Disconnecting from the database [null]...OK
3Connecting to database [remote:127.0.0.1/GratefulDeadConcerts] with user 'admin'...OK
4orientdb {db=GratefulDeadConcerts}>
现在,导出数据库. 导出
命令将当前数据库导出到一个 gziped、压缩的 JSON 文件中. 在本例中,我们将其导出到 OrientDB 的数据库目录 /opt/orientdb/databases
:
1export database /opt/orientdb/databases/GratefulDeadConcerts.export
目标数据库的完整出口命令输出为:
1[secondary_label Output]
2Exporting current database to: database /opt/orientdb/databases/GratefulDeadConcerts.export in GZipped JSON format ...
3
4Started export of database 'GratefulDeadConcerts' to /opt/orientdb/databases/GratefulDeadConcerts.export.gz...
5Exporting database info...OK
6Exporting clusters...OK (15 clusters)
7Exporting schema...OK (14 classes)
8Exporting records...
9- Cluster 'internal' (id=0)...OK (records=3/3)
10- Cluster 'index' (id=1)...OK (records=5/5)
11- Cluster 'manindex' (id=2)...OK (records=1/1)
12- Cluster 'default' (id=3)...OK (records=0/0)
13- Cluster 'orole' (id=4)...OK (records=3/3)
14- Cluster 'ouser' (id=5)...OK (records=3/3)
15- Cluster 'ofunction' (id=6)...OK (records=0/0)
16- Cluster 'oschedule' (id=7)...OK (records=0/0)
17- Cluster 'orids' (id=8)...OK (records=0/0)
18- Cluster 'v' (id=9).............OK (records=809/809)
19- Cluster 'e' (id=10)...OK (records=0/0)
20- Cluster 'followed_by' (id=11).............OK (records=7047/7047)
21- Cluster 'written_by' (id=12).............OK (records=501/501)
22- Cluster 'sung_by' (id=13).............OK (records=501/501)
23- Cluster '_studio' (id=14)...OK (records=0/0)
24
25Done. Exported 8873 of total 8873 records
26
27Exporting index info...
28- Index OUser.name...OK
29- Index dictionary...OK
30- Index ORole.name...OK
31OK (3 indexes)
32Exporting manual indexes content...
33- Exporting index dictionary ...OK (entries=0)
34OK (1 manual indexes)
35
36Database export completed in 60498ms
这就完成了出口步骤。
打开您的 Droplet 中的另一个终端,并列出数据库目录的内容:
1ls -lh /opt/orientdb/databases
您应该看到原始数据库以及数据库导出的压缩文件:
1[secondary_label Output]
2total 164K
3drwxr-xr-x 2 orientdb orientdb 4.0K Nov 27 02:36 GratefulDeadConcerts
4-rw-r--r-- 1 orientdb orientdb 158K Nov 27 14:19 GratefulDeadConcerts.export.gz
在您的 OrientDB 控制台的终端上,您现在可以通过键入从当前数据库中断连接:
1disconnect
如果成功关闭,您应该获得类似的输出:
1[secondary_label Output]
2Disconnecting from the database [GratefulDeadConcerts]...OK
3orientdb>
保持与控制台的连接开放,因为您将在下一步使用它。
步骤 2 - 导入数据库
在此步骤中,我们将导入我们在步骤 1 中导出的数据库,默认情况下,导入数据库将重写正在导入的数据库中的现有数据。
1connect plocal:/opt/orientdb/databases/GratefulDeadConcerts admin admin
您也可以使用连接:
1connect remote:127.0.0.1/GratefulDeadConcerts admin admin
任何一个输出都应该类似于此:
1[secondary_label Output]
2Connecting to database [remote:127.0.0.1/GratefulDeadConcerts] with user 'admin'...OK
3orientdb {db=GratefulDeadConcerts}>
有了连接,让我们导入导出的文件:
1import database /opt/orientdb/databases/GratefulDeadConcerts.export.gz
根據要輸入的記錄數量,這可能需要超過幾分鐘,所以坐下來放鬆,或獲得你最喜歡的液體的杯子。
进口输出应是(输出缩略):
1[secondary_label Output]
2Importing database database /opt/orientdb/databases/GratefulDeadConcerts.export.gz...
3Started import of database 'remote:127.0.0.1/GratefulDeadConcerts' from /opt/orientdb/databases/GratefulDeadConcerts.export.gz...
4Non merge mode (-merge=false): removing all default non security classes
5
6...
7
8Done. Imported 8,865 records in 915.51 secs
9
10Importing indexes ...
11- Index 'OUser.name'...OK
12- Index 'dictionary'...OK
13- Index 'ORole.name'...OK
14Done. Created 3 indexes.
15Importing manual index entries...
16- Index 'dictionary'...OK (0 entries)
17Done. Imported 1 indexes.
18Rebuild of stale indexes...
19Stale indexes were rebuilt...
20Deleting RID Mapping table...OK
21
22Database import completed in 1325943 ms
您现在可以从数据库中断连接:
1disconnect
退出 OrientDB 控制台并返回正常壳提示,键入退出
:
1exit
结论
您刚刚看到如何导出和导入 OrientDB 数据库. 请注意,导入/导出功能不会在整个过程中锁定数据库,因此它可能会在进程发生时接收字符。