You can set a backup cleanup strategy for a tenant as needed. After you set a cleanup strategy for a tenant, automatic cleanup will be triggered for the tenant every hour so that expired backup data can be promptly cleaned up.
Considerations
The cleanup of the archive log data depends on data backup. Before you clean up archive log data, confirm that a data backup file exists. If no data backup file exists, the archived log data cannot be cleaned up.
Automatic cleanup applies only to the data at the backup destinations specified by
data_backup_destandlog_archive_dest. If the backup destination changes, the expired backup data cannot be cleaned up in OceanBase Database.At least one copy of valid backup data is retained after automatic cleanup. If only one copy of valid backup data exists, this data copy will never be cleaned up.
When you clean up backup data from Network File System (NFS), the system directly deletes backup files that meet the requirements. When you clean up backup data from Object Storage Service (OSS), the backup file cleanup mode is specified by the
delete_modeparameter indata_backup_destandlog_archive_dest. For more information, see Preparations.
Set a cleanup strategy
Set a cleanup strategy for a user tenant
Log on to the database as an administrator of a user tenant.
Set a cleanup strategy. This is equivalent to enabling automatic cleanup for the tenant.
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window;The
POLICYparameter specifies the name of the cleanup strategy. It can be set todefaultonly, which indicates that automatic cleanup applies only to the data in the backup destinations specified bydata_backup_destandlog_archive_dest.The
RECOVERY_WINDOWparameter specifies the time window for restoring backup data. For more information about this parameter, see About the recovery_window parameter.
Here is an example:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d';
Set a cleanup strategy in the sys tenant
Log on to the
systenant of the cluster as therootuser.Set a cleanup strategy. This is equivalent to enabling automatic cleanup for the tenant.
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY policy_name RECOVERY_WINDOW recovery_window TENANT tenant_name;The
POLICYparameter specifies the name of the cleanup strategy. It can be set todefaultonly, which indicates that automatic cleanup applies only to the data in the backup destinations specified bydata_backup_destandlog_archive_dest.The
RECOVERY_WINDOWparameter specifies the time window for restoring backup data. For more information about this parameter, see About the recovery_window parameter.The
TENANTparameter specifies the tenant on which the cleanup strategy takes effect. You can specify the name of only one user tenant.
Notice
At present, you can set only tenant-level cleanup strategies but not cluster-level cleanup strategies. Each statement sets one cleanup strategy for only one tenant.
To set a cleanup strategy for the MySQL tenant from the sys tenant, execute the following statement:
obclient> ALTER SYSTEM ADD DELETE BACKUP POLICY 'default' RECOVERY_WINDOW '7d' TENANT MySQL;
Query configured cleanup strategies
You can query views for the configured cleanup strategies of all tenants from the sys tenant or for the configured cleanup strategies of a user tenant.
Log on to the database as an administrator of the sys tenant or a user tenant.
Query the configured cleanup strategies.
Query the
oceanbase.CDB_OB_BACKUP_DELETE_POLICYview for the cleanup strategies of all tenants from the sys tenant.For 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_POLICYorsys.DBA_OB_BACKUP_DELETE_POLICYview for the cleanup strategies of the current user 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