About dbt clone command
The dbt clone
command clones selected nodes from the specified state to the target schema(s). This command makes use of the clone
materialization:
- If your data platform supports zero-copy cloning of tables (Snowflake, Databricks, or BigQuery), and this model exists as a table in the source environment, dbt will create it in your target environment as a clone.
- Otherwise, dbt will create a simple pointer view (
select * from
the source object) - By default,
dbt clone
will not recreate pre-existing relations in the current target. To override this, use the--full-refresh
flag. - You may want to specify a higher number of threads to decrease execution time since individual clone statements are independent of one another.
The clone
command is useful for:
- blue/green continuous deployment (on data warehouses that support zero-copy cloning tables)
- cloning current production state into development schema(s)
- handling incremental models in dbt Cloud CI jobs (on data warehouses that support zero-copy cloning tables)
- testing code changes on downstream dependencies in your BI tool
# clone all of my models from specified state to my target schema(s)
dbt clone --state path/to/artifacts
# clone one_specific_model of my models from specified state to my target schema(s)
dbt clone --select "one_specific_model" --state path/to/artifacts
# clone all of my models from specified state to my target schema(s) and recreate all pre-existing relations in the current target
dbt clone --state path/to/artifacts --full-refresh
# clone all of my models from specified state to my target schema(s), running up to 50 clone statements in parallel
dbt clone --state path/to/artifacts --threads 50
When to use dbt clone
instead of deferral?
Unlike deferral, dbt clone
requires some compute and creation of additional objects in your data warehouse. In many cases, deferral is a cheaper and simpler alternative to dbt clone
. However, dbt clone
covers additional use cases where deferral may not be possible.
For example, by creating actual data warehouse objects, dbt clone
allows you to test out your code changes on downstream dependencies outside of dbt (such as a BI tool).
As another example, you could clone
your modified incremental models as the first step of your dbt Cloud CI job to prevent costly full-refresh
builds for warehouses that support zero-copy cloning.
Cloning in dbt Cloud
You can clone nodes between states in dbt Cloud using the dbt clone
command. This is available in the dbt Cloud IDE and the dbt Cloud CLI and relies on the --defer
feature. For more details on defer in dbt Cloud, read Using defer in dbt Cloud.
-
Using dbt Cloud CLI — The
dbt clone
command in the dbt Cloud CLI automatically includes the--defer
flag. This means you can use thedbt clone
command without any additional setup. -
Using dbt Cloud IDE — To use the
dbt clone
command in the dbt Cloud IDE, follow these steps before running thedbt clone
command:-
Set up your Production environment and have a successful job run.
-
Enable Defer to production by toggling the switch in the lower-right corner of the command bar.
-
Run the
dbt clone
command from the command bar.
-
Check out this Developer blog post for more details on best practices when to use dbt clone
vs. deferral.