taosdump
簡介
taosdump 是一個支持從運行中的 TDengine 服務器或集群中備份數據并將備份的數據恢復 到相同或另一個運行中的 TDengine 服務器或集群中的工具應用程序。
taosdump可以用數據庫、超級表或普通表作為邏輯數據單元備份,也可以對數據庫、超級 表和普通表中指定時間段內的數據記錄進行備份。您可以指定數據備份的目錄路徑,如果 不指定位置,taosdump默認會將數據備份到當前目錄。
如果指定的位置已經有數據文件,taosdump 會提示用戶并立即退出,避免數據被覆蓋。 如果您看到提示,請小心操作。
taosdump 是一個邏輯備份工具。它不打算或不應被期望用于備份任何原始數據、環境設置、 硬件信息、服務端配置或集群的拓撲結構。它使用 作為數據文件格式來存儲備份數據。
常用使用場景
taosdump 備份數據
- 指定 -A 或 --all-databases 參數指定所有數據庫;
- 使用 -D db1,db2,... 參數備份指定的多個數據庫;
- 使用 dbname stbname1 stbname2 tbname1 tbname2 ... 參數方式備份指定數據庫中的某些個超級表或普通表,注意這種輸入序列第一個參數為數據庫名稱,且只支持一個數據庫,第二個和之后的參數為該數據庫中的超級表或普通表名稱,中間以空格分隔;
- TDengine 服務器或集群通常會包含一個系統數據庫,名為 log,這個數據庫內的數據為 TDengine 自我運行的數據,taosdump 默認不會對 log 庫進行備份。如果有特定需求對 log 庫進行備份,可以使用 -a 或 --allow-sys 命令行參數。
- taosdump 1.4.1 之后的版本提供 -n 參數和 -L 參數,用于備份數據時不使用轉義字符和“寬容”模式,可以在表名、列名、標簽名沒使用轉義字符的情況下減少備份數據時間和備份數據占用空間。如果不確定符合使用 -n 和 -L 條件時請使用默認參數進行“嚴格”模式進行備份。轉義字符的說明請參考。
- taosdump 1.4.1 之后的版本提供 -I 參數,用于解析 avro 文件 schema 和數據,如果指定 -s 參數將只解析 schema。
- taosdump 1.4.2 之后的備份使用 -B 參數指定的批次數,默認值為 16384,如果在某些環境下由于網絡速度或磁盤性能不足導致 "Error actual dump .. batch .." 可以通過 -B 參數挑戰為更小的值進行嘗試。
taosdump恢復數據
- -i 加上數據文件所在路徑作為參數進行備份指定路徑下的數據文件。如前面提及,不應該使用同一個目錄備份不同數據集合,也不應該在同一路徑多次備份同一數據集,否則備份數據會造成覆蓋或多次備份。
- taosdump 內部使用 TDengine stmt binding API 進行恢復數據的寫入,為提高數據恢復性能,目前使用 16384 為一次寫入批次。如果備份數據中有比較多列數據,可能會導致產生 "WAL size exceeds limit" 錯誤,此時可以通過使用 -B 參數調整為一個更小的值進行嘗試。
詳細命令行參數列表
以下為 taosdump 詳細命令行參數列表:
Usage: taosdump [OPTION...] dbname [tbname ...]
or: taosdump [OPTION...] --databases db1,db2,...
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 User password to connect to server. Default is
taosdata.
-P, --port=PORT Port to connect
-u, --user=USER User name used to connect to server. Default is
root.
-c, --config-dir=CONFIG_DIR Configure directory. Default is /etc/taos
-i, --inpath=INPATH Input file path.
-o, --outpath=OUTPATH Output file path.
-r, --resultFile=RESULTFILE DumpOut/In Result file path and name.
-a, --allow-sys Allow to dump system database
-A, --all-databases Dump all databases.
-D, --databases=DATABASES Dump inputted databases. Use comma to separate
databases' name.
-N, --without-property Dump database without its properties.
-s, --schemaonly Only dump tables' schema.
-y, --answer-yes Input yes for prompt. It will skip data file
checking!
-d, --avro-codec=snappy Choose an avro codec among null, deflate, snappy,
and lzma.
-S, --start-time=START_TIME Start time to dump. Either epoch or
ISO8601/RFC3339 format is acceptable. ISO8601
format example: 2017-10-01T00:00:00.000+0800 or
2017-10-0100:00:00:000+0800 or '2017-10-01
00:00:00.000+0800'
-E, --end-time=END_TIME End time to dump. Either epoch or ISO8601/RFC3339
format is acceptable. ISO8601 format example:
2017-10-01T00:00:00.000+0800 or
2017-10-0100:00:00.000+0800 or '2017-10-01
00:00:00.000+0800'
-B, --data-batch=DATA_BATCH Number of data per query/insert statement when
backup/restore. Default value is 16384. If you see
'error actual dump .. batch ..' when backup or if
you see 'WAL size exceeds limit' error when
restore, please adjust the value to a smaller one
and try. The workable value is related to the
length of the row and type of table schema.
-I, --inspect inspect avro file content and print on screen
-L, --loose-mode Using loose mode if the table name and column name
use letter and number only. Default is NOT.
-n, --no-escape No escape char '`'. Default is using it.
-T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is
5.
-g, --debug Print debug info.
-?, --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@yakult-sh.com.cn>.

