forked from laiweijian4/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Wang , Deng Ke <wangdengke2@huawei.com> Co-committed-by: Wang , Deng Ke <wangdengke2@huawei.com>
50 lines
13 KiB
HTML
50 lines
13 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__p22054755175523"><span id="dds_03_0052__text228175913513">DDS</span> supports access through EIPs by enabling public accessibility. You can also access a database through an ECS in the private network.</p>
|
|
<p id="dds_03_0052__p29873552142950">Before migrating data from a <span class="keyword" id="dds_03_0052__keyword1861275719541">MongoDB database</span> to DDS, transfer data to a .json file using the mongoexport tool. This section guides you on how to import the data from the JSON files to DDS using the mongoimport tool on the ECS or the device that can access DDS.</p>
|
|
</div>
|
|
<div class="section" id="dds_03_0052__section8361919133059"><h4 class="sectiontitle"><strong id="dds_03_0052__b842352706105728">Preparations</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__li3562141155411">To connect to a <span class="keyword" id="dds_03_0052__keyword1864364152619">DDS DB instance</span> from an ECS, you need to create and log in to the ECS. For details, see <a href="dds_faq_0034.html">How Can I Create and Log In to an ECS?</a></li><li id="dds_03_0052__li10673162104619">To bind an EIP to a <span class="keyword" id="dds_03_0052__keyword1731821712717">DB instance</span>:<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 and Unbinding an EIP" in section "Cluster" or "Replica Set".</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 ECS or the device.<p id="dds_03_0052__p26409019102443"><a name="dds_03_0052__li19052705154115"></a><a name="li19052705154115"></a>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</h4><ol id="dds_03_0052__ol1570028110480"><li id="dds_03_0052__li5891409715403"><span>Log in to the ECS 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 a common 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"><</em><em id="dds_03_0052__i194601720113113">DB_ADDRESS></em> <strong id="dds_03_0052__b8932291171334"><em id="dds_03_0052__i30764941171334">--</em>port</strong> <em id="dds_03_0052__i55791432203116"><DB_PORT></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"><AUTH_DB</em>> <strong id="dds_03_0052__b59143543171913">-u</strong> <em id="dds_03_0052__i62861958123118"><DB_USER></em> <strong id="dds_03_0052__b66924903171411">--db</strong> <<em id="dds_03_0052__i23363254115444">DB_NAME</em>> <strong id="dds_03_0052__b54003533171416">--collection</strong> <<em id="dds_03_0052__i25006261115449">DB_COLLECTION</em>> <strong id="dds_03_0052__b28895193171420">--out</strong> <<em id="dds_03_0052__i56296162115454">DB_PATH</em>></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/mongodb/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 ECS or the device that can access DDS.</span></li><li id="dds_03_0052__li26104709101218"><span>Upload the data to be imported to the ECS 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"><</em><em id="dds_03_0052__i189201834185010">IDENTITY_FILE></em> <em id="dds_03_0052__i44339627121824"><REMOTE_USER></em>@<em id="dds_03_0052__i63512328121824"><REMOTE_ADDRESS></em>:<em id="dds_03_0052__i86871721051"><REMOTE_DIR></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__en-us_topic_0085335422_b842352706173133">REMOTE_USER</strong> indicates the ECS OS user.</li><li id="dds_03_0052__li4659824513458"><strong id="dds_03_0052__en-us_topic_0085335422_b842352706173149">REMOTE_ADDRESS</strong> indicates the ECS address.</li><li id="dds_03_0052__li395532491350"><strong id="dds_03_0052__b1753053063119">REMOTE_DIR</strong> indicates the directory of the ECS to which the <strong id="dds_03_0052__b95311230173116">exportfile.json.gz</strong> file is uploaded.</li></ul>
|
|
<p id="dds_03_0052__p16893486101822">In Windows, upload <strong id="dds_03_0052__b842352706111053">exportfile.json.gz</strong> to the ECS 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 a common 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> <<em id="dds_03_0052__i64302601103659">DB_ADDRESS</em>> <strong id="dds_03_0052__b16243656103724">--port</strong> <<em id="dds_03_0052__i730668618236">DB_PORT</em>> <strong id="dds_03_0052__b31514672103730">--ssl --sslAllowInvalidCertificates --type json --authenticationDatabase</strong> <<em id="dds_03_0052__i56432904182313">AUTH_DB</em>> <strong id="dds_03_0052__b28066016172239">-u</strong> <<em id="dds_03_0052__i10276675103710">DB_USER</em>> <strong id="dds_03_0052__b57950825103743">--db</strong> <<em id="dds_03_0052__i47507271182242">DB_NAME</em>> <strong id="dds_03_0052__b65641924163417">--collection</strong> <<em id="dds_03_0052__i24872374182320">DB_COLLECTION</em>> <strong id="dds_03_0052__b9589407103750">--file</strong> <<em id="dds_03_0052__i60291707182254">DB_PATH</em>></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__b203415035">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__b1812466946">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/mongodb/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__b700155420">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>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dds_03_0001.html">Managing DDS DB Instances</a></div>
|
|
</div>
|
|
</div>
|
|
|