You can manually clear backup data as needed. OceanBase supports manual backup data clearing only at the cluster level. We recommend that you choose automatic clearing of the backup data in routine use.
You can execute the ALTER SYSTEM statement to clear backup data with the specified backup_set_id, backup_piece_id, and round_id, or clear expired data.
Considerations
Log archive data clearing depends on data backup. Therefore, before you clear the log archive data, make sure that a data backup file exists. If no data backup file exists, the log archive data cannot be cleared.
When you clear backup data from the Network File System (NFS), the system directly clears backup files that meet the requirements. When you clear backup data from the Object Storage Service (OSS), the backup file clearing mode is specified by the
delete_modeparameter inbackup_dest. For more information, see Preparations for backup.
Clear specified backup data
OceanBase Database allows you to clear backup data with the specified backup_set_id, backup_piece_id, and backup_round_id.
Log on to the
systenant as therootuser.Query the
CDB_OB_BACKUP_SET_FILES,CDB_OB_BACKUP_ARCHIVELOG_SUMMARY, andCDB_OB_BACKUP_PIECE_FILESviews to find thebackup_set_id,round_id, andbackup_piece_idcorresponding to the backup data to be cleared.Obtain the
backup_set_idof the backup dataSample statement for querying the
CDB_OB_BACKUP_SET_FILESview:obclient> SELECT * FROM oceanbase.CDB_OB_BACKUP_SET_FILES WHERE tenant_id=1 AND copy_id=0 AND file_status != 'DELETED'; +-------------+-----------+--------+---------+-------------+-----------------+---------+-------------+----------------------------+----------------------------+------------------+------+------------+------------+--------------+-------------------+-------------------+----------------------+---------------------------+--------------------+ | INCARNATION | TENANT_ID | BS_KEY | COPY_ID | BACKUP_TYPE | ENCRYPTION_MODE | STATUS | FILE_STATUS | START_TIME | COMPLETION_TIME | ELAPSED_SECONDES | KEEP | KEEP_UNTIL | COMPRESSED | OUTPUT_BYTES | OUTPUT_RATE_BYTES | COMPRESSION_RATIO | OUTPUT_BYTES_DISPLAY | OUTPUT_RATE_BYTES_DISPLAY | TIME_TAKEN_DISPLAY | +-------------+-----------+--------+---------+-------------+-----------------+---------+-------------+----------------------------+----------------------------+------------------+------+------------+------------+--------------+-------------------+-------------------+----------------------+---------------------------+--------------------+ | 1 | 1 | 3 | 0 | D | NONE | SUCCESS | AVAILABLE | 2022-10-28 11:19:56.883788 | 2022-10-28 11:19:59.629990 | 3 | NO | | NO | 3376538 | 1229530.0928 | 0.02 | 3.22MB | 1.17MB/S | 00:00:02.746202 | +-------------+-----------+--------+---------+-------------+-----------------+---------+-------------+----------------------------+----------------------------+------------------+------+------------+------------+--------------+-------------------+-------------------+----------------------+---------------------------+--------------------+ 1 row in setFields in query results are as follows:
BS_KEY: indicates the backup set ID of the data backup, which is alsobackup_set_id.COPY_ID: The value of theCOPY_IDfield is0for a data backup task.
For more information about the fields in the
CDB_OB_BACKUP_SET_FILESview, see oceanbase.CDB_OB_BACKUP_SET_FILES.Obtain the
round_idof the log backupobclient> SELECT * FROM oceanbase.CDB_OB_BACKUP_ARCHIVELOG_SUMMARY WHERE tenant_id=1; +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+ | INCARNATION | LOG_ARCHIVE_ROUND | TENANT_ID | STATUS | START_PIECE_ID | BACKUP_PIECE_ID | MIN_FIRST_TIME | MAX_NEXT_TIME | INPUT_BYTES | OUTPUT_BYTES | COMPRESSION_RATIO | INPUT_BYTES_DISPLAY | OUTPUT_BYTES_DISPLAY | +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+ | 1 | 1 | 1 | STOP | 0 | 0 | 2022-10-24 18:02:10.951125 | 2022-10-24 19:43:06.867056 | 0 | 0 | NULL | 0.00MB | 0.00MB | | 1 | 2 | 1 | DOING | 0 | 0 | 2022-10-24 19:43:27.652015 | 2022-10-24 19:46:39.949493 | 0 | 0 | NULL | 0.00MB | 0.00MB | +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+ 2 rows in setThe value in the
LOG_ARCHIVE_ROUNDcolumn is theround_idthat you require. Only a round in theSTOPstate can be cleared.For more information about the fields in the
CDB_OB_BACKUP__ARCHIVELOG_SUMMARYview, see oceanbase.CDB_OB_BACKUP_ARCHIVELOG_SUMMARY.Obtain the corresponding
backup_piece_idbased on theround_idof the log backupSample statement for querying the
oceanbase.CDB_OB_BACKUP_PIECE_FILESview:obclient> SELECT * FROM oceanbase.CDB_OB_BACKUP_PIECE_FILES WHERE tenant_id=1 AND round_id=1 and copy_id=0 AND status!='ACTIVE' AND file_status!='DELETED'; +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+ | INCARNATION | TENANT_ID | ROUND_ID | BACKUP_PIECE_ID | COPY_ID | CREATE_DATE | START_TS | CHECKPOINT_TS | MAX_TS | STATUS | FILE_STATUS | COMPATIBLE | START_PIECE_ID | +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+ | 1 | 1 | 1 | 0 | 0 | 20221028 | 2022-10-28 10:58:38.325595 | 2022-10-28 14:50:29.834598 | 2022-10-28 14:50:39.280049 | FROZEN | AVAILABLE | 1 | 0 | +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+ 1 row in setFields in query results are as follows:
ROUND_ID: indicates theround_idof the log backup, if the round-based backup is enabled.BACKUP_PIECE_ID: indicates the piece ID of the log backup. If log splitting is enabled,backup_piece_id> 0. If log splitting is disabled,backup_piece_id= 0.COPY_ID: The value of theCOPY_IDfield is0for a log backup task. This view contains information about the backup and secondary backup tasks.
For more information about the fields in the
CDB_OB_BACKUP_PIECE_FILESview, see oceanbase.CDB_OB_BACKUP_PIECE_FILES.
Execute the statement as needed to clear the backup data.
Clear a backup set with the specified backup set ID (
backup_set_id).obclient> ALTER SYSTEM DELETE BACKUPSET backup_set_id;For example, you can execute the following statement to clear the backup set whose backup set ID is
1:obclient> ALTER SYSTEM DELETE BACKUPSET 1;When you execute the
DELETE BACKUPSETstatement to clear backup sets, the following limitations apply:When you clear backup sets of the specified backup set IDs, if the destinations of the backup sets are the same as the destination specified for
backup_dest, at least one complete and valid backup copy is retained. If their destinations are different from the specified destination, all data is cleared.When you clear backup sets based on the specified backup set IDs, if the destinations of the backup sets are the same as the destination specified for
backup_dest, you must clear the backup sets based on the order of their backup set IDs. For example, when you clear three backup sets whose backup set IDs are1,2, and3, you must clear the backup sets in the order of1,2, and3. If their destinations are different from the specified destination, you can clear the backup sets without following the preceding order.The operation fails if a specified backup set ID does not exist or a backup task with a specified backup set ID is still in progress.
Clear all data in a log backup round with the specified
round_id.obclient> ALTER SYSTEM DELETE BACKUPROUND round_id;The limitations on the
DELETE BACKUPPIECEcommand also apply to theDELETE BACKUPROUNDcommand:You can only delete backup rounds in the
STOPstate.When you clear backup data of the specified round IDs, if the destinations of the backup rounds are the same as the destination specified for
backup_destand the existing data does not fully cover the backup rounds, you cannot clear backup data of the corresponding round IDs. If their destinations are different from the specified destination, you can clear the backup data of the specified round IDs regardless of whether the existing backup data fully covers the backup rounds.When you clear backup data of the specified round IDs, if the destinations of the backup rounds are the same as the destination specified for
backup_dest, you must clear the backup data based on the order of the backup round IDs to avoid log discontinuity. For example, when you clear backup data whose round IDs are1,2, and3, you must clear the backup data in the order of1,2, and3. If their destinations are different from the specified destination, you can clear the backup data of the specified round IDs without following the preceding order.
Clear archive data of the specified backup piece IDs.
obclient> ALTER SYSTEM DELETE BACKUPPIECE backup_piece_id;When you run the
DELETE BACKUPPIECEcommand to clear backup pieces, the following limitations apply:You can run this command to clear specified pieces only when log splitting is enabled for log backup.
For more information about how to enable log splitting for log backup, see Enable backup based on log splitting.
You can clear only backup pieces that are in the Frozen or Inactive state.
When you clear backup pieces of the specified piece IDs, if the destinations of the backup pieces are the same as the destination specified for
backup_destand the existing backup data does not fully cover the backup pieces, you cannot clear the backup pieces of the corresponding piece IDs. If their destinations are different from the specified destination, you can clear the backup pieces of the specified piece IDs regardless of whether the existing backup data fully covers the backup pieces.When you clear backup pieces of the specified piece IDs, if the destinations of the backup pieces are the same as the destination specified for
backup_dest, you must clear the backup pieces based on the order of the backup piece IDs to avoid log discontinuity. For example, when you clear backup pieces whose piece IDs are1,2, and3, you must clear the backup pieces in the order of1,2, and3. If their destinations are different from the specified destination, you can clear the backup pieces of the specified piece IDs without following the preceding order.
Clear expired backup data
Preparations
Before you manually clear expired backup data, configure the clearing strategy for the backup data. That is, set the recovery_window parameter in backup_dest_option or set the backup_recovery_window parameter.
The recovery_window parameter specifies the time window for restoring backup data. The system determines whether backup data has expired based on the value of this parameter.
All backup data earlier than the latest backup data that meets the following condition is considered expired: current time - backup point in time >= recovery_window.
For example, the setting recovery_window='7d' indicates that the data backed up within the last 7 days must be restorable, and the backup data beyond this restore window is considered expired.
The backup_recovery_window parameter in this statement is equivalent to the recovery_window parameter in backup_dest_option. For more information about the recovery_window parameter, see Automatically clear backup data for clusters.
For more information about the backup_dest_option parameter, see backup_dest_option.
Manually clear expired backup data
Log on to the
systenant as therootuser.Execute the following statement to clear expired backup data:
obclient> ALTER SYSTEM DELETE OBSOLETE BACKUP;Note the following limitations for using the
DELETE OBSOLETEcommand:If no or only one valid
backup setexists, you cannot clear the backup pieces of the log archive data.The
DELETE OBSOLETEcommand only clears expired backup data whose storage path is the same as the destination specified forbackup_dest. For more information about expired backup data whose destination is changed, see Clear specified backup data in this topic.The
DELETE OBSOLETEcommand can clear secondary backup data corresponding to the backup_dest parameter.The operation fails if the number of existing
backup copiesis less than the value specified for thebackup_copiesparameter forbackup_dest_option.
What to do next
You can also configure the automatic clearing of backup data. For more information, see Automatically clear backup data for clusters.
OceanBase Database allows you to stop backup data clearing. For more information, see Stop backup data clearing for clusters.