# Adobe Analytics Import Integration Using CLI You can also use the FTP data connector from the command line interface. The following instructions show you how to import data using the CLI. ## Install 'td' command v0.11.9 or later Install the most current [Treasure Data Toolbelt](https://toolbelt.treasuredata.com/). ```bash $ td --version 0.11.10 ``` ## Create Seed Config File (seed.yml) Prepare seed.yml as shown in the following example, with your Adobe Analytics' SFTP details. We support two authentication methods: Public / Private Key Pair, and Password. ### Case 1: Public / Private Key Pair Authentication Create seed.yml with the following content. ```yaml in: type: adobe_analytics host: HOST port: user: USER secret_key_file: content: | -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: AES-128-CBC... ... -----END RSA PRIVATE KEY----- secret_key_passphrase: PASSPHRASE user_directory_is_root: true timeout: 600 path_prefix: /path/to/sample out: mode: append exec: {} ``` `secret_key_file` requires OpenSSH format. ### Case 2: Password Authentication Create seed.yml with the following content. ```yaml in: type: adobe_analytics host: HOST port: auth_method: password user: USER password: PASSWORD user_directory_is_root: true timeout: 600 path_prefix: /path/to/sample out: mode: append exec: {} ``` You can use the following special characters in the password: "#$!*@" If you are using the proxy, add the additional information as shown: ```yaml in: type: adobe_analytics host: HOST port: .... proxy: type: http host: PROXY_HOST port: PROXY_PORT user: PROXY_USER password: PROXY_PASSWORD command: SOMETHING COMMAND IF NEEDED ``` The Data Connector forAdobe Analytics imports all files that match the specified prefix (e.g. path_prefix: `path/to/sample_` –> `path/to/sample_201501.csv.gz`, `path/to/sample_201502.csv.gz`, …, `path/to/sample_201505.csv.gz`). For more details on available out modes, see [Appendix](/int/adobe-analytics-import-integration-using-cli#h1__1835053169). ## Guess Fields (Generate load.yml) Use connector:guess. This command automatically reads the source file, and assesses (uses logic to guess) the file format. ```bash $ td connector:guess seed.yml -o load.yml ``` If you open load.yml, you'll see the guessed file format definitions including file formats, encodings, column names, and types. This example is trying to load csv files. ```yaml in: type: adobe_analytics host: HOST port: user: USER secret_key_file: content: | -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: AES-128-CBC... ... -----END RSA PRIVATE KEY----- secret_key_passphrase: PASSPHRASE user_directory_is_root: true timeout: 600 path_prefix: /path/to/sample parser: skip_header_lines: 1 charset: UTF-8 newline: CRLF type: csv delimiter: ',' quote: '"' columns: - {name: id, type: long} - {name: account, type: long} - {name: time, type: timestamp, format: "%Y-%m-%d %H:%M:%S"} - {name: purchase, type: timestamp, format: "%Y%m%d"} - {name: comment, type: string} - {name: json_column, type: json} out: mode: append exec: {} ``` Then, you can preview how the system will parse the file by using the preview command. ``` $ td connector:preview load.yml +-------+---------+----------+---------------------+ | id | company | customer | created_at | +-------+---------+----------+---------------------+ | 11200 | AA Inc. | David | 2015-03-31 06:12:37 | | 20313 | BB Imc. | Tom | 2015-04-01 01:00:07 | | 32132 | CC Inc. | Fernando | 2015-04-01 10:33:41 | | 40133 | DD Inc. | Cesar | 2015-04-02 05:12:32 | | 93133 | EE Inc. | Jake | 2015-04-02 14:11:13 | +-------+---------+----------+---------------------+ ``` The guess command needs over 3 rows and 2 columns in source data file, because it guesses column definition using sample rows from source data. If the system detects your column name or column type unexpectedly, modify load.yml directly and preview again. Currently, the Data Connector supports parsing of “boolean”, “long”, “double”, “string”, and “timestamp” types. You also must create a local database and table prior to executing the data load job. Follow these steps: ```bash td database:create td_sample_db td table:create td_sample_db td_sample_table ``` ## Execute Load Job Submit the load job. It may take a couple of hours depending on the size of the data. Specify the Treasure Data database and table where the data should be stored. It's also recommended to specify --time-column option, because Treasure Data's storage is partitioned by time (see [data partitioning](https://docs.treasuredata.com/smart/project-product-documentation/data-partitioning-in-treasure-data)) If the option is not provided, the data connector chooses the first long or timestamp column as the partitioning time. The type of the column specified by --time-column must be either of long and timestamp type. If your data doesn't have a time column you can add a time column by using add_time filter option. For more details see [add_time filter plugin](https://docs.treasuredata.com/smart/project-product-documentation/add_time-filter-function). ```bash td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column created_at ``` The connector:issue command assumes that you have already created a *database(td_sample_db)* and a *table(td_sample_table)*. If the database or the table do not exist in TD, the connector:issue command fails, so create the database and table [manually](https://docs.treasuredata.com/smart/project-product-documentation/data-management) or use --auto-create-table option with td connector:issue command to auto create the database and table: ```bash td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column created_at --auto-create-table ``` The Data Connector does not sort records on server-side. To use time-based partitioning effectively, sort records in files beforehand. If you have a field called `time`, you don't have to specify the `--time-column` option. ``` $ td connector:issue load.yml --database td_sample_db --table td_sample_table ``` ## Scheduled execution You can schedule periodic Data Connector execution for incremental Adobe Analytics' SFTP file import. We configure our scheduler carefully to ensure high availability. By using this feature, you no longer need a cron daemon on your local data center. For the scheduled import, the Data Connector for Adobe Analytics imports all files that match with the specified prefix (e.g. path_prefix: `path/to/sample_` –> `path/to/sample_201501.csv.gz`, `path/to/sample_201502.csv.gz`, …, `path/to/sample_201505.csv.gz`) at first and remembers the last path (`path/to/sample_201505.csv.gz`) for the next execution. On the second and on subsequent runs, it imports only files that comes after the last path in alphabetical (lexicographic) order. (`path/to/sample_201506.csv.gz`, …) ### Create the schedule A new schedule can be created using the td connector:create command. The following are required: the name of the schedule, the cron-style schedule, the database and table where the data will be stored, and the Data Connector configuration file. ```bash td connector:create \ daily_import \ "10 0 * * *" \ td_sample_db \ td_sample_table \ load.yml ``` It's also recommended to specify the --time-column option, because Treasure Data's storage is partitioned by time (see [data partitioning](https://docs.treasuredata.com/smart/project-product-documentation/data-partitioning-in-treasure-data)) ```bash $ td connector:create \ daily_import \ "10 0 * * *" \ td_sample_db \ td_sample_table \ load.yml \ --time-column created_at ``` The `cron` parameter also accepts three special options: `@hourly`, `@daily` and `@monthly`. By default, schedule is setup in UTC timezone. You can set the schedule in a timezone using `-t` or `--timezone` option. The `--timezone` option supports only extended timezone formats like 'Asia/Tokyo', 'America/Los_Angeles' etc. Timezone abbreviations like PST, CST are not supported and may lead to unexpected schedules. ### List the Schedules You can see the list of currently scheduled entries by running the command td connector:list. ```bash td connector:list ``` ### Show the Setting and Schedule History td connector:show shows the execution setting of a schedule entry. ```bash td connector:show daily_import ``` td connector:history shows the execution history of a schedule entry. To investigate the results of each individual run, use td job jobid. ```bash td connector:history daily_import ``` ### Delete the Schedule td connector:delete will remove the schedule. ```bash td connector:delete daily_import ``` ## Appendix ### Modes for out plugin You can specify file import mode in out section of seed.yml. #### append (default) This is the default mode and records are appended to the target table. ```yaml in: ... out: mode: append ``` #### replace (In td 0.11.10 and later) This mode replaces data in the target table. Note that any manual schema changes made to the target table will remain intact with this mode. ```yaml in: ... out: mode: replace ```