After a backup is successfully created, you can set a cleanup policy for a tenant based on your business needs. Tenants with a cleanup policy will trigger an automatic cleanup operation 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 clearing 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 destination and log archive destination specified in
DATA_BACKUP_DESTandLOG_ARCHIVE_DEST, respectively. In scenarios where the backup or archive destination has been changed, data in the original backup or archive path cannot be cleared by using OceanBase Database.The automatic cleanup feature retains at least one valid backup copy. If only one valid backup copy exists, this copy will not be cleared.
When the backup destination is an NFS mount point or an object storage service that supports the S3 protocol (such as OBS and GCS), the system directly deletes the eligible backup files. When the backup destination is an object storage service that supports the OSS, COS, or S3 protocol, the files are cleared based on the value of the
delete_modeparameter specified fordata_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 statement:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;where:
The
POLICYparameter specifies the name of the cleanup policy. Currently, you can set this parameter to onlydefault, which indicates that backup data of only the currentdata_backup_destandlog_archive_destparameters will be cleared.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 tenant.
Use the following statement:
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. Currently, you can set this parameter to onlydefault, which indicates that backup data of only the currentdata_backup_destandlog_archive_destparameters will be cleared.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 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
At present, only tenant-level cleanup policies can be set, and cluster-level cleanup policies cannot be set. Each statement can set only one cleanup policy for one tenant.
The following example shows how to set a cleanup policy for the MySQL tenant in the sys tenant:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT MySQL;
View the cleanup strategies that have been configured
Both the system tenant and user tenants can query views to obtain all cleanup strategies that have been configured.
Log in to the database as the tenant administrator of the system tenant or a user tenant.
View the cleanup strategies that have been configured for the tenant.
Query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview for all cleanup strategies for tenants in 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 setQuery the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview orsys.DBA_OB_BACKUP_DELETE_POLICYview for the cleanup strategies that have been configured for 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