The ADD DELETE BACKUP POLICY statement and the DROP DELETE BACKUP POLICY statement are used to set and drop a cleanup policy, respectively.
To enable automatic cleanup for users, you can use the ADD DELETE BACKUP POLICY statement to set a cleanup policy for a tenant. A tenant with a cleanup policy will trigger an automatic cleanup task every hour.
During the execution of a cleanup task, if you only want to cancel the ongoing cleanup task, you can execute the CANCELE DELETE BACKUP statement. For more information about the CANCELE DELETE BACKUP statement, see CANCEL DELETE BACKUP. If you want to prevent the cleanup task from being scheduled for execution in the future, you must first execute the DROP DELETE BACKUP POLICY statement to remove the automatic cleanup policy, and then execute the CANCELE DELETE BACKUP statement to cancel the ongoing cleanup task.
Limitations and considerations
When using the
ADD DELETE BACKUP POLICYstatement to set a cleanup policy, only tenant-level automatic cleanup policies are supported; cluster-level cleanup policies are not supported.Each command can set or remove only one cleanup strategy for a tenant.
When you use the
DROP DELETE BACKUP POLICYstatement to drop a tenant's cleanup policy, if all cleanup policies for the tenant are dropped, the automatic cleanup feature for that tenant is effectively disabled.Dropping a cleanup policy using the
DROP DELETE BACKUP POLICYstatement does not affect ongoing cleanup tasks. It only means that the system will no longer generate cleanup tasks for the dropped policy during the next automatic cleanup scheduling.
Privilege requirements
This statement must be executed by the root user of the sys tenant (root@sys) or the administrator user of a user tenant (root user).
Syntax
ALTER SYSTEM delete_backup_action [ TENANT [=] tenant_name ];
delete_backup_action:
ADD DELETE BACKUP POLICY [=] policy_name [RECOVERY_WINDOW [=] recovery_window]
| DROP DELETE BACKUP POLICY [=] policy_name
Parameters
Parameter |
Description |
|---|---|
| POLICY | Specifies the cleanup policy name. Valid values:
|
| RECOVERY_WINDOW | Optional. Controls the time window within which backup data can be restored. If this parameter is not explicitly specified, the default time window is 0 days, meaning the backup set will not expire and the system will not perform cleanup. For more information about this parameter, see Introduction to backup cleanup parameters. |
| tenant_name | Optional. The name of the tenant. This parameter is required only when the statement is executed by the system tenant. |
Examples
System tenant
The system tenant sets the cleanup strategy for the
mysql_tenanttenant todefault, with a recoverable time window of 7 days for backup data.obclient [oceanbase]> ALTER SYSTEM ADD DELETE BACKUP POLICY = 'default' RECOVERY_WINDOW ='7d' TENANT = mysql_tenant;After successful configuration, you can use the following statement to view the cleanup strategy set for the tenant.
obclient [oceanbase]> SELECT * FROM oceanbase.CDB_OB_BACKUP_DELETE_POLICY WHERE TENANT_ID=1002;The query result is as follows:
+-----------+-------------+-----------------+ | TENANT_ID | POLICY_NAME | RECOVERY_WINDOW | +-----------+-------------+-----------------+ | 1002 | default | 7d | +-----------+-------------+-----------------+ 1 row in setThe system tenant's cleanup policy
defaultfor deleting themysql_tenanttenant.obclient [oceanbase]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default' TENANT mysql_tenant;
User tenant
The tenant
mysql_tenanthas its cleanup policy set todefault, and the time window for restoring backed-up data is 7 days.obclient [SYS]> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';After the cleanup policy is successfully set, you can use the following statement to view the cleanup policies set for the current tenant.
obclient [SYS]> SELECT * FROM SYS.DBA_OB_BACKUP_DELETE_POLICY;The query result is as follows:
+-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in setThe cleanup policy for the tenant
mysql_tenantwhen it is deleted.obclient [SYS]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default';