doc-exports/docs/dds/umn/dds_03_0052.html
Ru, Li Yi cd74617674 dds_umn_20240415
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com>
Co-authored-by: Ru, Li Yi <liyiru7@huawei.com>
Co-committed-by: Ru, Li Yi <liyiru7@huawei.com>
2024-04-16 08:01:15 +00:00

47 lines
14 KiB
HTML

<a name="dds_03_0052"></a><a name="dds_03_0052"></a>
<h1 class="topictitle1">Migrating Data</h1>
<div id="body1483590975886"><div class="section" id="dds_03_0052__section25341248175518"><h4 class="sectiontitle"><strong id="dds_03_0052__b84235270694112">Scenarios</strong></h4><p id="dds_03_0052__p179130313313">DDS is accessible through an EIP in a public network or an ECS in a private network.</p>
<p id="dds_03_0052__p1987917225233">DDS is compatible with MongoDB.</p>
<p id="dds_03_0052__p6231217193316">MongoDB can export data from a database into a JSON file. Such a JSON file can then be used to import the data to MongoDB databases. This section describes how to import the data from the JSON files to DDS using the mongoimport tool on the ECS or from some other devices that can access DDS.</p>
</div>
<div class="section" id="dds_03_0052__section8361919133059"><h4 class="sectiontitle"><strong id="dds_03_0052__b1953218375354">Prerequisites</strong></h4><ol id="dds_03_0052__ol2066643918543"><li id="dds_03_0052__li4066879018543">An ECS or a device that can access DDS is ready for use.<ul id="dds_03_0052__ul1290878172911"><li id="dds_03_0052__li0324616723">To connect your DDS DB instance through a private network:<p id="dds_03_0052__p128286417211"><a name="dds_03_0052__li0324616723"></a><a name="li0324616723"></a>Create and log in to an ECS. For details, see "Creating and Logging In to a Windows ECS" or "Creating and Logging In to a Linux ECS" in the <em id="dds_03_0052__i382815413216">Elastic Cloud Server User Guide</em>.</p>
</li><li id="dds_03_0052__li10673162104619">To connect to your DDS DB instance through an EIP:<ol type="a" id="dds_03_0052__ol26742218464"><li id="dds_03_0052__li146741213461">Bind an EIP to a node in the DB instance. For details about how to bind an EIP to a node, see "Binding an <span id="dds_03_0052__text1047914561115"></span><span id="dds_03_0052__text666865920110">EIP</span>" in the <em id="dds_03_0052__i3657143112914">Document Database Service Getting Started</em>.</li><li id="dds_03_0052__li12674221184618">Ensure that your local device can access the EIP that has been bound to the DB instance.</li></ol>
</li></ul>
</li><li id="dds_03_0052__li19052705154115">A migration tool has been installed on the prepared <span id="dds_03_0052__text1556913312025">ECS</span><span id="dds_03_0052__text1956963111220"></span>.<p id="dds_03_0052__p26409019102443">For details on how to install the migration tool, see <a href="dds_faq_0018.html">How Can I Install a MongoDB Client?</a></p>
<div class="note" id="dds_03_0052__note953551144012"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dds_03_0052__en-us_topic_0171122382_en-us_topic_0086557045_p591496422051">The MongoDB client provides the mongoexport and mongoimport tools.</p>
</div></div>
</li></ol>
</div>
<div class="section" id="dds_03_0052__section990018367329"><h4 class="sectiontitle">Exporting Data (Linux example)</h4><ol id="dds_03_0052__ol1570028110480"><li id="dds_03_0052__li5891409715403"><span>Log in to the <span id="dds_03_0052__text16813175511210">ECS</span><span id="dds_03_0052__text98149553210"></span> or the device that can access DDS.</span></li><li id="dds_03_0052__li4576157710480"><span>Use the mongoexport tool to transfer data from the source database to a .json file.</span><p><p id="dds_03_0052__p46808964171510">The SSL connection is used as an example. If you select an unencrypted connection, delete <span class="parmname" id="dds_03_0052__parmname37221548172813"><b>--ssl --sslAllowInvalidCertificates</b></span> from the following command.</p>
<p id="dds_03_0052__p61927198103818"><strong id="dds_03_0052__b21833124131546">mongoexport</strong> <strong id="dds_03_0052__b16236922171331">--host</strong> <em id="dds_03_0052__i415091212315">&lt;</em><em id="dds_03_0052__i194601720113113">DB_ADDRESS&gt;</em> <strong id="dds_03_0052__b8932291171334"><em id="dds_03_0052__i30764941171334">--</em>port</strong> <em id="dds_03_0052__i55791432203116">&lt;DB_PORT&gt;</em> <strong id="dds_03_0052__b17283288171345"><em id="dds_03_0052__i22582995171345">--</em>ssl</strong> <strong id="dds_03_0052__b62003291171352">--sslAllowInvalidCertificates</strong> <strong id="dds_03_0052__b4002111318500">--type json</strong> <strong id="dds_03_0052__b31551052171359">--authenticationDatabase</strong> <em id="dds_03_0052__i4245654418376">&lt;AUTH_DB</em>&gt; <strong id="dds_03_0052__b59143543171913">-u</strong> <em id="dds_03_0052__i62861958123118">&lt;DB_USER&gt;</em> <strong id="dds_03_0052__b66924903171411">--db</strong> &lt;<em id="dds_03_0052__i23363254115444">DB_NAME</em>&gt; <strong id="dds_03_0052__b54003533171416">--collection</strong> &lt;<em id="dds_03_0052__i25006261115449">DB_COLLECTION</em>&gt; <strong id="dds_03_0052__b28895193171420">--out</strong> &lt;<em id="dds_03_0052__i56296162115454">DB_PATH</em>&gt;</p>
<ul id="dds_03_0052__ul2384687213137"><li id="dds_03_0052__li43070988123013"><strong id="dds_03_0052__b842352706142916">DB_ADDRESS</strong> indicates the database address.</li><li id="dds_03_0052__li52094574123013"><strong id="dds_03_0052__b842352706142950">DB_PORT</strong> indicates the database port.</li><li id="dds_03_0052__li1253841995344"><strong id="dds_03_0052__b15464191112913">AUTH_DB</strong> indicates the database for storing DB_USER information. Generally, this value is <strong id="dds_03_0052__b17464141172910">admin</strong>.</li><li id="dds_03_0052__li4699616313143"><strong id="dds_03_0052__b84235270614296">DB_USER</strong> indicates the database user.</li><li id="dds_03_0052__li3204611413140"><strong id="dds_03_0052__b84235270691837_1">DB_NAME</strong> indicates the name of the database from which data will be exported.</li><li id="dds_03_0052__li33079577144440"><strong id="dds_03_0052__b84235270691837">DB_COLLECTION</strong> indicates the collection of the database from which data will be exported.</li><li id="dds_03_0052__li42729876144614"><strong id="dds_03_0052__b84235270619336">DB_PATH</strong> indicates the path where the .json file is located.</li></ul>
<p id="dds_03_0052__p3262912019332">Enter the database administrator password when prompted:</p>
<pre class="screen" id="dds_03_0052__screen12074070144047">Enter password:</pre>
<p id="dds_03_0052__p64501241172158">The following is an example. After the command is executed, the <strong id="dds_03_0052__b842352706125455">exportfile.json</strong> file will be generated:</p>
<p id="dds_03_0052__p1113995103829"><strong id="dds_03_0052__b1751311417223">mongoexport --host 192.168.1.21 --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --out /tmp/***/export/exportfile.json</strong></p>
</p></li><li id="dds_03_0052__li5438645142216"><span>Check the result.</span><p><p id="dds_03_0052__p1043914456224">If information similar to the following is displayed, the data is successfully exported. <strong id="dds_03_0052__b842352706165959">x</strong> indicates the number of exported data records.</p>
<pre class="screen" id="dds_03_0052__screen643917454228">exported x records</pre>
</p></li><li id="dds_03_0052__li920101610480"><span>Compress the exported .json file.</span><p><p id="dds_03_0052__p15952100131610"><strong id="dds_03_0052__b1417981014599">gzip exportfile.json</strong></p>
<p id="dds_03_0052__p2358214720438">Compressing the file helps reduce the time needed to transmit all the data. The compressed file is <strong id="dds_03_0052__b84235270614716">exportfile.json.gz</strong>.</p>
</p></li></ol>
</div>
<div class="section" id="dds_03_0052__section5895195683218"><h4 class="sectiontitle">Importing Data</h4><ol id="dds_03_0052__ol15917364105457"><li id="dds_03_0052__li63620196162521"><span>Log in to the <span id="dds_03_0052__text3326510318">ECS</span><span id="dds_03_0052__text332855312"></span> or the device that can access DDS.</span></li><li id="dds_03_0052__li26104709101218"><span>Upload the data to be imported to the <span id="dds_03_0052__text16295121217312">ECS</span><span id="dds_03_0052__text52955128315"></span> or the device that can access DDS.</span><p><p id="dds_03_0052__p44871872101226">Select an uploading method based on the OS you are using. In Linux, for example, run the following command:</p>
<p id="dds_03_0052__p53569133103643">scp <em id="dds_03_0052__i14197154105014">&lt;</em><em id="dds_03_0052__i189201834185010">IDENTITY_FILE&gt;</em> <em id="dds_03_0052__i44339627121824">&lt;REMOTE_USER&gt;</em>@<em id="dds_03_0052__i63512328121824">&lt;REMOTE_ADDRESS&gt;</em>:<em id="dds_03_0052__i86871721051">&lt;REMOTE_DIR&gt;</em></p>
<ul id="dds_03_0052__ul1246777413455"><li id="dds_03_0052__li18291784143629"><strong id="dds_03_0052__b842352706153429">IDENTITY_FILE</strong> indicates the directory where the <strong id="dds_03_0052__b842352706154813">exportfile.json.gz</strong> file is located. The file access permission is 600.</li><li id="dds_03_0052__li3703922913455"><strong id="dds_03_0052__b281655191916">REMOTE_USER</strong> indicates the <span id="dds_03_0052__text925913191532">ECS</span><span id="dds_03_0052__text192595196317"></span> OS user.</li><li id="dds_03_0052__li4659824513458"><strong id="dds_03_0052__b92965713194">REMOTE_ADDRESS</strong> indicates the <span id="dds_03_0052__text128203241439">ECS</span><span id="dds_03_0052__text682022412318"></span> address.</li><li id="dds_03_0052__li395532491350"><strong id="dds_03_0052__b18412193210193">REMOTE_DIR</strong> indicates the directory of the <span id="dds_03_0052__text1673593012315">ECS</span><span id="dds_03_0052__text97354305314"></span> to which the <strong id="dds_03_0052__b11425123841919">exportfile.json.gz</strong> file is uploaded.</li></ul>
<p id="dds_03_0052__p16893486101822">In Windows, upload <strong id="dds_03_0052__b93631229207">exportfile.json.gz</strong> to the <span id="dds_03_0052__text186567361534">ECS</span><span id="dds_03_0052__text265617364317"></span> using file transfer tools.</p>
</p></li><li id="dds_03_0052__li36369718173231"><span>Decompress the package.</span><p><p id="dds_03_0052__p8394414103633"><strong id="dds_03_0052__b50978469181842">gzip</strong> <strong id="dds_03_0052__b52937645181838">-d</strong> <em id="dds_03_0052__i331793181833">exportfile.json.gz</em></p>
</p></li><li id="dds_03_0052__li2445426410440"><span>Import the JSON file to the DDS database.</span><p><p id="dds_03_0052__p35606744172151">The SSL connection is used as an example. If you select an unencrypted connection, delete <span class="parmname" id="dds_03_0052__parmname369235513117"><b>--ssl --sslAllowInvalidCertificates</b></span> from the following command.</p>
<p id="dds_03_0052__p5042734813226"><strong id="dds_03_0052__b2225308313226">mongoimport --host</strong> &lt;<em id="dds_03_0052__i64302601103659">DB_ADDRESS</em>&gt; <strong id="dds_03_0052__b16243656103724">--port</strong> &lt;<em id="dds_03_0052__i730668618236">DB_PORT</em>&gt; <strong id="dds_03_0052__b31514672103730">--ssl --sslAllowInvalidCertificates --type json --authenticationDatabase</strong> &lt;<em id="dds_03_0052__i56432904182313">AUTH_DB</em>&gt; <strong id="dds_03_0052__b28066016172239">-u</strong> &lt;<em id="dds_03_0052__i10276675103710">DB_USER</em>&gt; <strong id="dds_03_0052__b57950825103743">--db</strong> &lt;<em id="dds_03_0052__i47507271182242">DB_NAME</em>&gt; <strong id="dds_03_0052__b65641924163417">--collection</strong> &lt;<em id="dds_03_0052__i24872374182320">DB_COLLECTION</em>&gt; <strong id="dds_03_0052__b9589407103750">--file</strong> &lt;<em id="dds_03_0052__i60291707182254">DB_PATH</em>&gt;</p>
<ul id="dds_03_0052__ul4765694918197"><li id="dds_03_0052__li2625935718197"><strong id="dds_03_0052__b842352706113916">DB_ADDRESS</strong> indicates the DB instance IP address.</li><li id="dds_03_0052__li3500762618197"><strong id="dds_03_0052__b324076143212">DB_PORT</strong> indicates the database port.</li><li id="dds_03_0052__li4663317918197"><strong id="dds_03_0052__b158760714328">AUTH_DB</strong> indicates the database that authenticates DB_USER. Generally, this value is <strong id="dds_03_0052__b11876271322">admin</strong>.</li><li id="dds_03_0052__li1704543518197"><strong id="dds_03_0052__b842352706151123">DB_USER</strong> indicates the account name of the database administrator.</li><li id="dds_03_0052__li3850302618197"><strong id="dds_03_0052__b551802461">DB_NAME</strong> indicates the name of the database to which data will be imported.</li><li id="dds_03_0052__li1098291418197"><strong id="dds_03_0052__b84235270611467">DB_COLLECTION</strong> indicates the collection of the database to which data will be imported.</li><li id="dds_03_0052__li3173736418197"><strong id="dds_03_0052__b729625829">DB_PATH</strong> indicates the path where the .json file is located.</li></ul>
<p id="dds_03_0052__p97276105334">Enter the database administrator password when prompted:</p>
<pre class="screen" id="dds_03_0052__screen4226648614415">Enter password:</pre>
<p id="dds_03_0052__p372722118456">The following is an example:</p>
<p id="dds_03_0052__p822259510380"><strong id="dds_03_0052__b5082800817258">mongoimport --host 192.168.1.21 --port 8635 --ssl --sslAllowInvalidCertificates --type json --authenticationDatabase admin -u rwuser --db test02 --collection Test --file /tmp/***/export/exportfile.json</strong></p>
</p></li><li id="dds_03_0052__li6390418685132"><span>Check the result.</span><p><p id="dds_03_0052__p53979779102325">If information similar to the following is displayed, the data is successfully imported. <strong id="dds_03_0052__b670496285">x</strong> indicates the number of imported data records.</p>
<pre class="screen" id="dds_03_0052__screen4571661618329">imported x records</pre>
</p></li></ol>
</div>
</div>