dbt clone command clones selected nodes from the specified state to the target schema(s). This command makes use of the
- If your data platform supports zero-copy cloning of tables, 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 * fromthe source object)
- By default,
dbt clonewill not recreate pre-existing relations in the current target. To override this, use the
- You may want to specify a higher number of threads to decrease execution time since individual clone statements are independent of one another.
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
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 clonecommand in the dbt Cloud CLI automatically includes the
--deferflag. This means you can use the
dbt clonecommand without any additional setup.
Using dbt Cloud IDE — To use the
dbt clonecommand in the dbt Cloud IDE, follow these steps before running the
- 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.Select the 'Defer to production' toggle on the bottom right of the command bar to enable defer in the dbt Cloud IDE.
- Run the
dbt clonecommand from the command bar.
Check out this Developer blog post for more details on best practices when to use
dbt clone vs. deferral.