

如需與 Amazon Timestream for LiveAnalytics 類似的功能，請考慮使用 Amazon Timestream for InfluxDB。它提供簡化的資料擷取和單一位數毫秒查詢回應時間，以進行即時分析。[在這裡](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)進一步了解。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 遷移概觀
<a name="timestream-for-influx-getting-started-migrating-data-overview"></a>

符合先決條件後：

1. 執行遷移指令碼：使用您選擇的終端應用程式，執行 Python 指令碼，將資料從來源 InfluxDB 執行個體傳輸到目的地 InfluxDB 執行個體。

1. 提供登入資料：提供主機地址和連接埠做為 CLI 選項。

1. 驗證資料：確保資料正確傳輸者：

   1. 使用 InfluxDB UI 並檢查儲存貯體。

   1. 使用 列出儲存貯體`influx bucket list -t <destination token> --host <destination host address> --skip-verify`。

   1. 使用 `influx v1 shell -t <destination token> --host <destination host address> --skip-verify`和 執行 `SELECT * FROM <migrated bucket>.<retention period>.<measurement name> LIMIT 100 to view contents of a bucket or SELECT COUNT(*) FROM <migrated bucket>.<retention period>.<measurment name>`來驗證已遷移的正確記錄數量。

**Example 範例執行**  

1. 開啟您選擇的終端應用程式，並確保已正確安裝必要的先決條件：  
![\[指令碼先決條件。\]](http://docs.aws.amazon.com/zh_tw/timestream/latest/developerguide/images/script-pre-reqs.png)

1. 導覽至遷移指令碼：  
![\[指令碼位置\]](http://docs.aws.amazon.com/zh_tw/timestream/latest/developerguide/images/script-navigate.png)

1. 準備以下資訊：

   1. 要遷移的來源儲存貯體名稱。

   1. （選用） 選擇目的地伺服器中已遷移儲存貯體的新儲存貯體名稱。

   1. 來源和目的地流入執行個體的根字符。

   1. 來源和目的地流入執行個體的主機地址。

   1. （選用） S3 AWS Command Line Interface 儲存貯體名稱和登入資料；憑證應在作業系統環境變數中設定。

      ```
      # AWS credentials (for timestream testing)
          export AWS_ACCESS_KEY_ID="xxx"
          export AWS_SECRET_ACCESS_KEY="xxx"
      ```

   1. 將命令建構為：

      ```
      python3 influx_migration.py --src-bucket [amzn-s3-demo-source-bucket]  --dest-bucket [amzn-s3-demo-destination-bucket] --src-host [source host] --dest-host [dest host] --s3-bucket [amzn-s3-demo-bucket2](optional) --log-level debug
      ```

   1. 執行指令碼：  
![\[指令碼執行\]](http://docs.aws.amazon.com/zh_tw/timestream/latest/developerguide/images/script-execution.png)

   1. 等待指令碼完成執行。

   1. 檢查新遷移的儲存貯體的資料完整性，`performance.txt`。此檔案位於執行指令碼的相同目錄下，包含每個步驟所採取時間的一些基本資訊。

## 遷移案例
<a name="timestream-for-influx-migration-scenarios"></a>

**Example 範例 1：使用本機儲存的簡易遷移**  
您想要將單一儲存貯體 amzn-s3-demo-primary-bucket 從來源伺服器遷移`(http://localhost:8086)`至目的地伺服器 `(http://dest-server-address:8086)`。  
在確保您擁有在連接埠 8086 上託管 InfluxDB 執行個體的兩部機器的 TCP 存取 （用於 HTTP 存取） 之後`INFLUX_DEST_TOKEN`，您同時擁有來源和目的地字符，並分別將其儲存為環境變數 `INFLUX_SRC_TOKEN`和 ，以提高安全性：  

```
python3 influx_migration.py --src-bucket amzn-s3-demo-primary-bucket --src-host http://localhost:8086 --dest-host http://dest-server-address:8086
```
輸出格式應類似以下內容：  

```
INFO: influx_migration.py: Backing up bucket data and metadata using the InfluxDB CLI
2023/10/26 10:47:15 INFO: Downloading metadata snapshot
2023/10/26 10:47:15 INFO: Backing up TSM for shard 1
2023/10/26 10:47:15 INFO: Backing up TSM for shard 8245
2023/10/26 10:47:15 INFO: Backing up TSM for shard 8263
[More shard backups . . .]
2023/10/26 10:47:20 INFO: Backing up TSM for shard 8240
2023/10/26 10:47:20 INFO: Backing up TSM for shard 8268
2023/10/26 10:47:20 INFO: Backing up TSM for shard 2
INFO: influx_migration.py: Restoring bucket data and metadata using the InfluxDB CLI
2023/10/26 10:47:20 INFO: Restoring bucket "96c11c8876b3c016" as "amzn-s3-demo-primary-bucket"
2023/10/26 10:47:21 INFO: Restoring TSM snapshot for shard 12772
2023/10/26 10:47:22 INFO: Restoring TSM snapshot for shard 12773
[More shard restores . . .]
2023/10/26 10:47:28 INFO: Restoring TSM snapshot for shard 12825
2023/10/26 10:47:28 INFO: Restoring TSM snapshot for shard 12826
INFO: influx_migration.py: Migration complete
```
目錄`influxdb-backup-<timestamp>`將建立並儲存在執行指令碼的目錄中，其中包含備份檔案。



**Example 範例 2：使用本機儲存和偵錯記錄進行完整遷移**  
與上述相同，但您想要遷移所有儲存貯體、字符、使用者和儀表板、刪除目的地伺服器中的儲存貯體，以及使用 `--confirm-full`選項繼續進行，而無需使用者確認完整的資料庫遷移。您也想要查看什麼是效能測量，以便啟用偵錯記錄。  

```
python3 influx_migration.py --full --confirm-full --src-host http://localhost:8086 --dest-host http://dest-server-address:8086 --log-level debug
```
輸出格式應類似以下內容：  

```
INFO: influx_migration.py: Backing up bucket data and metadata using the InfluxDB CLI
2023/10/26 10:55:27 INFO: Downloading metadata snapshot
2023/10/26 10:55:27 INFO: Backing up TSM for shard 6952
2023/10/26 10:55:27 INFO: Backing up TSM for shard 6953
[More shard backups . . .]
2023/10/26 10:55:36 INFO: Backing up TSM for shard 8268
2023/10/26 10:55:36 INFO: Backing up TSM for shard 2
DEBUG: influx_migration.py: backup started at 2023-10-26 10:55:27 and took 9.41 seconds to run.
INFO: influx_migration.py: Restoring bucket data and metadata using the InfluxDB CLI
2023/10/26 10:55:36 INFO: Restoring KV snapshot
2023/10/26 10:55:38 WARN: Restoring KV snapshot overwrote the operator token, ensure following commands use the correct token
2023/10/26 10:55:38 INFO: Restoring SQL snapshot
2023/10/26 10:55:39 INFO: Restoring TSM snapshot for shard 6952
2023/10/26 10:55:39 INFO: Restoring TSM snapshot for shard 6953
[More shard restores . . .]
2023/10/26 10:55:49 INFO: Restoring TSM snapshot for shard 8268
2023/10/26 10:55:49 INFO: Restoring TSM snapshot for shard 2
DEBUG: influx_migration.py: restore started at 2023-10-26 10:55:36 and took 13.51 seconds to run.
INFO: influx_migration.py: Migration complete
```



**Example 範例 3：使用 CSV、目的地組織和 S3 儲存貯體進行完整遷移**  
與先前的範例相同，但使用 Linux 或 Mac 並將檔案存放在 S3 儲存貯體 中`amzn-s3-demo-bucket`。這可避免備份檔案超過本機儲存容量。  

```
python3 influx_migration.py --full --src-host http://localhost:8086 --dest-host http://dest-server-address:8086 --csv --dest-org MyOrg --s3-bucket amzn-s3-demo-bucket
```
輸出格式應類似以下內容：  

```
INFO: influx_migration.py: Creating directory influxdb-backups
INFO: influx_migration.py: Mounting amzn-s3-demo-influxdb-migration-bucket
INFO: influx_migration.py: Creating directory influxdb-backups/amzn-s3-demo-bucket/influxdb-backup-1698352128323
INFO: influx_migration.py: Backing up bucket data and metadata using the InfluxDB v2 API
INFO: influx_migration.py: Restoring bucket data and metadata from csv
INFO: influx_migration.py: Restoring bucket amzn-s3-demo-some-bucket
INFO: influx_migration.py: Restoring bucket amzn-s3-demo-another-bucket
INFO: influx_migration.py: Restoring bucket amzn-s3-demo-primary-bucket
INFO: influx_migration.py: Migration complete
INFO: influx_migration.py: Unmounting influxdb-backups
INFO: influx_migration.py: Removing temporary mount directory
```