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 the automatic cleanup of expired backups and does not support manual cleanup of expired backups.
Considerations
Log archive data can be cleared only after data backups are 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. 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, this copy will not be cleared.
When the backup destination is an NFS mount point, the system directly deletes the specified backup files. When the backup destination is an OSS or COS mount point, the backup files are cleared based on the value of the
delete_modeparameter specified indata_backup_destandlog_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
POLICYparameter specifies the name of the cleanup policy. You can set this parameter to onlydefault, which specifies to clean up only the data 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 specifies to clean up only the data 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 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 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.
Query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview for all cleanup strategies that have been set for tenants in the system tenant.Here is the sample code:
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 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