After a backup is successfully created, you can set a cleanup policy for a tenant based on your business needs. A tenant with a cleanup policy will trigger an automatic cleanup process every hour to ensure that expired backups are promptly removed.
The current version supports only automatic cleanup of expired backups and does not support manual cleanup of expired backups.
Considerations
Log archive data can be cleared only after data backup is performed. Therefore, before you clear log archive data, you must make sure that data backup files exist. If no data backup files exist, the log archive data cannot be cleared.
The automatic cleanup feature applies only to the backup destinations and log archive destinations specified in
DATA_BACKUP_DESTandLOG_ARCHIVE_DEST, respectively. In scenarios where the backup or log archive destination has been changed, data in the original backup or log archive path cannot be cleared by OceanBase Database.The automatic cleanup feature retains at least one valid backup copy. If only one valid backup copy exists, it will not be cleared.
When the backup destination is an NFS mount point, the system directly deletes the backup files that meet the conditions. When the backup destination is an OSS, COS, or S3 bucket, the files that meet the conditions are cleared based on the value of the
delete_modeparameter specified indata_backup_destorlog_archive_dest. For more information, see Prepare for log archive and Prepare for data backup.
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.
Use the following syntax to set a cleanup policy:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;where:
The value of the
POLICYparameter is the name of the cleanup policy. Currently, you can specify only thedefaultpolicy, which specifies to clean up only the backup data specified in thedata_backup_destandlog_archive_destparameters.The value of 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';
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 specified user tenant.
Use the following syntax to set a cleanup policy:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window TENANT tenant_name;where:
The value of the
POLICYparameter is the name of the cleanup policy. Currently, you can specify only thedefaultpolicy, which specifies to clean up only the backup data specified in thedata_backup_destandlog_archive_destparameters.The value of 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 value of the
TENANTparameter is the name of the user tenant for which the cleanup policy takes effect.
Notice
At present, only tenant-level cleanup policies can be set, and cluster-level cleanup policies cannot be set. Each command can set only one cleanup policy for one tenant.
The following example shows how to set a cleanup policy for a MySQL tenant in the sys tenant:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT MySQL;
View the cleanup policies
The system tenant administrator and user tenant administrator can query views to obtain all cleanup policies configured.
Log in to the database as the system tenant administrator or a user tenant administrator.
View the cleanup policies configured for the current tenant.
The system tenant administrator can query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview for cleanup policies of 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 setThe user tenant administrator can query the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview or thesys.DBA_OB_BACKUP_DELETE_POLICYview for the cleanup policies of the current tenant.MySQL tenant
obclient [(none)]> SELECT * FROM oceanbase.DBA_OB_BACKUP_DELETE_POLICY; +-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in setOracle tenant
obclient [SYS]> SELECT * FROM sys.DBA_OB_BACKUP_DELETE_POLICY; +-------------+-----------------+ | POLICY_NAME | RECOVERY_WINDOW | +-------------+-----------------+ | default | 7d | +-------------+-----------------+ 1 row in set