After a backup is successfully created, you can set a cleanup policy for the tenant based on your business needs. Tenants 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 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 destinations and log archive destinations specified in
DATA_BACKUP_DESTandLOG_ARCHIVE_DEST. In the case where the backup or log archive destination is changed, data in the original backup or log archive destination 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, the system directly deletes the eligible backup files. When the backup destination is an OSS bucket, the files are cleared based on the value of the
delete_modeparameter specified fordata_backup_destorlog_archive_dest. For more information, see 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:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;where:
The
POLICYparameter specifies the name of the cleanup policy. You can set this parameter to onlydefault, which indicates that backup data is retained only in the locations specified in 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';
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:
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. You can set this parameter to onlydefault, which indicates that backup data is retained only in the locations specified in 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 tenant for which the cleanup policy takes effect. You can specify only one tenant name, which is the name of a user tenant.
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 a 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 set
Both the system tenant and user tenants can query views to obtain all cleanup strategies that have been set.
Log in to the database as the tenant administrator of the system tenant or a user tenant.
View the cleanup strategies that have been set for the tenant.
The system tenant can query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview for cleanup strategies 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 setUser tenants can query the
oceanbase.DBA_OB_BACKUP_DELETE_POLICYview or thesys.DBA_OB_BACKUP_DELETE_POLICYview for cleanup strategies 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