# Exporting & Importing DB

Source: https://docs.openwebui.com/tutorials/maintenance/database

If you need to migrate your **Open WebUI** data (e.g., chat histories, configurations, etc.) from one server to another or back it up for later use, you can export and import the database. This guide assumes you're running Open WebUI using the internal SQLite database (not PostgreSQL). Copying `webui.db` moves everything stored in the database (accounts, chats, settings, file and knowledge records) but not the files themselves: uploaded files under `/app/backend/data/uploads` and the vector store under `/app/backend/data/vector_db` stay behind, so chats that reference files will point at missing objects. Copy the whole `/app/backend/data` directory (see the [backups guide](/tutorials/maintenance/backups)) and keep the same `WEBUI_SECRET_KEY` for a complete move; the Docker image writes its auto-generated key to `/app/backend/.webui_secret_key`, outside that directory. With an external vector database such as PGVector, the vectors live there instead of in `vector_db`.

Follow the steps below to export and import the `webui.db` file, which contains your database.

---

### Exporting Database

> **note**
>
> Copy the database file yourself as described below. The **Database** download in **Settings > Database** (admin section) leaves out `webui.db-wal`, so it can miss recent data.

To export the database from your current Open WebUI instance:

1. **Stop Open WebUI before copying the database**: Open WebUI runs SQLite in write-ahead logging (WAL) mode by default, so recent committed changes are kept in `webui.db-wal` next to `webui.db`. Stop the container first so nothing writes to the database during the export:

```
docker stop open-webui
```
2. **Write the pending changes into `webui.db`**: Stopping the container leaves those changes in `webui.db-wal`, so a copy of `webui.db` alone can be missing them. Run a checkpoint from the same image while the container is stopped:

```
docker run --rm --volumes-from open-webui --entrypoint python3 "$(docker inspect -f '{{.Config.Image}}' open-webui)" -c "import sqlite3; db = sqlite3.connect('/app/backend/data/webui.db'); db.execute('PRAGMA wal_checkpoint(TRUNCATE)'); db.close()"
```
3. **Use `docker cp` to copy the database file**: The `webui.db` file is located in the container inside the directory `/app/backend/data`. Run the following command to copy it into your local machine:

```
docker cp open-webui:/app/backend/data/webui.db ./webui.db
```
4. **Start Open WebUI again on the source server**:

```
docker start open-webui
```
5. **Transfer the exported file to the new server**: You can use **FileZilla** or any other file transfer tool of your choice to move the `webui.db` file to the new server.

> **info**
>
> FileZilla is recommended for its ease of use when transferring files to the new server.

---

### Importing Database

After moving the `webui.db` file to the new server, follow these steps:

1. **Install and Run Open WebUI on the New Server**: Set up and run Open WebUI using a Docker container. Follow the instructions provided in the [Getting Started](/getting-started) to install and start the Open WebUI container. Once it's running, stop it before performing the import step.

```
docker stop open-webui
```
2. **Remove destination SQLite sidecar files**: If the destination container has already created `webui.db-wal` or `webui.db-shm`, remove those files before replacing `webui.db`. They belong to the old destination database state and must not be mixed with the imported database.

```
docker run --rm --volumes-from open-webui --entrypoint rm "$(docker inspect -f '{{.Config.Image}}' open-webui)" -f /app/backend/data/webui.db-wal /app/backend/data/webui.db-shm
```
3. **Use `docker cp` to copy the database file to the container**: Assuming the exported `webui.db` file is in your current working directory, copy it into the container:

```
docker cp ./webui.db open-webui:/app/backend/data/webui.db
```
4. **Start the Open WebUI container**: Start the container again to use the imported database.

```
docker start open-webui
```

The new server should now be running Open WebUI with your imported database.

---

### Notes

- This export/import process **only works if you're using the internal SQLite database (`webui.db`)**.
- If you're using an external PostgreSQL database, this method is not applicable because the database is managed outside the container. For PostgreSQL, you'd need to follow PostgreSQL-specific tools and procedures to back up and restore your database.
- Do not mix `webui.db-wal` or `webui.db-shm` files from a different database copy. When replacing `webui.db` on the destination, remove any existing destination sidecar files before starting Open WebUI.

---

### Why It's Important

This approach is particularly useful when:

- Migrating your Open WebUI data to a new server or machine.
- Creating backups of your data before an update or modification.
- Testing Open WebUI on multiple servers with the same setup.

```

# Quick commands summary for export and import

# Export:
docker stop open-webui
docker run --rm --volumes-from open-webui --entrypoint python3 "$(docker inspect -f '{{.Config.Image}}' open-webui)" -c "import sqlite3; db = sqlite3.connect('/app/backend/data/webui.db'); db.execute('PRAGMA wal_checkpoint(TRUNCATE)'); db.close()"
docker cp open-webui:/app/backend/data/webui.db ./webui.db
docker start open-webui

# Stop container on the new server:
docker stop open-webui

# Import:
docker run --rm --volumes-from open-webui --entrypoint rm "$(docker inspect -f '{{.Config.Image}}' open-webui)" -f /app/backend/data/webui.db-wal /app/backend/data/webui.db-shm
docker cp ./webui.db open-webui:/app/backend/data/webui.db

# Start container:
docker start open-webui
```

With these steps, you can easily manage your Open WebUI migration or backup process. Keep in mind the database format you're using to ensure compatibility.

---

## Related Guides

- [SQLite Database Overview](/reference/database-schema) - Detailed database schema
- [Backups](/tutorials/maintenance/backups) - Comprehensive backup strategies for your instance
