# Exporting data from a rules-based database

You can export the most recently generated rule-based database data to files or to a database.

Note that views are exported as tables. They do not create or replace the views in the target database.

## Starting the export <a href="#export-start" id="export-start"></a>

To start an export, in the database header, click **Export Data**.

Fabricate displays the **Export Data** panel.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2F6FKmE5NUUxVjVUlCOXvT%2FRulesBased_ExportData.png?alt=media&#x26;token=cbb9b53f-048f-40a1-b692-92cfac10c9be" alt=""><figcaption><p>Export Data panel to configure the export of a rules-based database</p></figcaption></figure>

## Selecting the output format <a href="#export-format" id="export-format"></a>

On the **Export Data** panel, from the **Format** dropdown list, select the format for the exported data:

* **SQL -** Exports the data to a .zip file called **\<database name>.zip**. The file contains a SQL file to load the exported data, and a readme file that summarizes the export.
* **CSV -** Exports the data to a .zip file called **\<database name>.zip**. The file contains a .csv file for each table and view, and a readme file that summarizes the export.
* **JSONL -** Exports the data to a .zip file called **\<database name>.zip**. The file contains a .jsonl file for each table and view, and a readme file that summarizes the export.
* **Parquet -** Exports the data to a .zip file called **\<database name>.zip**. The file contains a .parquet file for each table and view, and a readme file that summarizes the export.
* **XML -** Exports the data to a .zip file called **\<database name>.zip**. The file contains an XML file for each table and view.
* **Push to Database -** Available for databases that are created with a specific database type, such as PostgreSQL. Uses the data to populate a database that you specify.

When you export PostgreSQL or SQL Server databases to SQL or to a database, if you [provided a schema name](https://docs.tonic.ai/fabricate/database-create-manage#database-schema-name), then Fabricate assigns all of the tables to that schema.

## Adding and selecting an export target <a href="#export-configure-target-database" id="export-configure-target-database"></a>

When you select **Push to Database**, you are prompted for an export target. An export target includes:

* A server connection where the database is located.
* The database. The database must already exist.

Your external database must allow connections from the following Fabricate IP addresses:

* US instance (<https://fabricate.tonic.ai/>)
  * 184.72.239.148
  * 3.231.122.192
* EU instance (<http://eu.fabricate.tonic.ai/>)
  * 3.67.149.135
  * 3.69.97.191

### Selecting an existing target

If you previously created an export target, then from the **Target Database** dropdown list, select the export target to use.

### Defining a new export target

To define an export target:

1. From the **Target Database** dropdown list, select **create new target**.
2. On the **New Target Database Connection** panel, in the **Connection Name** field, provide a name to use to identify the export target.
3. From the **Server Connection** dropdown list, select the server connection where the export target is located.\
   \
   You can if needed add a new server connection or edit the selected server connection.\
   \
   New server connections are added to the [available server connections for the workspace](https://docs.tonic.ai/fabricate/workspaces/workspace-server-connections).\
   \
   Note that any edits to the selected server connection apply to all of the locations where the server connection is used.
4. Specify the database to connect to.\
   \
   For platforms other than Databricks, in the **Database Name** field, provide the name of the database to export to.\
   \
   For Databricks:
   1. In the **Catalog** field, provide the data catalog for the data.
   2. In the **Schema** field, provide the schema for the data.
5. To test the connection, click **Test Connection**.
6. To save the target database, click **Create Connection**.

The export target is then available to use whenever you export the database.

### Note on exports to Databricks&#x20;

When Fabricate exports data to Databricks, it:

1. Creates a volume called `/Volumes///fabricate`.
2. Creates a directory in that volume that is named with a UUID.
3. Uploads a CSV file for each table into that directory.
4. Copies the data from each CSV file into the destination tables in the schema.

The catalog, schema, and tables must already exist. Fabricate creates the volume automatically.

## Including the DDL in the export <a href="#export-include-ddl" id="export-include-ddl"></a>

When you export to SQL or push to a database, you can include the DDL in the export.

To include the DDL, check the **Include DDL** checkbox.

Remember that Fabricate does not update the DDL to reflect manual changes to the database schema. Make sure that either the DDL matches the current schema, or that you handle the migration in the destination database.

## Selecting the scope of the data to export <a href="#export-select-scope" id="export-select-scope"></a>

If you are currently viewing a specific table or a view, then on the **Export Database** panel:

* To export the entire database, click **All Tables**.
* To only export the current table or view, click **Only \<table or view name>.**

## Completing the export and downloading exported files

After you configure the export, to complete the export, click **Export Database**.

When you export to files, after Fabricate generates the file, it prompts you to download the file.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2FKl3of1LNAqRkCW2W6Rgo%2FDatabase_ExportDownloadPrompt.png?alt=media&#x26;token=de7d51fc-a83e-4c49-a5a6-3c94e539aa6d" alt=""><figcaption><p>Download prompt for export to a file</p></figcaption></figure>

If you do not download the file immediately, it is also available on the downloads list.

To display the list of available downloads, in the Fabricate header, click the download icon.

<figure><img src="https://4109733485-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmoU4gTR9LxlzHeWmQCUZ%2Fuploads%2F6IUWbI7jfIs5mWJxKswY%2FDownloadIcon.png?alt=media&#x26;token=d6411ded-bffc-425d-901d-a32656566a35" alt=""><figcaption><p>Download icon to display the list of available files to download</p></figcaption></figure>
