> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Rollback

<Card title="Tutorial: Manage Database Change with 1-Click Data Rollback" icon="graduation-cap" href="/tutorials/data-rollback" horizontal />

Bytebase provides **Prior Backup** functionality that captures a snapshot of data before changes are applied. This safety mechanism stores the original state of affected rows, enabling you to revert data changes with **1-Click** when necessary. You can perform **multi-task rollbacks** to efficiently revert multiple related changes across databases in one operation.

<Info>
  Backup data is stored within your own database instance in a dedicated `bbdataarchive` location. Bytebase does not automatically purge this backup data, so you can manually clean up the `bbdataarchive` database or schema as needed.
</Info>

## Supported Databases

| Database   | Prerequisites                                                                         | Prior Backup | 1-click Rollback |
| ---------- | ------------------------------------------------------------------------------------- | ------------ | ---------------- |
| MySQL      | Create a `bbdataarchive` **database** on the instance where your database is located. | ✅            | ✅                |
| MariaDB    | Create a `bbdataarchive` **database** on the instance where your database is located. | ✅            | ✅                |
| TiDB       | Create a `bbdataarchive` **database** on the instance where your database is located. | ✅            | ✅                |
| PostgreSQL | Create a `bbdataarchive` **schema** on the database.                                  | ✅            | ✅                |
| Oracle     | Create a `bbdataarchive` **schema** on the database.                                  | ✅            | ✅                |
| SQL Server | Create a `bbdataarchive` **database** on the instance where your database is located. | ✅            | ✅                |

## Supported Operations

Prior backup is feasible when meeting **all** of the following conditions:

* `UPDATE` or `DELETE`
* No mixed `UPDATE`/`DELETE` on the same table.
* The SQL statement size is less than 2M.
* No mixed DDL/DML.

1-click rollback is feasible when meeting **all** of the following conditions:

* For `UPDATE`, the changed table has primary key and primary key columns are not updated.

## Enable Prior Backup

You can enable the **Prior Backup** option either before or after creating a database change issue.

<img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-issue-backup-on.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=58b8b0cab352bbb6f84727e95c9b8ead" alt="bb-issue-backup-on" width="2536" height="1200" data-path="content/docs/change-database/rollback-data-changes/bb-issue-backup-on.webp" />

<Note>
  If the Prior Backup switch appears disabled, navigate to the database page and click **Sync
  instance** to refresh the database metadata.
</Note>

## Perform 1-Click and Multi-Task Rollback

1. After your database change has been successfully deployed, click the **Rollback available** link to initiate the rollback process.

   <img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-issue-done-1.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=9b369cbc3260fe452919b0a1efaf771f" alt="bb-issue-done-1" width="2536" height="1212" data-path="content/docs/change-database/rollback-data-changes/bb-issue-done-1.webp" />

2. You may see multiple rollbackable changes available, depending on your deployment scenario.

   <Note>
     This could include a single change applied to multiple databases, multiple changes to one
     database, or a combination of both scenarios.
   </Note>

   <img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-issue-done-2.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=a7522a99dde9d2975725b5b949269ba4" alt="bb-issue-done-2" width="2542" height="1206" data-path="content/docs/change-database/rollback-data-changes/bb-issue-done-2.webp" />

3. Select which changes you want to rollback - you can choose individual changes or rollback all of them at once. This **multi-task rollback** capability allows you to efficiently revert multiple related changes in a single operation.

   <img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-rollback-select.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=0e751c65c38fef8b5190c7186e3cfd8c" alt="bb-rollback-select" width="2540" height="1214" data-path="content/docs/change-database/rollback-data-changes/bb-rollback-select.webp" />

4. Bytebase automatically generates the appropriate rollback SQL statements based on the backup data.

   <img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-rollback-issue-1.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=a026236010177585e1fd4ffd73b25d3c" alt="bb-rollback-issue-1" width="2542" height="1212" data-path="content/docs/change-database/rollback-data-changes/bb-rollback-issue-1.webp" />

   <img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-rollback-issue-2.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=562b649cc73c33083eeae39e7ea5f090" alt="bb-rollback-issue-2" width="2534" height="1218" data-path="content/docs/change-database/rollback-data-changes/bb-rollback-issue-2.webp" />

## Inspect Backup Data

You can examine the stored backup data using Bytebase's SQL Editor to verify what information has been preserved.

<img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-sql-editor-test.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=dbb7f33a21dd7b579cb1a461d2597877" alt="bb-sql-editor-test" width="2546" height="1226" data-path="content/docs/change-database/rollback-data-changes/bb-sql-editor-test.webp" />

<img src="https://mintcdn.com/dbx/afRbc5nzzK45dH85/content/docs/change-database/rollback-data-changes/bb-sql-editor-prod.webp?fit=max&auto=format&n=afRbc5nzzK45dH85&q=85&s=68bd49bf249a863825d66e02559d9f94" alt="bb-sql-editor-prod" width="2548" height="1228" data-path="content/docs/change-database/rollback-data-changes/bb-sql-editor-prod.webp" />

## Appendix: Setting Up `bbdataarchive`

Before using Prior Backup functionality, you must create the `bbdataarchive` storage location in your database instance. Follow the instructions for your specific database engine:

### MySQL, MariaDB, and TiDB

These MySQL-compatible engines share the same setup.

1. **Create the backup database:**

   ```sql theme={null}
   CREATE DATABASE bbdataarchive;
   ```

2. **Grant necessary privileges:**

   Replace `your_user` with the actual username that Bytebase uses to connect to your database.

   ```sql theme={null}
   GRANT ALL PRIVILEGES ON bbdataarchive.* TO 'your_user'@'%';
   FLUSH PRIVILEGES;
   ```

### PostgreSQL

1. **Create the backup schema:**

   ```sql theme={null}
   CREATE SCHEMA bbdataarchive;
   ```

2. **Grant necessary privileges:**

   Replace `your_user` with the actual username that Bytebase uses to connect to your database.

   ```sql theme={null}
   GRANT ALL PRIVILEGES ON SCHEMA bbdataarchive TO your_user;
   GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA bbdataarchive TO your_user;
   ```

3. **If using `SET ROLE`, grant permissions to that role:**

   Replace `your_role` with the role used in `SET ROLE`.

   ```sql theme={null}
   GRANT USAGE, CREATE ON SCHEMA bbdataarchive TO your_role;
   ```

### Oracle

1. **Create the backup user:**

   ```sql theme={null}
   CREATE USER bbdataarchive IDENTIFIED BY password;
   ```

2. **Grant connection privileges:**

   ```sql theme={null}
   GRANT CREATE SESSION TO bbdataarchive;
   ```

3. **Grant unlimited space quota:**

   Replace `tablespace_name` with your actual tablespace name.

   ```sql theme={null}
   GRANT QUOTA UNLIMITED ON tablespace_name TO bbdataarchive;
   ```

4. **Grant privileges to the instance administrator:**

   Replace `admin_user` with the actual username that Bytebase uses as the instance administrator.

   ```sql theme={null}
   GRANT CREATE ANY TABLE TO admin_user;
   GRANT SELECT ANY TABLE TO admin_user;
   ```

### SQL Server

1. **Create the backup database:**

   ```sql theme={null}
   CREATE DATABASE bbdataarchive;
   ```

2. **Grant necessary privileges:**

   Replace `your_user` with the actual username that Bytebase uses to connect to your database.

   ```sql theme={null}
   USE bbdataarchive;
   GRANT CONTROL ON DATABASE::bbdataarchive TO your_user;
   ```
