# Running Sling

The `sling run` command is the primary mechanism for executing data movement operations in Sling CLI. It provides a flexible interface for transferring data between various sources and targets, with support for different replication modes and configuration options.

There are 2 primary ways to configure and run sling, using:

* [**CLI Flags**](#cli-flags-overview): quick ad-hoc runs from your terminal shell or script.
* [**Replication**](/concepts/replication.md): streams defined in a YAML or JSON file.

***

Furthermore, you'll find plenty of examples on how to use Sling:

* [Database to Database](https://github.com/slingdata-io/sling-docs/blob/master/sling-cli/run/examples/database-to-database.md)
* [Database to File](https://github.com/slingdata-io/sling-docs/blob/master/sling-cli/run/examples/database-to-file.md)
* [File to Database](https://github.com/slingdata-io/sling-docs/blob/master/sling-cli/run/examples/file-to-database.md)

## CLI Flags Overview

For quickly running ad-hoc operations from the terminal, using CLI flags is often best. Here are some examples using:

{% code overflow="wrap" %}

```bash
# Load all tables in a schema in with 3 threads
$ export SLING_THREADS=3
$ sling run \
    --src-conn MY_SOURCE_DB \
    --src-stream 'source_schema.*' \
    --tgt-conn MY_TARGET_DB \
    --tgt-object 'target_schema.{stream_table}'
    --mode full-refresh
    
# Pipe in your json file and flatten the nested keys into their own columns
$ cat /tmp/my_file.json | sling run --src-options '{"flatten": "true"}' --tgt-conn MY_TARGET_DB --tgt-object 'target_schema.target_table' --mode full-refresh

# Read folder containing many CSV files
$ sling run \
    --src-stream 'file:///tmp/my_csv_folder/' \
    --tgt-conn MY_TARGET_DB --tgt-object 'target_schema.target_table' \
    --mode full-refresh

# Load only latest data from one source DB to another.
$ sling run \
    --src-conn MY_SOURCE_DB \
    --src-stream 'source_schema.source_table' \
    --tgt-conn MY_TARGET_DB \
    --tgt-object 'target_schema.target_table' \
    --mode incremental \
    --primary-key 'id' --update-key 'last_modified_dt' 

# Export / Backup database tables to JSON files
$ sling run \
    --src-conn MY_SOURCE_DB \
    --src-stream 'source_schema.source_table' \
    --tgt-conn MY_S3_BUCKET \
    --tgt-object 's3://my-bucket/my_json_folder/' \
    --tgt-options '{"file_max_rows": 100000, "format": "jsonlines"}'
```

{% endcode %}

## Interface Specifications

<table data-full-width="false"><thead><tr><th width="215.4264102691841">CLI Flag</th><th>Description</th></tr></thead><tbody><tr><td><code>--src-conn</code></td><td>The source database connection (name, conn string or URL).</td></tr><tr><td><code>--tgt-conn</code></td><td>The target database connection (name, conn string or URL).</td></tr><tr><td><code>--src-stream</code></td><td>The source table (schema.table), local / cloud file path. Can also be the path of sql file or in-line text to use as query. Use <code>file://</code> for local paths.</td></tr><tr><td><code>--tgt-object</code></td><td>The target table (schema.table) or local / cloud file path. Use <code>file://</code> for local paths. See <a href="/pages/y2M4d0G7ur8y4f4KiQ0i">here</a> for details on runtime variables.</td></tr><tr><td><code>--mode</code></td><td>The target load <a href="/pages/YmhsNnZAWVIOnjeuszZx">mode</a> to use: <code>incremental</code>, <code>truncate</code>, <code>full-refresh</code>, <code>backfill</code> or <code>snapshot</code>. Default is <code>full-refresh</code>.</td></tr><tr><td><code>--primary-key</code></td><td>The column(s) to use as primary key (for <code>incremental</code> mode). If composite key, use a comma-delimited string.</td></tr><tr><td><code>--update-key</code></td><td>The column to use as update key (for <code>incremental</code> mode).</td></tr><tr><td><code>--src-options</code></td><td>In-line options to further configure source (JSON or YAML). See <a href="/pages/3BkvtN9AW4GCDlyu6jGw">here</a> for details.</td></tr><tr><td><code>--tgt-options</code></td><td>In-line options to further configure target (JSON or YAML). See <a href="/pages/dhKMJTL71CTD8kxiAgi4">here</a> for details.</td></tr><tr><td><code>--stdout</code></td><td>Output the stream to standard output (STDOUT).</td></tr><tr><td><code>--select</code></td><td>Select or exclude specific columns from the source stream. (comma separated). Use <code>-</code> prefix to exclude.</td></tr><tr><td><code>--transforms</code></td><td>An object/map, or array/list of built-in transforms to apply to records (JSON or YAML).</td></tr><tr><td><code>--columns</code></td><td>An object/map to specify the type that a column should be cast as (JSON or YAML).</td></tr><tr><td><code>--streams</code></td><td>Only run specific streams from a replication (comma separated). See <a href="/pages/pQWU3jzZUoz5vHLm4CZw">here</a> for details.</td></tr></tbody></table>

## Features

* **Flexible Data Sources**: Supports databases, files, cloud storage, and standard input
* **Multiple Load Modes**: Includes full refresh, incremental, snapshot, and truncate modes
* **Data Transformations**: Allows column selection, type casting, and custom transformations
* **Progress Tracking**: Monitors row counts, bytes transferred, and constraint violations
* **Error Handling**: Provides detailed error reporting and validation

The `sling run` command is designed to be both powerful and flexible, accommodating various data movement scenarios while maintaining ease of use through consistent parameter patterns and comprehensive documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/sling-cli/run.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
