After a backup is successfully performed, you can set retention policies for tenants based on your business requirements. Tenants with retention policies will trigger an automatic cleanup process every hour to ensure that expired backups are promptly removed.
The current version only supports the automatic cleanup of expired backups and does not support manual cleanup of expired backups.
Considerations
Log archive data can be cleared only after data backups are performed. If no data backup files exist, the system does not automatically clean up log archive data.
Automatic cleanup is supported only for the backup and archive destinations specified by using the
DATA_BACKUP_DESTandLOG_ARCHIVE_DESTparameters. If the backup or archive destination is changed, the data in the original backup or archive destination cannot be cleared by using OceanBase Database.Automatic cleanup retains at least one valid backup copy. If only one valid backup copy exists, this copy will not be cleared.
Different backup media have varying results for automatic backup cleaning:
- For backup media like NFS or object storage compatible with the S3 protocol (such as OBS, GCS, etc.), the system will directly delete backup files that meet the requirements during data cleanup.
- For scenarios where the backup destination is S3/COS (accessed via the S3 protocol), the method of cleaning backup files depends on the value of the
delete_modeparameter indata_backup_destandlog_archive_dest. For detailed information on this parameter, refer to SET LOG_ARCHIVE_DEST and SET DATA_BACKUP_DEST.
Specifically, for paths where the
enable_worm=trueparameter is configured, the system will select backup sets that meet the conditions for cleanup based on the time specified byRECOVERY_WINDOW. However, whether the cleanup is successful depends on the cleanup mode corresponding to the path (the value of thedelete_modeparameter) and the retention policy of the corresponding bucket.Notice
The
enable_worm=trueparameter is applicable in scenarios where a compliance retention policy (WORM) is enabled. Starting from version V4.3.5 BP2, OceanBase Database supports using Alibaba Cloud OSS buckets configured with a WORM policy as backup or archive paths.For example, if a backup set is outside the time specified by
RECOVERY_WINDOWbut still within the WORM (Write Once Read Many) retention period, then:If the cleanup mode of the backup set is
delete, OceanBase Database will fail to clean up the backup set. Cleanup can only occur after the retention period of the object expires.If the cleanup mode is
tagging, OceanBase Database will tag the backup set, and the object storage will execute the deletion after the lifecycle ends and the WORM retention period has passed.
Set a cleanup policy
Set a cleanup policy in a user tenant
Log in to the database as the tenant administrator of the user tenant.
Set a cleanup policy to enable the automatic cleanup feature for the tenant.
The statement is as follows:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;where:
The
POLICYparameter specifies the name of the cleanup policy. Set the value todefault. This indicates that automatic cleanup applies only to backups specified by thedata_backup_destandlog_archive_destparameters.The
RECOVERY_WINDOWparameter specifies the time window during which backup data can be restored. For more information about this parameter, see recovery_window.
Example:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';
Set a cleanup policy in the sys tenant
Log in to the
systenant of the cluster as therootuser.Set a cleanup policy to enable the automatic cleanup feature for the tenant.
The statement is as follows:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window TENANT tenant_name;where:
The
POLICYparameter specifies the name of the cleanup policy. Set the value todefault. This indicates that automatic cleanup applies only to backups specified by thedata_backup_destandlog_archive_destparameters.The
RECOVERY_WINDOWparameter specifies the time window during which backup data can be restored. For more information about this parameter, see recovery_window.The
TENANTparameter specifies the tenant for which the cleanup policy takes effect. Specify the name of a user tenant. You can specify only one tenant name.
Notice
You can set a cleanup policy only at the tenant level. You cannot set a cleanup policy at the cluster level. Moreover, the statement in a single session can set cleanup policies for only one tenant.
Here is an example of setting a cleanup policy for a MySQL tenant in the sys tenant:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT MySQL;
Query the cleanup policies
Both system tenants and user tenants can query views to obtain the cleanup policies that have been set.
Log in to the database as the tenant administrator of the system tenant or user tenant.
Query the cleanup policies set for the tenant.
Query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview in the sys tenant to obtain the cleanup policies set for all tenants.Here is an example:
obclient> SELECT * FROM oceanbase.CDB_OB_BACKUP_DELETE_POLICY; +-----------+-------------+-----------------+ | TENANT_ID | POLICY_NAME | RECOVERY_WINDOW | +-----------+-------------+-----------------+ | 1002 | default | 7d | +-----------+-------------+-----------------+ 1 row in setQuery the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview or thesys.DBA_OB_BACKUP_DELETE_POLICYview to obtain the cleanup policies set for the current tenant.For a MySQL tenant
obclient [(none)]> SELECT * FROM oceanbase.DBA_OB_BACKUP_DELETE_POLICY; +-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in setFor an Oracle tenant
obclient [SYS]> SELECT * FROM sys.DBA_OB_BACKUP_DELETE_POLICY; +-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in set