Skip to content
Last updated

SFTP Server Export Integration

このSFTP Server Export Integrationを使用すると、ワークフロージョブの結果をSFTPサーバーに直接送信できます。

前提条件

  • toolbeltを含むTreasure Dataの基本知識
  • SFTPサーバー

制限事項

  • パスプレフィックスには次の文字を含めることはできません: * ?
  • v.1では接続タイムアウト設定が正しく機能しないため、エクスポートジョブがタイムアウトする代わりに長時間実行される可能性があります。

Static IP Address of Treasure Data Integration

If your security policy requires IP whitelisting, you must add Treasure Data's IP addresses to your allowlist to ensure a successful connection.

Please find the complete list of static IP addresses, organized by region, at the following link:
https://api-docs.treasuredata.com/en/overview/ip-addresses-integrations-result-workers/

基本的な使用方法

次の図は、Treasure Data AgentsからSFTPまたは類似のサーバーへのデータのエクスポートを含む典型的な使用シナリオを示しています。

SFTPサーバーの資格情報を取得

SFTPサーバーにアクセスするための資格情報を取得します。

クエリの定義

  1. Data Workbench > Queriesに移動します。

  2. New Queryを選択します。

  3. クエリを実行して結果セットを検証します。

結果エクスポートターゲットの指定

  1. Export Resultsを選択します。

  1. 出力に使用する外部サービスの認証として、既存の統合または新しい統合を選択できます。以下のいずれかを選択します:

既存の統合を使用

新しい統合を作成

リモートSFTPインスタンスに必要な詳細と資格情報を入力します。

  • Host: リモートSFTPインスタンスのホスト情報(例: IPアドレス)。
  • Port: リモートSFTPインスタンスの接続ポート。デフォルトのポート番号は22です。
  • User: リモートFTPインスタンスへの接続に使用されるユーザー名。
  • Authentication mode: SFTPサーバーでの認証方法。
  • Secret key file: Authentication Modeとしてpublic / private key pairが選択されている場合は必須です。(キータイプEd25519はサポートされていませんが、DSA/RSA/ECDSAキータイプはサポートされています。)
  • Passphrase for secret key file: (オプション)必要な場合は、提供されたシークレットファイルのパスフレーズを提供します。
  • Retry limit: 失敗した接続を再試行する回数(デフォルト10)。
  • Timeout: 接続タイムアウト(秒)(デフォルト600)。

SFTPへのエクスポート情報を指定

Field Description
Is user directory Root?選択すると、ユーザーディレクトリがルートディレクトリとして扱われます。(例: /home/treasure-data/として)
Path prefixファイルが保存されるファイルパス
Rename file after upload finish選択すると、SFTP結果出力は、すべてのデータが転送された後、リモートSFTPサーバー上のファイル名を.xxx.tmpから.xxxに変更します。一部のMAツールは、SFTPサーバーに特定の名前のファイルが存在する場合にデータをインポートしようとします。一時名オプションは、このようなケースで役立ちます。
Formatエクスポートされたファイルのフォーマット:
  • csv (カンマ区切り)
  • tsv (タブ区切り)
Encoders
  • None - エンコーダーは適用されません(デフォルト)
  • GZ - アップロード前にgzipを使用してファイルが圧縮されます
  • BZIP2 - アップロード前にbzip2を使用してファイルが圧縮されます
  • PGP Encryption - アップロード前に公開鍵を使用してファイルが暗号化されます

Public Key

EncoderがPGP暗号化の場合は必須

アップロード前にファイルを暗号化するために使用される公開鍵

Key Identifier

EncoderがPGP暗号化の場合は必須

ファイルを保護するために使用される暗号化サブキーのKey IDを指定します。マスターキーは暗号化プロセスから除外されます。

Armor

オプション

ASCIIアーマーを使用するかどうか

Compression Type

SFTPサーバーへのアップロードのために暗号化の前に圧縮されるファイルを圧縮するために使用される圧縮アルゴリズムを定義します。

暗号化してアップロードする前にファイルを圧縮してください。復号化すると、ファイルは.gzや.bz2などの圧縮形式に戻ります。

Header line?ヘッダー行には、最初の行として列名が含まれます
Delimiter区切り文字:
  • Default - ,
  • Tab
  • |
Quote policy引用符のポリシー:
  • ALL
  • MINIMAL: 区切り文字、引用符、またはlineterminatorの任意の文字を含むフィールドにのみ引用符文字を追加します
  • NONE
Null stringクエリの結果のnull値の表示方法:
  • Default - 空文字列
  • \N
  • NULL
  • null
End-of-line characterEOL(end-of-line)文字:
  • CRLF
  • LF
  • CR

Temp filesize threshold

ローカル一時ファイルの最大ファイルサイズ(バイト単位)。一時ファイルがしきい値に達すると、ファイルはリモートファイルにフラッシュされます。

channel is brokenエラーが発生した場合は、このオプションの値を減らしてエラーを解決してください。

(Optional) Schedule Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.

Treasure Data's scheduler feature supports periodic query execution to achieve high availability.

When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.

For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.

Scheduling your Job Using TD Console

  1. Navigate to Data Workbench > Queries

  2. Create a new query or select an existing query.

  3. Next to Schedule, select None.

  4. In the drop-down, select one of the following schedule options:

    Drop-down ValueDescription
    Custom cron...Review Custom cron... details.
    @daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
    @hourly (:00)Run every hour at 00 minutes.
    NoneNo schedule.

Custom cron... Details

Cron ValueDescription
0 * * * *Run once an hour.
0 0 * * *Run once a day at midnight.
0 0 1 * *Run once a month at midnight on the morning of the first day of the month.
""Create a job that has no scheduled run time.
 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat.
  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description
A single value, within the limits displayed above for each field.
A wildcard '*' to indicate no restriction based on the field.'0 0 1 * *'Configures the schedule to run at midnight (00:00) on the first day of each month.
A range '2-5', indicating the range of accepted values for the field.'0 0 1-10 * *'Configures the schedule to run at midnight (00:00) on the first 10 days of each month.
A list of comma-separated values '2,3,4,5', indicating the list of accepted values for the field.0 0 1,11,21 * *'Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
A periodicity indicator '*/5' to express how often based on the field's valid range of values a schedule is allowed to run.'30 */2 1 * *'Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. '0 0 */5 * *' configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
A comma-separated list of any of the above except the '*' wildcard is also supported '2,*/5,8-10'.'0 0 5,*/10,25 * *'Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
  1. (Optional) You can delay the start time of a query by enabling the Delay execution.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination.

Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.

(Optional) You can delay the start time of a query by enabling the Delay execution.

Activate a Segment in Audience Studio

You can also send segment data to the target platform by creating an activation in the Audience Studio.

  1. Navigate to Audience Studio.
  2. Select a parent segment.
  3. Open the target segment, right-mouse click, and then select Create Activation.
  4. In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
  5. Customize the activation output in the Output Mapping panel.

  • Attribute Columns
    • Select Export All Columns to export all columns without making any changes.
    • Select + Add Columns to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select + Add Columnsto add new columns for your activation output.
  • String Builder
    • + Add string to create strings for export. Select from the following values:
      • String: Choose any value; use text to create a custom value.
      • Timestamp: The date and time of the export.
      • Segment Id: The segment ID number.
      • Segment Name: The segment name.
      • Audience Id: The parent segment number.
  1. Set a Schedule.

  • Select the values to define your schedule and optionally include email notifications.
  1. Select Create.

If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.

(オプション)CLIを使用したエクスポート統合

CLIをSFTPへの結果エクスポートに使用することもできます。

secret_key_fileケース

次の例では、キーにバックスラッシュでエスケープされた改行があります。

$ td query --result '{"type":"sftp","host":"xx.xx.xx.xx","port":22,"username":"xxxx","secret_key_file":"{\"content\":\"-----BEGIN RSA PRIVATE KEY-----\nABCDEFJ\nABCDEFJ\n-----END RSA PRIVATE KEY-----\"}","secret_key_passphrase":"xxxxxx", "user_directory_is_root":true,"path_prefix":"/path/to/file.csv","rename_file_after_upload":false,"header_line":true,"quote_policy":"MINIMAL","delimiter":",","null_string":"","newline":"CRLF"}' -d sample_datasets "select * from www_access" -T presto

ユーザーとパスワードのケース

例:

$ td query \
--result '{"type":"sftp","host":"xx.xx.xx.xx","port":22,"auth_method":"Password","username":"xxxx","password":"xxxxx","user_directory_is_root":true,"path_prefix":"/path/to/file.csv","rename_file_after_upload":false,"header_line":true,"quote_policy":"MINIMAL","delimiter":",","null_string":"","newline":"CRLF"}' \
-d sample_datasets "select * from www_access" -T presto

(オプション)ワークフローでエクスポート結果を設定

Treasure Workflow内で、この統合を使用してデータをエクスポートすることを指定できます。サンプルワークフローについては、Treasure Boxesをご覧ください。

参考資料

SFTPデータコネクタのFAQ

Q: SFTPサーバーに接続できません。どうすればよいですか?

A: 確認すべき事項は次のとおりです:

  • プロトコルが有効であることを確認してください。SFTPを使用する場合は、この統合を使用できます。FTP/FTPSを使用する場合は、FTP Server Import Integrationで接続を試みてください。
  • ファイアウォールを使用している場合は、許可されているIP範囲とポートを確認してください。サーバー管理者は、セキュリティ上の理由からデフォルトのポート番号をTCP 22から変更することがあります。
  • プライベートキーがOpenSSH形式であることを確認してください。Treasure Dataは「PuTTY」などの他の形式をサポートしていません。
  • Treasure Dataは、OpenSSH 7.8以降、プライベートキーのデフォルト形式をサポートしていません。'-m PEM'オプションを使用してキーを再生成してください。

Q: SFTPサーバーにアップロードしたファイルが見つかりません。何が起こりましたか?

A: SFTPサーバーがAppendモードをサポートしていない場合、統合は「SFTP Exception: no such file」というエラーでファイルを更新できない可能性があります。安定性の理由から、統合はファイルコンテンツをバッチでアップロードします。したがって、SFTPサーバーでAppendモードを有効にする必要があります。SFTPサーバーでAppendモードを有効にできない場合は、temp_file_thresholdを0に設定してこの機能をバイパスする必要があります。

注意: 暗号化してアップロードする前にファイルを圧縮してください。

  1. 組み込みでない暗号化を使用して復号化すると、ファイルは.gzや.bz2などの圧縮形式に戻ります。

  2. 組み込み暗号化を使用して復号化すると、ファイルは生データに戻ります。