当前位置: 首页 > 工具软件 > CRIU > 使用案例 >

Docker热迁移工具CRIU原理系列:images

淳于泓
2023-12-01

  criu 备份进程或者容器后,会生成一系列的镜像文件。这些镜像会被用来进程或者容器在任何其他同体系架构主机上的恢复。本文将描述这些镜像文件的格式、功能。

1、镜像文件的类型

  criu镜像文件采用google RPC格式,即ProtoBuf 格式。ProtoBuf是和JSON、XML 一样,用作序列化/反序列化结构数据的方法。 ProtoBuf语言中对criu各功能条目的描述位于criu 源码的images/目录中的相应.proto文件中。

2、备份后生成的镜像文件

  下表列举了criu备份进程或者容器后,可能生成的镜像文件。

名称描述
inventory.imgcriu备份后对所有镜像文件的概括性描述,比如protobuf版本
core-tid.img保存了备份程序中主线程和所有线程的核心信息(比如name、sigmask、itimers等)和 体系架构相关的信息(比如gpregs、fpregs等)。其中tid代表的是线程号
fdinfo.img保存了备份进程打开的文件描述符
pstree.img进程程序树信息。criu restore 时可以使用–restore-detached参数分离进程
eventfd.imgEvendfd 文件信息
mm-pid.img保存了备份程序中主进程和所有子进程的地址空间信息,比如VMAs、segments等。
tty.img保存进程打开的dev/ttys的相关信息
netdev.img保存网络设备的相关信息
inetsk.imgPF_INET sockets, 包括 IPv4 和 IPv6
ids.img保存所有对象和命名空间的ID号
pipe.img保存Pipe信息
fifo.img保存fifo信息
creds.img保存进程信任状g相关信息,比如uids、gids、caps等
fs.img保存了chroot和chdir信息
tcp-stream.img保存tcp链接状态信息
sigacts.img如果进程使用了信号处理相关函数,此镜像保存相关信息

3、镜像工具CRIT

  .img文件的文件是二进制格式,不能用普通文本打开查看。CRIT(CRiu Image Tool)工具可以帮助我们把上面那些.img文件翻译成人类可读的格式。CRIT是用平台无关的python语言编写,源码和工具位于criu源码的crit目录下。用法如下:

usage: crit [-h] {decode,encode,info,x,show} ...

CRiu Image Tool

positional arguments:
  {decode,encode,info,x,show}
                        Use crit CMD --help for command-specific help
    decode              convert criu image from binary type to json
    encode              convert criu image from json type to binary
    info                show info about image
    x                   explore image dir
    show                convert criu image from binary to human-readable json

optional arguments:
  -h, --help            show this help message and exit

比如我们查看inventory.img里面的内容,可以使用命令:

$ crit show inventory.img

如果要把inventory.img转换成json格式,可以使用命令:

$ crit decode -i inventory.img -o inventory.json

-i代表 input 。“-o”代表out。生成的inventory.json可以使用linux工具jq查看,比如:

$ cat inventory.json | jq .
 类似资料: