After a backup is successfully performed, you can set a cleanup policy for a tenant based on your business requirements. A tenant with a cleanup policy triggers an automatic cleanup every hour to ensure that expired backups or archive data is promptly removed.
Considerations
Log archive data can be cleared only after data backups are performed. Before you clean up log archive data, make sure that data backup files exist. If no data backup files exist, log archive data cannot be cleaned up.
Automatic cleanup is supported only for the backup or archive data stored in the paths currently specified by the
DATA_BACKUP_DESTandLOG_ARCHIVE_DESTparameters. Data in the backup paths and archive paths that are no longer in use is not cleaned up. If the backup destination or archive destination has been changed, the data in the original backup path or archive path can be cleaned up only manually.For more information about manually cleaning up backup or archive data, see Manually clean up specified backup or archive data and Manually clear a backup or archive path.
Automatic cleanup retains at least one valid backup copy. If only one valid backup copy exists, this copy is not cleaned up.
Different backup media have varying results for automatic cleanup of backup or archive data:
- For backup media such as object storage compatible with the S3 protocol (OBS, GCS, and so on), the system directly deletes the backup files that meet the cleanup requirements during backup data cleanup.
- For scenarios where the backup destination is S3/COS (accessed by using the S3 protocol), the method of cleaning backup files depends on the value of the
delete_modeparameter indata_backup_destandlog_archive_dest. For more information about this parameter, see SET LOG_ARCHIVE_DEST and SET DATA_BACKUP_DEST.
In particular, for paths where the
enable_worm=trueparameter is configured in the path attributes, during automatic cleanup of backup or archive data, the system selects the backup or archive data that meets the conditions 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.Note
The
enable_worm=trueparameter is applicable to scenarios where the compliance retention policy (WORM) is enabled.For example, if a backup set is outside the time specified by
RECOVERY_WINDOWbut is still within the WORM (Write Once Read Many) retention period, then:If the cleanup mode of the backup set is
delete, OceanBase AI Database fails to clean up the backup set. You must wait until the retention period of the object expires before you can clean it up.If the cleanup mode of the backup set is
tagging, OceanBase AI Database tags the backup set, and the object storage finally deletes it after its lifecycle ends and the WORM retention period has passed.
Set a cleanup policy for a specified user tenant in the sys tenant
Log in to the
systenant of the cluster as therootuser.Set a cleanup policy to enable the automatic cleanup feature of the tenant.
The statement is as follows:
ALTER SYSTEM ADD DELETE BACKUP POLICY [=] policy_name RECOVERY_WINDOW [=] recovery_window TENANT [=] tenant_name;where:
policy_name: specifies the name of the cleanup policy. Supported values:default: automatic cleanup applies only to the backup and archive data stored in the paths currently specified by theDATA_BACKUP_DESTandLOG_ARCHIVE_DESTparameters of the tenant.log_only: automatic cleanup applies only to the logs in the archive path currently specified by theLOG_ARCHIVE_DESTparameter of the tenant. This mode is applicable when only log archiving is enabled and no data backup is performed. When the cleanup policy is set tolog_only, the current value ofDATA_BACKUP_DESTfor the tenant must be empty, which means that no data backup destination is configured. Accordingly, if alog_onlycleanup policy has been set, you can no longer configure a backup destination by setting theDATA_BACKUP_DESTparameter.
The
recovery_windowparameter specifies the time window during which backup data can be restored. For more information about this parameter, see Introduction to backup cleanup parameters.The
TENANTparameter specifies the tenant for which the cleanup policy takes effect. You must specify the name of a user tenant, and only one tenant name is supported.
Note
Only tenant-level cleanup policies are supported. Cluster-level cleanup policies are not supported. Each statement can set a cleanup policy for only one tenant.
Example: set a cleanup policy for the
mysql001tenant from the sys tenant.obclient(root@sys)[(none)]> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT mysql001;Note
The automatic cleanup task is triggered by the background system every hour. Therefore, after a cleanup policy is set, you may need to wait for some time (no more than one hour) before the corresponding cleanup task can be queried.
View the configured cleanup policies.
After the cleanup policies are configured, you can query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview to view the cleanup policies of all tenants.obclient(root@sys)[oceanbase]> SELECT TENANT_ID, POLICY_NAME, RECOVERY_WINDOW FROM oceanbase.CDB_OB_BACKUP_DELETE_POLICY;The query result is as follows:
+-----------+-------------+-----------------+ | TENANT_ID | POLICY_NAME | RECOVERY_WINDOW | +-----------+-------------+-----------------+ | 1002 | default | 7d | | 1004 | log_only | 7d | +-----------+-------------+-----------------+ 2 rows in set
Set a cleanup policy in a user tenant
Log in to the database as the tenant administrator of the user tenant.
Note
The administrator user of a user tenant is the
rootuser.Set a cleanup policy to enable the automatic cleanup feature of the tenant.
The statement is as follows:
ALTER SYSTEM ADD DELETE BACKUP POLICY [=] policy_name RECOVERY_WINDOW [=] recovery_window;where:
policy_name: specifies the name of the cleanup policy. Supported values:default: automatic cleanup applies only to the backup and archive data stored in the paths currently specified by theDATA_BACKUP_DESTandLOG_ARCHIVE_DESTparameters of the tenant.log_only: automatic cleanup applies only to the logs in the archive path currently specified by theLOG_ARCHIVE_DESTparameter of the tenant. This mode is applicable when only log archiving is enabled and no data backup is performed. When the cleanup policy is set tolog_only, the current value ofDATA_BACKUP_DESTfor the tenant must be empty, which means that no data backup destination is configured. Accordingly, if alog_onlycleanup policy has been set, you can no longer set theDATA_BACKUP_DESTparameter.
recovery_window: specifies the time window during which backup data can be restored. For more information about this parameter, see Introduction to backup cleanup parameters.
Example: set the cleanup policy of the current tenant to
defaultand the time window during which backups can be restored to 7 days.obclient(root@mysql001)[(none)]> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';Note
The automatic cleanup task is triggered by the background system every hour. Therefore, after a cleanup policy is set, you may need to wait for some time (no more than one hour) before the corresponding cleanup task can be queried.
View the configured cleanup policy.
After the cleanup policy is configured, you can query the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview to view the cleanup policy of the current tenant.The sample query is as follows:
obclient(root@mysql001)[oceanbase]> SELECT POLICY_NAME, RECOVERY_WINDOW FROM oceanbase.DBA_OB_BACKUP_DELETE_POLICY;The query result is as follows:
+-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in set
What to do next
After a cleanup policy is configured, if you need to change the cleanup policy, you must delete the current cleanup policy first and then configure a new one. For more information about how to delete a cleanup policy, see Delete a cleanup policy.
After a cleanup policy is configured, if you want to perform an expired backup cleanup as soon as possible, you can manually trigger an expired backup cleanup task. For more information, see Manually trigger expired backup cleanup.