After a backup is successfully created, 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 deleted.
The current version only supports the automatic cleanup of expired backups and does not support manual cleanup of expired backups.
Considerations
Log archive data will only be cleared after data backups are performed. Therefore, before you clear log archive data, you must make sure that backup files exist. If no backup files exist, the log archive data cannot be cleared.
The automatic cleanup feature only supports clearing backup data and log archive data that are stored in the backup destination and archive destination specified by using the
DATA_BACKUP_DESTandLOG_ARCHIVE_DESTparameters respectively. If the backup destination or archive destination is changed, the data in the original backup path or archive path cannot be cleared in the OceanBase Database.The automatic cleanup feature will retain at least one valid backup. If only one valid backup exists, this backup will not be cleared.
When the backup destination is an NFS mount point, the system will directly delete the backup files that meet the conditions during backup data cleanup. When the backup destination is an OSS bucket, the backup files will be cleared based on the value of the
delete_modeparameter specified fordata_backup_destorlog_archive_dest. For more information, see Prepare for backup.
Configure a cleanup policy
Configure a cleanup policy in the user tenant
The tenant administrator of the user tenant logs in to the database.
Configure 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. Only the valuedefaultis supported. This indicates that the automatic cleanup feature applies only to backup data specified by using thedata_backup_destandlog_archive_destparameters.The
RECOVERY_WINDOWparameter specifies the time window during which the backup data can be restored. For more information about this parameter, see recovery_window.
Here is an example:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';
Configure a cleanup policy in the sys tenant
Log in to the
systenant of the cluster as therootuser.Configure a cleanup policy to enable the automatic cleanup feature for the specified user 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. Only the valuedefaultis supported. This indicates that the automatic cleanup feature applies only to backup data specified by using thedata_backup_destandlog_archive_destparameters.The
RECOVERY_WINDOWparameter specifies the time window during which the backup data can be restored. For more information about this parameter, see recovery_window.The
TENANTparameter specifies the name of the tenant for which the cleanup policy takes effect. You must specify the name of a user tenant. You can specify only one tenant name in a statement.
Notice
You can configure a cleanup policy only at the tenant level. You cannot configure a cleanup policy at the cluster level. A statement can configure a cleanup policy for only one tenant.
The following example shows how to configure a cleanup policy for the MySQL tenant, which is the sys tenant:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT MySQL;
View the cleanup policies
Both system tenants and user tenants can query views to view all cleanup policies that are set.
Log in to the database as the tenant administrator of a system tenant or a user tenant.
View the cleanup policies set for the current tenant.
To view the cleanup policies of all tenants, query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview as a user of the system tenant.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 setTo view the cleanup policies set for the current tenant, query the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview or thesys.DBA_OB_BACKUP_DELETE_POLICYview as a user of a user 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