Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 52 additions & 41 deletions mintlify/change-database/rollback-data-changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ feature_name: 'ROLLBACK_DATA_CHANGES'
horizontal
/>

Bytebase allows taking **Prior Backup** before a data change is made. Bytebase stores the pre-snapshot of the affected rows, which allows you to revert that data change if needed.
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>

The backup data is stored in your own database instance. Bytebase does not purge the backup data automatically.
You can manually delete the data in `bbdataarchive` database/schema.
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>

Expand All @@ -30,73 +29,85 @@ You can manually delete the data in `bbdataarchive` database/schema.

## Supported Operations

We are working on enabling backup and 1-click rollback for more SQL statements.
Bytebase continues to expand backup and rollback support for additional SQL statement types.

### Feasibility Conditions

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

- The SQL statement size is less than 2M.

- No mixed `UPDATE`/`DELETE` on the same table.

- 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.

## Create backup
## Enable Prior Backup

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

![bb-issue-backup-on](/content/docs/change-database/rollback-data-changes/bb-issue-backup-on.webp)

You can toggle **Prior Backup** switch before or after creating the issue.
<Note>
If the Prior Backup switch appears disabled, navigate to the database page and click **Sync instance** to refresh the database metadata.
</Note>

![bb-prior-bk-on](/content/docs/change-database/rollback-data-changes/bb-prior-bk-on.webp)
## Perform 1-Click and Multi-Task Rollback

<Note>If the switch is disabled, go to the database page and click **Sync instance** first.</Note>
1. After your database change has been successfully deployed, click the **Rollback available** link to initiate the rollback process.

## 1-click rollback
![bb-issue-done-1](/content/docs/change-database/rollback-data-changes/bb-issue-done-1.webp)

1. Once the change has been rolled out. You can click the **Rollback** button to create the rollback issue.
1. You may see multiple rollbackable changes available, depending on your deployment scenario.

![bb-prior-bk-rollback](/content/docs/change-database/rollback-data-changes/bb-prior-bk-rollback.webp)
<Note>
This could include a single change applied to multiple databases, multiple changes to one database, or a combination of both scenarios.
</Note>

1. The rollback issue automatically populates the rollback statements.
![bb-issue-done-2](/content/docs/change-database/rollback-data-changes/bb-issue-done-2.webp)

![bb-prior-bk-rollback-issue](/content/docs/change-database/rollback-data-changes/bb-prior-bk-rollback-issue.webp)
1. 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.

## Inspect the backup data
![bb-rollback-select](/content/docs/change-database/rollback-data-changes/bb-rollback-select.webp)

You can go to SQL Editor to inspect the backup data. If the DML change contains no more than 5 statements, then each
statements will be backed up to a separate table.
1. Bytebase automatically generates the appropriate rollback SQL statements based on the backup data.

![bb-prior-bk-separate-table](/content/docs/change-database/rollback-data-changes/bb-prior-bk-separate-table.webp)
![bb-rollback-issue-1](/content/docs/change-database/rollback-data-changes/bb-rollback-issue-1.webp)

If the DML change contains more than 5 statements, then all statements will be backed up to a single table.
![bb-rollback-issue-2](/content/docs/change-database/rollback-data-changes/bb-rollback-issue-2.webp)

![bb-prior-bk-single-table-issue](/content/docs/change-database/rollback-data-changes/bb-prior-bk-single-table-issue.webp)
## Inspect Backup Data

![bb-prior-bk-single-table](/content/docs/change-database/rollback-data-changes/bb-prior-bk-single-table.webp)
You can examine the stored backup data using Bytebase's SQL Editor to verify what information has been preserved.

## Project backup settings
![bb-sql-editor-test](/content/docs/change-database/rollback-data-changes/bb-sql-editor-test.webp)
![bb-sql-editor-prod](/content/docs/change-database/rollback-data-changes/bb-sql-editor-prod.webp)

- You can enable **Prior Backup** by default.
- You can control whether you want to skip backup errors and continue changing the data.
## Project Backup Settings

![prior-backup-default](/content/docs/change-database/rollback-data-changes/bb-prior-backup-default.webp)
Configure backup behavior at the project level for consistent data protection:

- **Default backup**: Enable **Prior Backup** by default for all changes in the project
- **Error handling**: Control whether to skip backup errors and proceed with data changes

![prior-backup-default](/content/docs/change-database/rollback-data-changes/bb-prior-backup-default.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

1. Create the `bbdataarchive` Database:
1. **Create the backup database:**

```sql
CREATE DATABASE bbdataarchive;
```

1. Grant Necessary Privileges:
1. **Grant necessary privileges:**

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

```sql
GRANT ALL PRIVILEGES ON bbdataarchive.* TO 'your_user'@'%';
Expand All @@ -105,15 +116,15 @@ If the DML change contains more than 5 statements, then all statements will be b

### PostgreSQL

1. Create the `bbdataarchive` Schema:
1. **Create the backup schema:**

```sql
CREATE SCHEMA bbdataarchive;
```

1. Grant Necessary Privileges:
1. **Grant necessary privileges:**

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

```sql
GRANT ALL PRIVILEGES ON SCHEMA bbdataarchive TO your_user;
Expand All @@ -122,29 +133,29 @@ If the DML change contains more than 5 statements, then all statements will be b

### Oracle

1. Create the `bbdataarchive` User:
1. **Create the backup user:**

```sql
CREATE USER bbdataarchive IDENTIFIED BY password;
```

1. Grant Connection Privileges:
1. **Grant connection privileges:**

```sql
GRANT CREATE SESSION TO bbdataarchive;
```

1. Grant unlimited space quota to the `bbdataarchive` user on the specified `tablespace`:
1. **Grant unlimited space quota:**

Replace `tablespace_name` with the actual tablespace name.
Replace `tablespace_name` with your actual tablespace name.

```sql
GRANT QUOTA UNLIMITED ON tablespace_name TO bbdataarchive;
```

1. Grant Privileges to the Instance Administrator:
1. **Grant privileges to the instance administrator:**

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

```sql
GRANT CREATE ANY TABLE TO admin_user;
Expand All @@ -153,15 +164,15 @@ If the DML change contains more than 5 statements, then all statements will be b

### SQL Server

1. Create the `bbdataarchive` Database:
1. **Create the backup database:**

```sql
CREATE DATABASE bbdataarchive;
```

1. Grant Necessary Privileges:
1. **Grant necessary privileges:**

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

```sql
USE bbdataarchive;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.