The ADD DELETE BACKUP POLICY and DROP DELETE BACKUP POLICY statements are used to set and drop the cleanup strategy respectively.
To enable the automatic cleanup feature for a user, you can set a cleanup strategy for the tenant by using the ADD DELETE BACKUP POLICY statement. A tenant with a cleanup strategy will trigger an automatic cleanup task every hour.
During a cleanup task, you can execute the CANCELE DELETE BACKUP statement to cancel the task. For more information about the CANCELE DELETE BACKUP statement, see CANCEL DELETE BACKUP. To cancel a scheduled cleanup task, you need to execute the DROP DELETE BACKUP POLICY statement to delete the automatic cleanup strategy first, and then execute the CANCELE DELETE BACKUP statement to cancel the task.
Limitations and considerations
When you use the
ADD DELETE BACKUP POLICYstatement to set a cleanup policy, you can set only a tenant-level automatic cleanup policy, but not a cluster-level cleanup policy.You can use each command to set or delete a cleanup policy for only one tenant.
When you use the
DROP DELETE BACKUP POLICYstatement to delete a cleanup policy of a tenant, the tenant's automatic cleanup feature is disabled if all its cleanup policies are deleted.The
DROP DELETE BACKUP POLICYstatement will not affect the ongoing cleanup tasks. It only means that the deleted cleanup policy will no longer generate cleanup tasks in the future when the system schedules automatic cleanup.
Privilege requirements
You must be the root user of the sys tenant or a tenant administrator. Here are the default administrators in MySQL and Oracle modes respectively:
rootuser in MySQL modeSYSuser in Oracle mode
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 |
|---|---|
| tenant_name | The name of the tenant. |
| POLICY | The name of the cleanup policy. The value must be default. This indicates that the scope of automatic cleanup is only the backups stored in the destinations specified by the data_backup_dest and log_archive_dest parameters. |
| RECOVERY_WINDOW | The time window in which backup data can be restored. This parameter is optional. If it is not explicitly specified, the default value is 0, which indicates that the backup sets do not expire and the system will not perform cleanup. For more information about this parameter, see Parameters related to backup cleanup. |
Examples
System tenant
Set the cleanup strategy of the
mysql_tenanttenant todefaultand the backup data restore window to 7 days.obclient [oceanbase]> ALTER SYSTEM ADD DELETE BACKUP POLICY = 'default' RECOVERY_WINDOW ='7d' TENANT = mysql_tenant;After the setting is successful, you can execute the following statement to query the cleanup strategy of 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 setDelete the cleanup strategy
defaultof themysql_tenanttenant.obclient [oceanbase]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default' TENANT mysql_tenant;
User tenant
Set the cleanup strategy of the
oracle_tenanttenant todefaultand the backup data restore window to 7 days.obclient [SYS]> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';After the setting is successful, you can execute the following statement to query the cleanup strategy of the 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 setDelete the cleanup strategy of the
oracle_tenanttenant.obclient [SYS]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default';