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 deleted in a timely manner.
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, respectively. In scenarios where the backup or log archive destination has been changed, data in the original backup or log archive destination cannot be cleared by 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 you clear the backup data. When the backup destination is an object storage service accessed through the S3 protocol (OSS, S3, or COS), the files to be cleared depend on the value of the
delete_modeparameter specified fordata_backup_destorlog_archive_dest. For more information, see Prepare for log archiving 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:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;where:
The value of the
POLICYparameter specifies the name of the cleanup policy. You can set this parameter to onlydefault, which specifies to clean up only the backups configured indata_backup_destandlog_archive_dest.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.
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 value of the
POLICYparameter specifies the name of the cleanup policy. You can set this parameter to onlydefault, which specifies to clean up only the backups configured indata_backup_destandlog_archive_dest.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 specifies 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 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.
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 set 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