If you need to manually clean up specific backup or archive data due to business requirements, you can refer to this topic to manually clean up specified data backup sets or log archive pieces.
Limitations
When manually cleaning up specified backup or archive data, the user tenant being operated on must not have an automatic cleanup policy configured. If an automatic cleanup policy is configured, manual cleanup cannot be performed.
For scenarios where only log archiving is enabled and no data backup path is configured, you cannot manually clean up specified log archive pieces. Users can only achieve the cleanup of log archive pieces by configuring the automatic cleanup policy to
log_only.For more information about how to configure an automatic cleanup policy, see Automatically clean up expired backups.
Clean up a specified data backup set
Precautions
When you clean up a specified data backup set, note the following:
If you need to specify multiple
BACKUP_SET_IDfor cleanup, allBACKUP_SET_IDmust be under the same backup path. Cleaning up data backups from multiple paths in a single command is not supported.For the currently in-use backup path, you must retain at least one latest full data backup that can be used for recovery. That is, you can delete other backup sets before the one to be cleaned up only after retaining a full backup available for recovery.
If the data backup set to be deleted is not in the currently used backup path, make sure that OceanBase AI Database has access permissions on the corresponding backup path.
Clean up a specified data backup set for a specified user tenant in the sys tenant
Log in to the
systenant of the cluster as therootuser.Here is an example of how to connect to the database. Use the actual environment settings when you connect to the database.
obclient -h10.xx.xx.xx -P2883 -uroot@sys#obdemo -p***** -AView tenant information to obtain the tenant's
TENANT_ID.This document uses the tenant
mysql001as an example. The query example is as follows:obclient(root@sys)[(none)]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';The query result is as follows:
+-----------+-------------+-------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | +-----------+-------------+-------------+ | 1002 | mysql001 | USER | +-----------+-------------+-------------+ 1 row in setAccording to the query result, the
TENANT_IDof this tenant is 1002.Obtain the
backup_set_idof the backup set to be cleaned up.obclient(root@sys)[(none)]> SELECT TENANT_ID, BACKUP_SET_ID, BACKUP_TYPE, PREV_FULL_BACKUP_SET_ID, PREV_INC_BACKUP_SET_ID, STATUS, FILE_STATUS, START_REPLAY_SCN, START_REPLAY_SCN_DISPLAY, MIN_RESTORE_SCN, MIN_RESTORE_SCN_DISPLAY, PATH FROM oceanbase.CDB_OB_BACKUP_SET_FILES WHERE TENANT_ID = 1002;The query result is as follows:
+-----------+---------------+-------------+-------------------------+------------------------+---------+-------------+---------------------+----------------------------+---------------------+-------------------------------+-------------------------------+ | TENANT_ID | BACKUP_SET_ID | BACKUP_TYPE | PREV_FULL_BACKUP_SET_ID | PREV_INC_BACKUP_SET_ID | STATUS | FILE_STATUS | START_REPLAY_SCN | START_REPLAY_SCN_DISPLAY | MIN_RESTORE_SCN | MIN_RESTORE_SCN_DISPLAY | PATH | +-----------+---------------+-------------+-------------------------+------------------------+---------+-------------+---------------------+----------------------------+---------------------+-------------------------------+-------------------------------+ | 1002 | 1 | FULL | 0 | 0 | SUCCESS | AVAILABLE | 1757326402739265000 | 2025-09-08 18:13:22.739265 | 1757326563751672000 | 2025-09-08 18:16:03.751672000 | s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com | | 1002 | 3 | FULL | 0 | 0 | SUCCESS | AVAILABLE | 1757326402739265000 | 2025-09-08 18:13:22.739265 | 1757326826319880000 | 2025-09-08 18:20:26.319880000 | s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com | | 1002 | 4 | FULL | 0 | 0 | SUCCESS | AVAILABLE | 1757326402739265000 | 2025-09-08 18:13:22.739265 | 1757326961311034000 | 2025-09-08 18:22:41.311034000 | s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com | | 1002 | 5 | FULL | 0 | 0 | SUCCESS | AVAILABLE | 1757326402739265000 | 2025-09-08 18:13:22.739265 | 1757327092469081000 | 2025-09-08 18:24:52.469081000 | s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com | | 1002 | 6 | FULL | 0 | 0 | SUCCESS | AVAILABLE | 1757326402739265000 | 2025-09-08 18:13:22.739265 | 1757327219591390000 | 2025-09-08 18:26:59.591390000 | s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com | +-----------+---------------+-------------+-------------------------+------------------------+---------+-------------+---------------------+----------------------------+---------------------+-------------------------------+-------------------------------+ 6 rows in setAccording to the query result, for the tenant with the tenant ID
1002, five full backups are all located in the same backup path. Specifically:- The backups with
BACKUP_SET_ID1, 3, 4, 5, and 6 are full backups.
According to the cleanup requirements:
If the backup path where the backup set to be deleted is located is the backup path currently used by the tenant, you must retain the latest full backup that can be used for restore, and earlier backups can be deleted.
Whether a backup can be used for restore depends on whether the required log archive data is complete. For example, in this scenario, you can determine whether the full backup
BACKUP_SET_ID6 can be used for restore as follows:Check the log archive pieces in the current archive path to make sure that a complete and continuous log archive piece from
START_REPLAY_SCNtoMIN_RESTORE_SCNof the backup set exists. If no such log archive piece exists,BACKUP_SET_ID6 cannot be used for restore. In this case, you must check whether the previous full backupBACKUP_SET_ID5 can be used for restore in the same way, and so on.
- The backups with
Execute the following statement to delete the specified data backup:
ALTER SYSTEM DELETE BACKUPSET backup_set_id[,backup_set_id,...] TENANT [=] tenant_name;The parameters in the statement are described as follows:
backup_set_id: the ID of the backup set to be deleted. You can specify multiple data backup sets in a single statement. If you specify multiplebackup_set_idvalues for cleanup, all of them must be in the same backup path. You cannot clean up data backups in multiple paths in a single statement.tenant_name: the tenant for which the backup set is to be deleted.
Here are some examples:
Delete the data backup set with
backup_set_id3 of themysql001tenant.obclient(root@sys)[(none)]> ALTER SYSTEM DELETE BACKUPSET 3 TENANT = mysql001;Delete the three data backup sets with
backup_set_id1, 2, and 4 of themysql001tenant at the same time.obclient(root@sys)[(none)]> ALTER SYSTEM DELETE BACKUPSET 1,2,4 TENANT = mysql001;
Clean up specified data backup sets in a user tenant
Log in to the database as a tenant administrator.
Note
The administrator user of a user tenant is the
rootuser.Here is an example of how to connect to the database. Use the actual environment settings when you connect to the database.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql001#obdemo -p***** -AObtain the
backup_set_idof the backup set to be cleaned up.A sample query is as follows:
obclient(root@mysql001)[(none)]> SELECT BACKUP_SET_ID, BACKUP_TYPE, PREV_FULL_BACKUP_SET_ID, PREV_INC_BACKUP_SET_ID, STATUS, FILE_STATUS, START_REPLAY_SCN, START_REPLAY_SCN_DISPLAY, MIN_RESTORE_SCN, MIN_RESTORE_SCN_DISPLAY, PATH FROM oceanbase.DBA_OB_BACKUP_SET_FILES;Execute the following statement to delete the specified data backup:
ALTER SYSTEM DELETE BACKUPSET backup_set_id[,backup_set_id,...];The parameters in the statement are described as follows:
backup_set_id: the ID of the backup set to be deleted. You can specify multiple data backup sets in a single statement, separated by commas. If you specify multiplebackup_set_idvalues for cleanup, all of them must be in the same backup path. You cannot clean up data backups in multiple paths in a single statement.tenant_name: the tenant for which the backup set is to be deleted.
Here are some examples:
Delete the data backup set with
backup_set_id3 of the current tenant.obclient> ALTER SYSTEM DELETE BACKUPSET 3;Delete the three data backup sets with
backup_set_id1, 2, and 4 of the current tenant at the same time.obclient> ALTER SYSTEM DELETE BACKUPSET 1,2,4;
Clean up a specified log archive piece
Precautions
When you clean up a specified log archive piece, note the following:
You must clean up log archive pieces in order.
When you clean up pieces in the current archive path, make sure that the piece to be cleaned up is not depended on by any data backup in the current data backup path.
To determine whether a piece to be cleaned up is depended on by a data backup set, perform the following steps:
In the current backup path of the tenant, find a data backup set that was created earlier.
Check the
START_REPLAY_SCNof this data backup set.System tenant
obclient(root@sys)[(none)]> SELECT * FROM oceanbase.CDB_OB_BACKUP_SET_FILES WHERE TENANT_ID = tenant_id AND BACKUP_SET_ID = set_id;User tenant
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_BACKUP_SET_FILES WHERE BACKUP_SET_ID = set_id;obclient(SYSt@oracl001)[SYS]> SELECT * FROM SYS.DBA_OB_BACKUP_SET_FILES WHERE BACKUP_SET_ID = set_id;
For more information, see View data backup results.
Check the
END_SCNof the piece to be cleaned up.System tenant
obclient(root@sys)[(none)]> SELECT * FROM oceanbase.CDB_OB_ARCHIVELOG_PIECE_FILES WHERE TENANT_ID = tenant_id AND PIECE_ID = piece_id;User tenant
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_ARCHIVELOG_PIECE_FILES WHERE PIECE_ID = piece_id;obclient(SYSt@oracl001)[SYS]> SELECT * FROM SYS.DBA_OB_ARCHIVELOG_PIECE_FILES WHERE PIECE_ID = piece_id;
For more information, see View piece information.
Compare the obtained information. If the
END_SCNof the piece to be cleaned up is greater than or equal to theSTART_REPLAY_SCNof any data backup in the current backup path, it means this piece is depended on by that data backup set.
If you specify multiple
PIECE_IDvalues for cleanup, all of them must be in the same archive path. You cannot clean up log archive pieces in multiple paths in a single statement.
Clean up specified log archive pieces for a specified tenant in the sys tenant
Log in to the
systenant of the cluster as therootuser.Here is an example of how to connect to the database. Use the actual environment settings when you connect to the database.
obclient -h10.xx.xx.xx -P2883 -uroot@sys#obdemo -p***** -AQuery tenant information and obtain the tenant's
TENANT_ID.This topic uses the
mysql001tenant as an example. A sample query is as follows:obclient(root@sys)[(none)]> SELECT TENANT_ID, TENANT_NAME, TENANT_TYPE FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mysql001';The query result is as follows:
+-----------+-------------+-------------+ | TENANT_ID | TENANT_NAME | TENANT_TYPE | +-----------+-------------+-------------+ | 1002 | mysql001 | USER | +-----------+-------------+-------------+ 1 row in setAccording to the query result, the
TENANT_IDof this tenant is 1002.Obtain the
piece_idof the log archive piece to be cleaned up.obclient(root@sys)[(none)]> SELECT TENANT_ID, ROUND_ID, PIECE_ID, STATUS, FILE_STATUS, START_SCN, START_SCN_DISPLAY, END_SCN, END_SCN_DISPLAY, PATH FROM oceanbase.CDB_OB_ARCHIVELOG_PIECE_FILES WHERE TENANT_ID = 1002;The query result is as follows:
+-----------+----------+----------+--------+-------------+---------------------+----------------------------+---------------------+----------------------------+----------------------------------+ | TENANT_ID | ROUND_ID | PIECE_ID | STATUS | FILE_STATUS | START_SCN | START_SCN_DISPLAY | END_SCN | END_SCN_DISPLAY | PATH | +-----------+----------+----------+--------+-------------+---------------------+----------------------------+---------------------+----------------------------+----------------------------------+ | 1002 | 1 | 1 | FROZEN | AVAILABLE | 1757333158537074000 | 2025-09-08 20:05:58.537074 | 1757333218537074000 | 2025-09-08 20:06:58.537074 | s3://oceanbase-test-bucket/backup/archive1?host=obs.****.myhuaweicloud.com | | 1002 | 1 | 2 | FROZEN | AVAILABLE | 1757333218537074000 | 2025-09-08 20:06:58.537074 | 1757333278537074000 | 2025-09-08 20:07:58.537074 | s3://oceanbase-test-bucket/backup/archive1?host=obs.****.myhuaweicloud.com | | 1002 | 1 | 3 | FROZEN | AVAILABLE | 1757333278537074000 | 2025-09-08 20:07:58.537074 | 1757333338537074000 | 2025-09-08 20:08:58.537074 | s3://oceanbase-test-bucket/backup/archive1?host=obs.****.myhuaweicloud.com | | 1002 | 1 | 4 | ACTIVE | AVAILABLE | 1757333338537074000 | 2025-09-08 20:08:58.537074 | 1757333398537074000 | 2025-09-08 20:09:58.537074 | s3://oceanbase-test-bucket/backup/archive1?host=obs.****.myhuaweicloud.com | | 1002 | 2 | 5 | FROZEN | AVAILABLE | 1757333589335423000 | 2025-09-08 20:13:09.335423 | 1757333649335423000 | 2025-09-08 20:14:09.335423 | s3://oceanbase-test-bucket/backup/archive2?host=obs.****.myhuaweicloud.com | | 1002 | 3 | 6 | FROZEN | AVAILABLE | 1757333769705693000 | 2025-09-08 20:16:09.705693 | 1757333829705693000 | 2025-09-08 20:17:09.705693 | s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com | | 1002 | 3 | 7 | FROZEN | AVAILABLE | 1757333829705693000 | 2025-09-08 20:17:09.705693 | 1757333889705693000 | 2025-09-08 20:18:09.705693 | s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com | | 1002 | 3 | 8 | ACTIVE | AVAILABLE | 1757333889705693000 | 2025-09-08 20:18:09.705693 | 1757333949705693000 | 2025-09-08 20:19:09.705693 | s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com | | 1002 | 3 | 9 | FROZEN | AVAILABLE | 1757333949705693000 | 2025-09-08 20:19:09.705693 | 1757334009705693000 | 2025-09-08 20:20:09.705693 | s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com | | 1002 | 3 | 10 | FROZEN | AVAILABLE | 1757334009705693000 | 2025-09-08 20:20:09.705693 | 1757334069705693000 | 2025-09-08 20:21:09.705693 | s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com | +-----------+----------+----------+--------+-------------+---------------------+----------------------------+---------------------+----------------------------+----------------------------------+ 10 rows setAccording to the query result, the tenant with the tenant ID
1002has 10 log archive pieces. Specifically:- The log archive pieces with
PIECE_ID1, 2, 3, and 4 come from the same archive path:s3://oceanbase-test-bucket/backup/archive1?host=obs.****.myhuaweicloud.com. - The log archive piece with
PIECE_ID5 comes from the archive path:s3://oceanbase-test-bucket/backup/archive2?host=obs.****.myhuaweicloud.com. - The log archive pieces with
PIECE_ID6, 7, 8, 9, and 10 come from the archive path:s3://oceanbase-test-bucket/backup/archive3?host=obs.****.myhuaweicloud.com.
According to the cleanup requirements:
Pieces must be cleaned up in order. For example, you cannot clean up one or more pieces with
PIECE_ID2, 3, or 4 first, and then clean up the piece withPIECE_ID1. Similarly, you cannot clean up any one or more pieces withPIECE_ID7, 8, 9, or 10 first, and then clean up the piece withPIECE_ID6.Multiple pieces can be cleaned up simultaneously in order. For example, pieces 1, 2, and 3 can be cleaned up together.
When specifying multiple
PIECE_IDvalues, allPIECE_IDmust refer to pieces in the same archive path. For example, you cannot clean up pieces withPIECE_ID1, 2, and 5, or 5, 6, and 7 at the same time.
- The log archive pieces with
Execute the following statement to delete the specified log archive piece:
ALTER SYSTEM DELETE ARCHIVELOG_PIECE piece_id[,piece_id,...] TENANT [=] tenant_name;The parameters in the statement are described as follows:
piece_id: the ID of the log archive piece to be deleted. You can specify multiple pieces in a single statement. If you specify multiplepiece_idvalues for cleanup, all pieces must be in the same archive path. You cannot clean up log archive pieces in multiple paths in a single statement.tenant_name: the tenant for which the log archive piece is to be deleted.
Here is an example:
Delete the log archive piece with
piece_id5 of themysql001tenant.obclient(root@sys)[(none)]> ALTER SYSTEM DELETE ARCHIVELOG_PIECE 5 TENANT = mysql001;Delete the four log archive pieces with
piece_id6, 7, 8, and 9 of themysql001tenant at the same time.obclient(root@sys)[(none)]> ALTER SYSTEM DELETE ARCHIVELOG_PIECE 6,7,8,9 TENANT = mysql001;
Clean up specified log archive pieces in a user tenant
Log in to the database as a tenant administrator.
Note
The administrator user of a user tenant is the
rootuser.Here is an example of how to connect to the database. Use the actual environment settings when you connect to the database.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql001#obdemo -p***** -AObtain the
piece_idof the log archive piece to be cleaned up.A sample query is as follows:
obclient(root@mysql001)[(none)]> SELECT ROUND_ID, PIECE_ID, STATUS, FILE_STATUS, START_SCN, START_SCN_DISPLAY, END_SCN, END_SCN_DISPLAY, PATH FROM oceanbase.DBA_OB_ARCHIVELOG_PIECE_FILES;Execute the following statement to delete the specified log archive piece:
ALTER SYSTEM DELETE ARCHIVELOG_PIECE piece_id[,piece_id,...];The parameters in the statement are described as follows:
piece_id: the ID of the log archive piece to be deleted. You can specify multiple pieces in a single statement. If you specify multiplepiece_idvalues for cleanup, all pieces must be in the same archive path. You cannot clean up log archive pieces in multiple paths in a single statement.tenant_name: the tenant for which the log archive pieces are to be deleted.
Here is an example:
Delete the log archive piece with
piece_id5 of the current tenant.obclient> ALTER SYSTEM DELETE ARCHIVELOG_PIECE 5;Delete the four log archive pieces with
piece_id6, 7, 8, and 9 of the current tenant at the same time.obclient> ALTER SYSTEM DELETE ARCHIVELOG_PIECE 6,7,8,9;