You can execute the ADD DELETE BACKUP POLICY statement to set a cleanup strategy and the DROP DELETE BACKUP POLICY statement to drop a cleanup strategy.
If you want to enable the automatic cleanup feature for a user, you can use the ADD DELETE BACKUP POLICY statement to set a cleanup strategy for the tenant. A tenant with a cleanup strategy in effect will trigger an automatic cleanup task every hour.
While an automatic cleanup task is being executed, you can use the CANCEL DELETE BACKUP statement to cancel the task. For more information, see CANCEL DELETE BACKUP. If you want to stop a scheduled automatic cleanup task from being executed, you must first use the DROP DELETE BACKUP POLICY statement to drop the automatic cleanup strategy, and then use the CANCEL DELETE BACKUP statement to cancel the task.
Limitations and considerations
When you use the
ADD DELETE BACKUP POLICYstatement to set a cleanup strategy, you can set only a tenant-level cleanup strategy, not a cluster-level one.You can set or delete a cleanup strategy for only one tenant per command.
If you use the
DROP DELETE BACKUP POLICYstatement to delete a cleanup strategy for a tenant, and all cleanup strategies of the tenant are deleted, the automatic cleanup feature of the tenant is disabled.Deleting a cleanup strategy does not affect ongoing cleanup tasks. It only means that the deleted cleanup strategy will not generate new cleanup tasks during the next automatic cleanup scheduling.
Privilege requirements
You must use the root user of the sys tenant (root@sys) or the administrator of each tenant to perform the operation. By default:
- In MySQL mode, the default administrator is the
rootuser. - In Oracle mode, the default administrator is the
SYSuser.
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 strategy. Currently, you can specify only default, which specifies to automatically clear only the backups in the data_backup_dest and log_archive_dest parameters. |
| RECOVERY_WINDOW | The time window within which backup data can be restored. It is optional. If you do not specify this parameter, the default value of 0 is used, which means that the backup sets will not expire and the system will not perform automatic cleanup. For more information about this parameter, see Parameters of automatic cleanup. |
Examples
System tenant
Set the cleanup strategy of the
mysql_tenanttenant todefault, which specifies to retain backup data for 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 view the cleanup strategy that has been 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 setDelete the
defaultcleanup strategy from themysql_tenanttenant.obclient [oceanbase]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default' TENANT mysql_tenant;
User tenant
Set the cleanup strategy of the
oracle_tenanttenant todefault, which specifies to retain backup data for 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 view the cleanup strategy that has been set for 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 from the
oracle_tenanttenant.obclient [SYS]> ALTER SYSTEM DROP DELETE BACKUP POLICY 'default';