导入(Import)和导出(Export)操作是管理和迁移 RBD 镜像数据的关键手段
作用:
1.使用实际数据量测试新版本
2.使用实际的数据量运行质量保证流程
3.实现业务连续性场景
4.从生产块设备解耦备份进程
导入导出操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| 参数 作用 --export-format 指定导出格式(1 或 2,默认 2) --image-format 导入时指定 RBD 格式(必须匹配) --compress-algorithm 压缩算法(如 lz4, zstd) --object-size 导入时指定对象大小(如 4M, 8M) --stripe-unit 条带化单元大小(优化性能)
rbd export <pool>/<image-name> <output-file>
rbd export <pool>/<image-name>@<snapshot-name> <output-file>
rbd import <input-file> <pool>/<new-image-name>
rbd import --image-format 2 <input-file> <pool>/<new-image>
|
导入导出镜像(快照)更改
和增量备份差不多
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| 带快照的情况下: 初始全备 (T0) rbd snap create myvol@snap_base rbd export myvol@snap_base full.bin full.bin是只读的,不会修改
第一次增量 (T1) rbd snap create myvol@snap1 rbd export-diff myvol@snap1 --from-snap snap_base inc1.bin
使用snap1与snap_base进行对比,增量出一个新文件inc1.bin
第二次增量 (T2) rbd snap create myvol@snap2 rbd export-diff myvol@snap2 --from-snap snap1 inc2.bin
使用snap2与snap1进行对比,增量出一个新文件inc2.bin
恢复流程 rbd import full.bin newvol rbd snap create newvol@snap_base rbd import-diff inc1.bin newvol rbd import-diff inc2.bin newvol
|
使用管道
1 2 3 4 5
| rbd export rbd/img1 - | rbd import - rbd/img2
将rbd/img1导出,并导入到rbd/img2,相当于复制了一份 避免了创建临时镜像文件(如 export-file.bin) 整个操作是单条命令,要么完全成功要么失败
|