<@U04S8PLJWMT> is there an efficient way to pull h...
# replication-ask-ai
s
@kapa.ai is there an efficient way to pull historical data by passing the dates dynamically?
k
Yes! Airbyte supports dynamic date handling for pulling historical data through its incremental sync feature in the Connector Builder. Here's how it works: Using Incremental Sync with Dynamic Dates You can configure your connector to dynamically inject start and end dates into your API requests using Jinja expressions and built-in variables: •
{{ stream_interval.start_time }}
— represents the start of the current sync time window •
{{ stream_interval.end_time }}
— represents the end of the current sync time window •
{{ now_utc().strftime('%Y-%m-%dT%H:%M:%SZ') }}
— represents the current UTC datetime (useful for setting a dynamic end date) [Incremental sync example] Example Setup (GET request with query parameters) In the incremental sync configuration: • Set "Start datetime" to
{{ config['start_time'] }}
(user-defined input) • Set "End datetime" to
{{ now_utc().strftime('%Y-%m-%dT%H:%M:%SZ') }}
(always syncs up to now) • Set "Inject start time" to
request_parameter
with the appropriate field name (e.g.,
from-date
) • Set "Inject end time" to
request_parameter
with the appropriate field name (e.g.,
to-date
) [Incremental sync example] Example Setup (POST request with body parameters) If you need to inject dates into a POST request body, disable the built-in inject options and use the generic parameter section instead:
Copy code
Field Name: startDate
Value: {{ stream_interval.start_time }}

Field Name: endDate
Value: {{ stream_interval.end_time }}
[Dynamic date filling] How State Works After each sync, Airbyte saves the most recent cursor date as the connection's state. The next scheduled sync automatically picks up from that cutoff date — so you don't need to manually update the start date each time. [Incremental sync example] Limitations • Airbyte does not natively support subtracting a fixed number of days (e.g., "current day minus 1") directly within the Connector Builder configuration. As a workaround, you could use the "Update Source" API endpoint to programmatically pass a new start date before each sync run. [Forum: Dynamic Start Date] 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
s
@kapa.ai what about backfilling the data?
k
Based on the knowledge sources, backfilling historical data in Airbyte is handled through the incremental sync configuration in the Connector Builder. Here's how it works: Backfilling Historical Data When you first set up an incremental sync, you define a Start datetime — this is effectively your backfill starting point. The connector will fetch all data from that date up to the current time. How to Configure a Backfill 1. Set the "Start datetime" to the earliest date you want to backfill from (e.g.,
{{ config['start_time'] }}
as a user input, so the user can specify how far back to go). [Incremental sync] 2. Set the "End datetime" to
now
(or
{{ now_utc().strftime('%Y-%m-%dT%H:%M:%SZ') }}
) to sync all data up to the current date. [Incremental sync example] 3. Enable "Split up interval" (under Advanced settings) and set a Step (e.g.,
P1D
for daily chunks). This partitions the backfill into smaller requests, which is important for APIs with rate limits or date-range restrictions. [Adding incremental reads] How State Prevents Re-fetching Once the backfill completes, Airbyte saves the most recent cursor value as the connection's state. Subsequent syncs will automatically start from that cutoff point — so the backfill only happens once, and future syncs only pull new/changed data. [Incremental sync example] Testing Note During testing in the Connector Builder, at most 5 partitions are requested to speed things up. During a real sync, the full time range between your configured start date and the current day will be executed. [Adding incremental reads] 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
s
@kapa.ai can we trigger this using airflow?
k
Yes, you can trigger Airbyte syncs using Apache Airflow! Airbyte is an official community provider for the Apache Airflow project. Setup 1. Install the provider package in your Airflow environment:pip install 'apache-airflow-providers-airbyte>=5.0.0' 2. Set the Airbyte connection's sync schedule to Manual so Airflow controls when syncs run. [Airflow Airbyte Provider] 3. Create an Airflow connection to Airbyte via Admin > Connections in the Airflow UI, using your Client ID and Client Secret from Airbyte's Settings > Applications. [Airflow Airbyte Provider] Example DAGs Synchronous (waits for completion)
Copy code
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.providers.airbyte.operators.airbyte import AirbyteTriggerSyncOperator

with DAG(
    dag_id="trigger_airbyte_sync",
    default_args={"owner": "airflow"},
    schedule_interval="@daily",
    start_date=days_ago(1),
) as dag:

    sync_connection = AirbyteTriggerSyncOperator(
        task_id="sync_airbyte_connection",
        connection_id="your-airbyte-connection-uuid",
        timeout=3600,
        wait_seconds=3,
    )
Asynchronous (uses a sensor, lighter on resources)
Copy code
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.providers.airbyte.operators.airbyte import AirbyteTriggerSyncOperator
from airflow.providers.airbyte.sensors.airbyte import AirbyteJobSensor

with DAG(
    dag_id="trigger_airbyte_sync_async",
    default_args={"owner": "airflow"},
    schedule_interval="@daily",
    start_date=days_ago(1),
) as dag:

    trigger_sync = AirbyteTriggerSyncOperator(
        task_id="trigger_airbyte_sync",
        connection_id="your-airbyte-connection-uuid",
        asynchronous=True,
    )

    wait_for_sync = AirbyteJobSensor(
        task_id="wait_for_airbyte_sync",
        airbyte_job_id=trigger_sync.output,
    )

    trigger_sync >> wait_for_sync
[DAG examples] The asynchronous approach is recommended if your Airflow instance has limited resources, as sensors don't occupy a worker slot. [DAG examples] > Note: The
connection_id
is the Airbyte Connection UUID, which you can find in the URL when viewing a connection in the Airbyte UI. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
s
@kapa.ai can we backfill using airflow
k
Based on the knowledge sources available, there is no explicit documentation about passing dynamic date parameters (like a backfill start date) directly from an Airflow DAG to an Airbyte sync at trigger time. What the Airflow integration does is trigger the Airbyte connection as configured — meaning the backfill behavior is determined by the Airbyte connection's own incremental sync settings (start date, cursor field, etc.), not by parameters passed from Airflow. Here's how you'd approach backfilling via Airflow in practice: 1. Configure the backfill in Airbyte first — Set your connection's "Start datetime" to the historical date you want to backfill from, as described in the incremental sync setup. 2. Set the sync schedule to Manual in Airbyte, so Airflow controls when the sync runs. [Airflow Airbyte Provider] 3. Trigger the sync from Airflow using `AirbyteTriggerSyncOperator`:
Copy code
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.providers.airbyte.operators.airbyte import AirbyteTriggerSyncOperator

with DAG(
    dag_id="trigger_airbyte_backfill",
    default_args={"owner": "airflow"},
    schedule_interval="@daily",
    start_date=days_ago(1),
) as dag:

    backfill_sync = AirbyteTriggerSyncOperator(
        task_id="airbyte_backfill",
        connection_id="your-airbyte-connection-uuid",
        timeout=3600,
        wait_seconds=3,
    )
[DAG examples] Airflow will trigger the Airbyte job, and Airbyte will handle the backfill based on its configured start date and state. Once the backfill completes, subsequent syncs will automatically pick up from the last cursor value saved in Airbyte's state. > Note: The knowledge sources do not describe a way to dynamically pass a custom start date from Airflow to Airbyte at trigger time. If you need that level of control, you would need to update the Airbyte connection's configuration (e.g., via the Airbyte API) before triggering the sync. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.