序章

OrientDBは、グラフおよびドキュメントデータベースをサポートするマルチモデルのNoSQLデータベースです。 これはJavaアプリケーションであり、任意のオペレーティングシステムで実行できます。 また、マルチマスターレプリケーションのサポートにより完全にACIDに準拠しています。 これは、同じ名前の会社によって開発されており、EnterpriseエディションとCommunityエディションがあります。

この記事では、 GratefulDeadConcerts データベースを使用して、OrientDBデータベースをエクスポートおよびインポートする方法を示します。 そのデータベースはOrientDBのすべてのインストールに付属しているため、新しいデータベースを作成する必要はありません。

前提条件

チュートリアルを完了するには、次のものが必要です。

これらすべてが整ったら、始めましょう。

ステップ1—既存のOrientDBデータベースをエクスポートする

OrientDBデータベースをインポートするには、最初にインポートするDBをエクスポートする必要があります。 このステップでは、インポートする必要のあるデータベースをエクスポートします。

OrientDBが実行されていない場合は、次のように起動します。

  1. sudo service orientdb start

実行されているかどうかわからない場合は、いつでもステータスを確認できます。

  1. sudo service orientdb status

次に、OrientDBコンソールを使用してサーバーに接続します。

  1. sudo -u orientdb /opt/orientdb/bin/console.sh

出力は次のようになります。

Output
OrientDB console v.2.1.3 (build UNKNOWN@r; 2015-10-04 10:56:30+0000) www.orientdb.com Type 'help' to display all the supported commands. Installing extensions for GREMLIN language v.2.6.0 orientdb>

エクスポートするデータベースに接続します。 ここでは、データベースのデフォルトユーザーadminとそのパスワードadminを使用して、GratefulDeadConcertsデータベースに接続しています。

  1. connect plocal:/opt/orientdb/databases/GratefulDeadConcerts admin admin

次のような出力が表示されます。

Output
Connecting to database [plocal:/opt/orientdb/databases/GratefulDeadConcerts] with user 'admin'...OK orientdb {db=GratefulDeadConcerts}>

または、リモートモードを使用してデータベースに接続することもできます。これにより、複数のユーザーが同じデータベースにアクセスできます。

  1. connect remote:127.0.0.1/GratefulDeadConcerts admin admin

接続出力は次のようなものである必要があります。

Output
Disconnecting from the database [null]...OK Connecting to database [remote:127.0.0.1/GratefulDeadConcerts] with user 'admin'...OK orientdb {db=GratefulDeadConcerts}>

次に、データベースをエクスポートします。 exportコマンドは、現在のデータベースをgzipで圧縮されたJSONファイルにエクスポートします。 この例では、OrientDBのデータベースディレクトリ/opt/orientdb/databasesにエクスポートしています。

  1. export database /opt/orientdb/databases/GratefulDeadConcerts.export

ターゲットデータベースの完全なエクスポートコマンド出力は次のとおりです。

Output
Exporting current database to: database /opt/orientdb/databases/GratefulDeadConcerts.export in GZipped JSON format ... Started export of database 'GratefulDeadConcerts' to /opt/orientdb/databases/GratefulDeadConcerts.export.gz... Exporting database info...OK Exporting clusters...OK (15 clusters) Exporting schema...OK (14 classes) Exporting records... - Cluster 'internal' (id=0)...OK (records=3/3) - Cluster 'index' (id=1)...OK (records=5/5) - Cluster 'manindex' (id=2)...OK (records=1/1) - Cluster 'default' (id=3)...OK (records=0/0) - Cluster 'orole' (id=4)...OK (records=3/3) - Cluster 'ouser' (id=5)...OK (records=3/3) - Cluster 'ofunction' (id=6)...OK (records=0/0) - Cluster 'oschedule' (id=7)...OK (records=0/0) - Cluster 'orids' (id=8)...OK (records=0/0) - Cluster 'v' (id=9).............OK (records=809/809) - Cluster 'e' (id=10)...OK (records=0/0) - Cluster 'followed_by' (id=11).............OK (records=7047/7047) - Cluster 'written_by' (id=12).............OK (records=501/501) - Cluster 'sung_by' (id=13).............OK (records=501/501) - Cluster '_studio' (id=14)...OK (records=0/0) Done. Exported 8873 of total 8873 records Exporting index info... - Index OUser.name...OK - Index dictionary...OK - Index ORole.name...OK OK (3 indexes) Exporting manual indexes content... - Exporting index dictionary ...OK (entries=0) OK (1 manual indexes) Database export completed in 60498ms

これでエクスポート手順は完了です。

ドロップレットに対して別のターミナルを開き、データベースディレクトリの内容を一覧表示します。

  1. ls -lh /opt/orientdb/databases

元のデータベースとデータベースエクスポート用の圧縮ファイルが表示されます。

Output
total 164K drwxr-xr-x 2 orientdb orientdb 4.0K Nov 27 02:36 GratefulDeadConcerts -rw-r--r-- 1 orientdb orientdb 158K Nov 27 14:19 GratefulDeadConcerts.export.gz

OrientDBコンソールを使用してターミナルに戻り、次のように入力して現在のデータベースから切断できます。

  1. disconnect

正常に切断されると、次のような出力が得られます。

Output
Disconnecting from the database [GratefulDeadConcerts]...OK orientdb>

次の手順で使用するため、コンソールへの接続は開いたままにします。

ステップ2—データベースをインポートする

このステップでは、ステップ1でエクスポートしたデータベースをインポートします。 デフォルトでは、データベースをインポートすると、インポート先のデータの既存のデータが上書きされます。 したがって、最初にターゲットデータベースに接続します。 この例では、手順1で使用したデフォルトのデータベースに接続します。

  1. connect plocal:/opt/orientdb/databases/GratefulDeadConcerts admin admin

次を使用して接続することもできます。

  1. connect remote:127.0.0.1/GratefulDeadConcerts admin admin

どちらの出力も次のようになります。

Output
Connecting to database [remote:127.0.0.1/GratefulDeadConcerts] with user 'admin'...OK orientdb {db=GratefulDeadConcerts}>

接続が確立されたら、エクスポートされたファイルをインポートしましょう。

  1. import database /opt/orientdb/databases/GratefulDeadConcerts.export.gz

インポートするレコードの数によっては、これには数分以上かかる場合があります。 だから、座ってリラックスするか、お気に入りの液体のそのカップに手を伸ばしてください。

インポート出力は次のようになります(出力は切り捨てられます)。

Output
Importing database database /opt/orientdb/databases/GratefulDeadConcerts.export.gz... Started import of database 'remote:127.0.0.1/GratefulDeadConcerts' from /opt/orientdb/databases/GratefulDeadConcerts.export.gz... Non merge mode (-merge=false): removing all default non security classes ... Done. Imported 8,865 records in 915.51 secs Importing indexes ... - Index 'OUser.name'...OK - Index 'dictionary'...OK - Index 'ORole.name'...OK Done. Created 3 indexes. Importing manual index entries... - Index 'dictionary'...OK (0 entries) Done. Imported 1 indexes. Rebuild of stale indexes... Stale indexes were rebuilt... Deleting RID Mapping table...OK Database import completed in 1325943 ms

これで、データベースから切断できます。

  1. disconnect

OrientDBコンソールを終了し、通常のシェルプロンプトに戻り、exitと入力します。

  1. exit

結論

OrientDBデータベースをエクスポートおよびインポートする方法を見てきました。 インポート/エクスポート機能はプロセス全体でデータベースをロックしないため、プロセスの実行中にデータベースが書き込みを受信する可能性があることに注意してください。 このトピックの詳細については、公式のOrientDBエクスポート/インポートガイドを参照してください。