从 OceanBase 数据库 V2.2.77 版本开始,日志备份提供了基于 Piece 的按指定时间段切换目录的功能,即日志分片功能。开启日志分片功能后,管理员可以在备份备份时选择按照分片的日志备份来复制数据。

操作步骤

  1. 使用 sys 租户的 root 用户登录数据库。

  2. 通过指定 backup_dest_option 中的 log_archive_piece_switch_interval 参数值来开启日志分片的备份功能。

    示例如下:

    1. obclient> ALTER SYSTEM SET backup_dest_option='recovery_window=7d&auto_delete_obsolete_backup=true&backup_copies=2&log_archive_piece_switch_interval=1d';

    该示例中,日志备份会每天切分一个日志 Piece,保留 7 天。backup_copies2 表示在执行备份备份后才会回收原备份。 更多 backup_dest_option 配置项的说明信息请参见 backup_dest_option

    开启日志分片的备份功能后,可以通过视图来查看日志备份的进度及日志分片的情况。

    • 查看日志进度

      1. obclient> SELECT * FROM CDB_OB_BACKUP_ARCHIVELOG;
      2. +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+
      3. | 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 |
      4. +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+
      5. | 1 | 1 | 1 | DOING | 1 | 12 | 2021-04-30 00:00:28.197301 | 2021-04-30 11:33:41.845543 | 0 | 0 | NULL | 0.00MB | 0.00MB |
      6. | 1 | 1 | 1001 | DOING | 1 | 12 | 2021-04-30 00:00:28.197301 | 2021-04-30 11:33:58.444979 | 0 | 0 | NULL | 0.00MB | 0.00MB |
      7. | 1 | 1 | 1002 | DOING | 1 | 12 | 2021-04-30 00:00:28.197301 | 2021-04-30 11:33:41.845543 | 0 | 0 | NULL | 0.00MB | 0.00MB |
      8. +-------------+-------------------+-----------+--------+----------------+-----------------+----------------------------+----------------------------+-------------+--------------+-------------------+---------------------+----------------------+
      9. 3 rows in set (0.07 sec)
    • 查看日志分片情况

      1. obclient> SELECT * FROM CDB_OB_BACKUP_PIECE_FILES ;
      2. +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+
      3. | 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 |
      4. +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+
      5. | 1 | 1 | 1 | 1 | 0 | 20210430 | 2021-04-30 00:00:28.197301 | 2021-04-30 00:59:49.402568 | 2021-04-30 01:02:32.336195 | FROZEN | AVAILABLE | 1 | 1 |
      6. | 1 | 1 | 1 | 2 | 0 | 20210430 | 2021-04-30 01:02:32.336195 | 2021-04-30 02:01:38.260158 | 2021-04-30 02:04:10.990039 | ACTIVE | AVAILABLE | 1 | 1 |
      7. | 1 | 1001 | 1 | 1 | 0 | 20210430 | 2021-04-30 00:00:28.197301 | 2021-04-30 01:00:00.733364 | 2021-04-30 01:02:32.166782 | FROZEN | AVAILABLE | 1 | 1 |
      8. | 1 | 1001 | 1 | 2 | 0 | 20210430 | 2021-04-30 01:02:32.166782 | 2021-04-30 02:01:38.260158 | 2021-04-30 02:04:09.731651 | ACTIVE | AVAILABLE | 1 | 1 |
      9. +-------------+-----------+----------+-----------------+---------+-------------+----------------------------+----------------------------+----------------------------+--------+-------------+------------+----------------+