Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

43 lines
10 KiB
HTML

<a name="mrs_01_24292"></a><a name="mrs_01_24292"></a>
<h1 class="topictitle1">Backing Up and Restoring ClickHouse Data Using a Data File</h1>
<div id="body0000001213828401"><div class="section" id="mrs_01_24292__section1679317551859"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_24292__p79281945151012">This section describes how to back up data by exporting ClickHouse data to a CSV file and restore data using the CSV file.</p>
</div>
<div class="section" id="mrs_01_24292__section992817454108"><h4 class="sectiontitle">Prerequisites</h4><ul id="mrs_01_24292__ul19281345101017"><li id="mrs_01_24292__li13928134520102">You have installed the ClickHouse client.</li><li id="mrs_01_24292__li19928145181016">You have created a user with related permissions on ClickHouse tables on Manager.</li><li id="mrs_01_24292__li6928164515108">You have prepared a server for backup.</li></ul>
</div>
<div class="section" id="mrs_01_24292__section1999010433103"><h4 class="sectiontitle">Backing Up Data</h4><ol id="mrs_01_24292__ol16928124513104"><li id="mrs_01_24292__li5928174516108"><span>Log in to the node where the client is installed as the client installation user.</span></li><li id="mrs_01_24292__li1792874591010"><span>Run the following command to go to the client installation directory:</span><p><p id="mrs_01_24292__p192811458102"><strong id="mrs_01_24292__b392816458101">cd /opt/client</strong></p>
</p></li><li id="mrs_01_24292__li1892844511102"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_24292__p492834541010"><strong id="mrs_01_24292__b1392813452103">source bigdata_env</strong></p>
</p></li><li id="mrs_01_24292__li1910333418475"><span>If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the current user. The current user must have the permission to create ClickHouse tables. If Kerberos authentication is disabled for the current cluster, skip this step.</span><p><ol type="a" id="mrs_01_24292__ol105001049105617"><li id="mrs_01_24292__li874145945616">Run the following command if it is an MRS 3.1.0 cluster:<p id="mrs_01_24292__p1957917005718"><a name="mrs_01_24292__li874145945616"></a><a name="li874145945616"></a><strong id="mrs_01_24292__b5766124418552">export CLICKHOUSE_SECURITY_ENABLED=true</strong></p>
</li><li id="mrs_01_24292__li89311551185611"><strong id="mrs_01_24292__b936123635310">kinit</strong> <em id="mrs_01_24292__i442236105313">Component service user</em><p id="mrs_01_24292__p23600116552">Example: <strong id="mrs_01_24292__b1976844017533">kinit clickhouseuser</strong></p>
</li></ol>
</p></li><li id="mrs_01_24292__li109284457109"><span>Run the ClickHouse client command to export the ClickHouse table data to be backed up to a specified directory.</span><p><p id="mrs_01_24292__p19287456105"><strong id="mrs_01_24292__b209281245161017">clickhouse client --host </strong><em id="mrs_01_24292__i17928134514109">Host name/Instance IP address</em><strong id="mrs_01_24292__b392834551013"> --secure --port 9440 --query=</strong>"<em id="mrs_01_24292__i89281145131017">Table query statement</em>" &gt; <em id="mrs_01_24292__i10928144521019">Path of the exported CSV file</em></p>
<p id="mrs_01_24292__p169281945191014">The following shows an example of backing up data in the <strong id="mrs_01_24292__b817867479104742">test</strong> table to the <strong id="mrs_01_24292__b878269331104742">default_test.csv</strong> file on the ClickHouse instance <strong id="mrs_01_24292__b1677069001104742">10.244.225.167</strong>.</p>
<p id="mrs_01_24292__p3928124519104"><strong id="mrs_01_24292__b10928124561015">clickhouse client --host 10.244.225.167 --secure --port 9440 --query="select * from default.test FORMAT CSV" &gt; /opt/clickhouse/default_test.csv</strong></p>
</p></li><li id="mrs_01_24292__li189281545161013"><span>Upload the exported CSV file to the backup server.</span></li></ol>
</div>
<div class="section" id="mrs_01_24292__section899217431104"><h4 class="sectiontitle">Restoring Data</h4><ol id="mrs_01_24292__ol189290452101"><li id="mrs_01_24292__li59297455105"><span>Upload the backup data file on the backup server to the directory where the ClickHouse client is located.</span><p><p id="mrs_01_24292__p19929154531016">For example, upload the <strong id="mrs_01_24292__b1301709311104742">default_test.csv</strong> backup file to the <strong id="mrs_01_24292__b1436077636104742">/opt/clickhouse</strong> directory.</p>
</p></li><li id="mrs_01_24292__li792918452107"><span>Log in to the node where the client is installed as the client installation user.</span></li><li id="mrs_01_24292__li18929114571016"><span>Run the following command to go to the client installation directory:</span><p><p id="mrs_01_24292__p192964511103"><strong id="mrs_01_24292__b20929194531010">cd /opt/client</strong></p>
</p></li><li id="mrs_01_24292__li209298458107"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_24292__p99291845151018"><strong id="mrs_01_24292__b9929845121015">source bigdata_env</strong></p>
</p></li><li id="mrs_01_24292__li7827626191010"><span>If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the current user. The current user must have the permission to create ClickHouse tables. If Kerberos authentication is disabled for the current cluster, skip this step.</span><p><ol type="a" id="mrs_01_24292__ol9827726101016"><li id="mrs_01_24292__li1382715264106">Run the following command if it is an MRS 3.1.0 cluster:<p id="mrs_01_24292__p178271526111010"><a name="mrs_01_24292__li1382715264106"></a><a name="li1382715264106"></a><strong id="mrs_01_24292__b3827226111010">export CLICKHOUSE_SECURITY_ENABLED=true</strong></p>
</li><li id="mrs_01_24292__li4827102691014"><strong id="mrs_01_24292__b13688165315537">kinit</strong> <em id="mrs_01_24292__i8694853115310">Component service user</em><p id="mrs_01_24292__p108271026131018">Example: <strong id="mrs_01_24292__b177411355135312">kinit clickhouseuser</strong></p>
</li></ol>
</p></li><li id="mrs_01_24292__li29293451102"><span>Run the ClickHouse client command to log in to the ClickHouse cluster.</span><p><p id="mrs_01_24292__p1929184520101"><strong id="mrs_01_24292__b179298455101">clickhouse client --host </strong><em id="mrs_01_24292__i1092984511011">Host name/Instance IP address</em><strong id="mrs_01_24292__b16929194521018"> --secure</strong><strong id="mrs_01_24292__b392924511106"> --port 9440</strong></p>
</p></li><li id="mrs_01_24292__li14929104515101"><a name="mrs_01_24292__li14929104515101"></a><a name="li14929104515101"></a><span>Create a table with the format corresponding to the CSV file.</span><p><p id="mrs_01_24292__p89295452109"><strong id="mrs_01_24292__b1965049723104742">CREATE TABLE [IF NOT EXISTS] </strong><em id="mrs_01_24292__i1523353835104742">[database_name.]table_name</em><strong id="mrs_01_24292__b85456425104742"> [ON CLUSTER </strong><em id="mrs_01_24292__i1654915186104742">Cluster name</em><strong id="mrs_01_24292__b357075138104742">]</strong></p>
<p id="mrs_01_24292__p11929144591016"><strong id="mrs_01_24292__b17929144510101">(</strong></p>
<p id="mrs_01_24292__p15929184591018"><strong id="mrs_01_24292__b1592984514100"></strong><em id="mrs_01_24292__i14929194511015">name1</em><strong id="mrs_01_24292__b09291145131016"> [</strong><em id="mrs_01_24292__i3929945101016">type1</em><strong id="mrs_01_24292__b2929174518106">] [DEFAULT|</strong><em id="mrs_01_24292__i2092954518109">materialized</em><strong id="mrs_01_24292__b13929845131012">|ALIAS </strong><em id="mrs_01_24292__i16929124571011">expr1</em><strong id="mrs_01_24292__b7929194511017">],</strong></p>
<p id="mrs_01_24292__p209292454104"><strong id="mrs_01_24292__b6929114511018"></strong><em id="mrs_01_24292__i1392910454104">name2</em><strong id="mrs_01_24292__b169291545141010"><em id="mrs_01_24292__i79291145151011"> </em>[</strong><em id="mrs_01_24292__i69299455109">type2</em><strong id="mrs_01_24292__b59292458102">] [DEFAULT|</strong><em id="mrs_01_24292__i79291945191017">materialized</em><strong id="mrs_01_24292__b1493014456108">|ALIAS </strong><em id="mrs_01_24292__i169303457100">expr2</em><strong id="mrs_01_24292__b49301645121018">],</strong></p>
<p id="mrs_01_24292__p13930445121020"><strong id="mrs_01_24292__b593064521015">...</strong></p>
<p id="mrs_01_24292__p79301945191019"><strong id="mrs_01_24292__b189301145101012">) </strong><em id="mrs_01_24292__i12930144512109">ENGINE</em> = <em id="mrs_01_24292__i2930144518109">engine</em></p>
</p></li><li id="mrs_01_24292__li293064518109"><span>Import the content in the backup file to the table created in <a href="#mrs_01_24292__li14929104515101">7</a> to restore data.</span><p><p id="mrs_01_24292__p1993017457105"><strong id="mrs_01_24292__b79301645181011">clickhouse client --host </strong><em id="mrs_01_24292__i1693015456107">Host name/Instance IP address</em> <strong id="mrs_01_24292__b39303456103">--secure --port 9440 --query=</strong>"<strong id="mrs_01_24292__b1593004541011">insert into </strong><em id="mrs_01_24292__i393019450107">Table name</em> <strong id="mrs_01_24292__b593017454103">F</strong><strong id="mrs_01_24292__b20930164561019">ORMAT CSV</strong>" <strong id="mrs_01_24292__b18930184551012">&lt; </strong><em id="mrs_01_24292__i4930104581010">CSV file path</em></p>
<p id="mrs_01_24292__p11930144518107">The following shows an example of restoring data from the <strong id="mrs_01_24292__b914717579104742">default_test.csv</strong> backup file to the <strong id="mrs_01_24292__b958181822104742">test_cpy</strong> table on the ClickHouse instance <strong id="mrs_01_24292__b1734660232104742">10.244.225.167</strong>.</p>
<p id="mrs_01_24292__p13930134541016"><strong id="mrs_01_24292__b1993084510107">clickhouse client --host </strong><strong id="mrs_01_24292__b169302453100">10.244.225.167 </strong><strong id="mrs_01_24292__b19301145131010">--secure --port 9440 --query=</strong><strong id="mrs_01_24292__b1493044501017">"insert into default.test_cpy FORMAT CSV" &lt; /opt/clickhouse/default_test.csv</strong></p>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_2344.html">Using ClickHouse</a></div>
</div>
</div>