TDengine產(chǎn)品提供一個數(shù)據(jù)庫數(shù)據(jù)的導入導出DUMP工具,從而支持數(shù)據(jù)的遷移。比如從某家公有云遷移到另外一家公有云。
DUMP工具導出數(shù)據(jù)時,以sql語句的形式導出內(nèi)容,包括數(shù)據(jù)庫、超級表、普通表,以及表中的記錄數(shù)據(jù),然后保存到指定的輸出文件中。
DUMP工具導入數(shù)據(jù)時,將導出的文件作為輸入,順序讀入并執(zhí)行文件中的sql語句,完成數(shù)據(jù)的導入。
(工具的參數(shù)內(nèi)容有可能因版本更新而改變,請以 help 實際輸出的聯(lián)機幫助信息為準。)
DUMP命令幫助信息
root@taos-ec1:/dump# ./taosdump --help
Usage: taosdump [OPTION...] dbname [tbname ...]
or: taosdump [OPTION...] --databases dbname ...
or: taosdump [OPTION...] --all-databases
or: taosdump [OPTION...] -i inpath
or: taosdump [OPTION...] -o outpath
-h, --host=HOST Server host dumping data from. Default is
localhost.
-p, --password=PASSWORD User password to connect to server. Default is
taosdata.
-P, --port=PORT Port to connect
-q, --mysqlFlag=MYSQLFLAG mysqlFlag, Default is 0
-u, --user=USER User name used to connect to server. Default is
root.
-v, --cversion=CVERION client version
-c, --config=CONFIG_DIR Configure directory. Default is
/etc/taos/taos.cfg.
-e, --encode=ENCODE Input file encoding.
-g, --debug Print debug info.
-i, --inpath=INPATH Input file path.
-o, --outpath=OUTPATH Output file path.
-r, --resultFile=RESULTFILE DumpOut/In Result file path and name.
--verbose Print verbose debug info.
-A, --all-databases Dump all databases.
-D, --databases Dump assigned databases
-a, --allow-sys Allow to dump sys database
-B, --data-batch=DATA_BATCH Number of data point per insert statement.
Default is 1.
-E, --end-time=END_TIME End time to dump. Either Epoch or ISO8601/RFC3339
format is acceptable. Epoch precision millisecond.
ISO8601 format example:
2017-10-01T18:00:00.000+0800 or
2017-10-0100:00:00.000+0800 or '2017-10-01
00:00:00.000+0800'
-L, --max-sql-len=SQL_LEN Max length of one sql. Default is 65480.
-N, --without-property Dump schema without properties.
-s, --schemaonly Only dump schema.
-S, --start-time=START_TIME Start time to dump. Either Epoch or
ISO8601/RFC3339 format is acceptable. Epoch
precision millisecond. ISO8601 format example:
2017-10-01T18:00:00.000+0800 or
2017-10-0100:00:00.000+0800 or '2017-10-01
00:00:00.000+0800'
-t, --table-batch=TABLE_BATCH Number of table dumpout into one output file.
Default is 1.
-T, --thread_num=THREAD_NUM Number of thread for dump in file. Default is
5.
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to <support@taosdata.com>.
導出命令說明
導出數(shù)據(jù)時,可以使用不同的方式,比如導出所有數(shù)據(jù)庫的數(shù)據(jù);導出指定一個或多個數(shù)據(jù)庫的數(shù)據(jù);導出指定一個數(shù)據(jù)庫中指定一個或多個表的數(shù)據(jù);僅僅導出schema。同時,以上方式時,還可以指定數(shù)據(jù)的時間范圍。下面分別舉例描述。
1、導出所有數(shù)據(jù)庫的數(shù)據(jù)
root@taos-ec1:/dump# ./taosdump -c /dump/cfg -o /dump/data-data0601-0701 -u jason -p abcd -A -S 1559318400000 -E 1561910400000 -t 500 -B 80 -T 8
-c : 指定配置文件所在的路徑。因為dump會啟動taos客戶端,去鏈接taosd服務,所以需要做好配置文件。
-o:指定輸出文件的路徑。文件會自動生成,一個dbs.sql文件,導出數(shù)據(jù)庫、超級表;若干個XXX_tables.N.sql文件,文件名的規(guī)則:XXX是數(shù)據(jù)庫名稱,N是數(shù)字,從0開始遞增。
-u:用戶名。
-p:密碼。
-A:指示導出所有數(shù)據(jù)庫的數(shù)據(jù)。
-S:指定導出記錄的開始時間。Unix時間戳,單位:毫秒。該示例中時間是2019/6/1 0:0:0。
-E:指定導出記錄的最后時間。Unix時間戳,單位:毫秒。該示例中時間是2019/7/1 0:0:0
-t:指定導入到一個文件的表的個數(shù)。該參數(shù)可以控制輸出文件的大小。
-B:指定一條import語句中包含記錄的條數(shù)。注意:不要讓sql語句超過64k,否則后續(xù)導入會出錯。該參數(shù)為了后續(xù)導入時,提高導入速率。
-T: 指定導出數(shù)據(jù)時,啟動的線程數(shù)。建議設置成機器上core的2倍。
2、導出指定數(shù)據(jù)庫的數(shù)據(jù)
root@taos-ec1:/dump# ./taosdump -c /dump/cfg -o /dump/data-data0601-0701 -u jason -p abcd -D dbname1 dbname2 -S 1559318400000 -E 1561910400000 -t 500 -B 100 -T 8
-D:指定僅導出dbname1和dbname2的所有數(shù)據(jù)。
3、導出指定數(shù)據(jù)庫中指定表的數(shù)據(jù)
root@taos-ec1:/dump# ./taosdump -c /dump/cfg -o /dump/data-data0601-0701 -u jason -p abcd dbname1 tablename1 tablename2 -S 1559318400000 -E 1561910400000 -t 500 -B 100 -T 8
指定導出dbname1數(shù)據(jù)庫中tablename1和tablename2的數(shù)據(jù)。
4、僅僅導出schema
root@taos-ec1:/dump# ./taosdump -c /dump/cfg -o /dump/data-data0601-0701 -u jason -p abcd -A -S 1559318400000 -E 1561910400000 -t 500 -s -T 8
-s:僅僅導出所有數(shù)據(jù)庫的schema,即數(shù)據(jù)庫、超級表、普通表,但不導出表中的記錄。
導出完成后,在指定的輸出目錄下生成若干.sql的文件。
導入命令說明
將導出的所有文件(由于文件比較大,建議進行壓縮,傳輸?shù)侥康臋C器上后,再解壓),拷貝到一個路徑下,比如/tmp路徑。導入數(shù)據(jù)時,需要指定導入文件所在的目錄。
root@ecs-17fe:# ./taosdump -c /tmp/cfg -u jason -p abcd -i /tmp/data0601-0701 -T 8
-i:導入文件所在路徑。
-T:指定導入數(shù)據(jù)時,啟動的線程數(shù)。建議設置成機器上core的2倍。
校驗
完成導入后,可以隨機執(zhí)行一些查詢,在相同的查詢條件下,導出前與導入后的記錄條數(shù)是否相同。比如
taos> select count(*) from table_name;
taos> select count(*) from super_table where ts >= 1559318400000 and ts <= 1561910400000;



互聯(lián)網(wǎng).png)



-1.png)












伙伴.png)



