Xcopy
更新時間 2025-02-05 09:37:29
最近更新時間: 2025-02-05 09:37:29
分享文章
本頁為您介紹Xcopy的簡介和使用方法。
Xcopy模塊是支持數據遷移功能的重要組成部分。該模塊不僅支持元數據的遷移,還支持表數據的遷移,并提供四種不同的遷移粒度,包括集群級別、數據庫級別、Schema級別和表級別的數據遷移。
初始化實例
通過pgxc_ctl新建一個雙CN、雙DN的實例,并開啟服務。
使用Xcopy進行數據遷移
表級別數據遷移。
./Xcopy --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password '源庫密碼' --dest-host 目標庫host --dest-port 目標庫端口 --dest-user 目標庫用戶 --dest-password '目標庫密碼' --include-table 表名 --truncate模式級別數據遷移。
./Xcopy --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password '源庫密碼' --dest-host 目標庫host --dest-port 源庫端口 --dest-user 目標庫用戶 --dest-password '目標庫密碼' --schema schema名 --dest-schema schema名 --truncate數據庫級別數據遷移。
./Xcopy --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password '源庫密碼' --dest-host 目標庫host --dest-port 源庫端口 --dest-user 目標庫用戶 --dest-password '目標庫密碼' --dbname "xcopydb" --dest-dbname "xcopydb" --truncate-cascade實例級別數據遷移。
./Xcopy --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password '源庫密碼' --dest-host 目標庫host --dest-port 源庫端口 --dest-user 目標庫用戶 --dest-password '目標庫密碼'--truncate-cascade
使用Xcheck進行數據對比驗證
表級別對比
./Xcheck --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password "源庫密碼" --dest-host 目標庫host --dest-port 目標庫端口 --dest-user 目標庫用戶 --dest-password "目標庫密碼" --mapping-file "mapping-file絕對路徑" --mode high;模式級別對比
./Xcheck --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password "源庫密碼" --dest-host 目標庫host --dest-port 目標庫端口 --dest-user 目標庫用戶 --dest-password "目標庫密碼" --dbname postgres --dest-dbname postgres --schema 模式名 --dest-schema 模式名 --mode high庫級別對比
./Xcheck --source-host 源庫host --source-port 源庫端口 --source-user 源庫用戶 --source-password "源庫密碼" --dest-host 目標庫host --dest-port 目標庫端口 --dest-user 目標庫用戶 --dest-password "目標庫密碼" --dbname "庫名" --dest-dbname "庫名" --mode high
使用Ximport導入數據
在機器上創建名為control_file2的control_file文件,并寫入數據庫實例和需要導入的表的相關信息
執行以下語法導入指定表
./Ximport --control_file 'control_file文件絕對路徑' --host 實例host --port 實例端口 --user root --database ximport --force_password_auth
使用Xexport導出數據
執行以下語法導出指定表:
../Xexport -h 實例host -p 實例端口 -u 用戶名 -s '密碼' -d "Xexport" -r \"AllcolumnCopy\".\"Test_1\" -o '導出文件名稱1' -i '~' -z 'none' -l \"N_smallint\",n_integer -c 'UTF-8' -w 'where "N_smallint">1'