在Linux中创建检查点并还原的工具——criu

news2024/10/3 16:22:06

相信很多用过Unix系统的人都不会对 ctrl+z 的 job 挂起不会陌生,然而这个功能却只能在用户空间中,而不能在磁盘上持久化就感觉对PC用户不是非常完美。而最近我发现一个叫criu的工具通过kernel直接镜像进程的cpu和内存状态存储的本地磁盘。

安装

这里我建议Ubuntu 22.04以下的直接用make

# apt install libbsd-dev libdrm-dev gnutls-dev libnftables-dev
# apt install libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python3-protobuf
# apt-get install libnet1-dev
# apt-get install libcap-dev
# wget https://bootstrap.pypa.io/get-pip.py
# /usr/bin/python3 get-pip.py

# git clone https://github.com/checkpoint-restore/criu.git
# cd criu
# make install

其他用包安装就可以了,注意要在3.17版本以上,否则会有问题。
WSL 亦可以使用

使用

保存检查点

sudo criu dump -t <PID> -v4 -o dump.log -D <image_dir> --shell-job

还原

sudo criu restore --shell-job -D <image_dir> -v2 -o restore.log

我用clamav的clamscan进程测试过可以暂停和恢复

详细

$ criu -h

Usage:
  criu dump|pre-dump -t PID [<options>]
  criu restore [<options>]
  criu check [--feature FEAT]
  criu page-server
  criu service [<options>]
  criu dedup
  criu lazy-pages -D DIR [<options>]

Commands:
  dump           checkpoint a process/tree identified by pid
  pre-dump       pre-dump task(s) minimizing their frozen time
  restore        restore a process/tree
  check          checks whether the kernel support is up-to-date
  page-server    launch page server
  service        launch service
  dedup          remove duplicates in memory dump
  cpuinfo dump   writes cpu information into image file
  cpuinfo check  validates cpu information read from image file

Most of the true / false long options (the ones without arguments) can be
prefixed with --no- to negate the option (example: --display-stats and
--no-display-stats).

Dump/Restore options:

* Generic:
  -t|--tree PID         checkpoint a process tree identified by PID
  -d|--restore-detached detach after restore
  -S|--restore-sibling  restore root task as sibling
  -s|--leave-stopped    leave tasks in stopped state after checkpoint
  -R|--leave-running    leave tasks in running state after checkpoint
  -D|--images-dir DIR   directory for image files
     --pidfile FILE     write root task, service or page-server pid to FILE
  -W|--work-dir DIR     directory to cd and write logs/pidfiles/stats to
                        (if not specified, value of --images-dir is used)
     --cpu-cap [CAP]    CPU capabilities to write/check. CAP is comma-separated
                        list of: cpu, fpu, all, ins, none. To disable
                        a capability, use ^CAP. Empty argument implies all
     --exec-cmd         execute the command specified after '--' on successful
                        restore making it the parent of the restored process
  --freeze-cgroup       use cgroup freezer to collect processes
  --weak-sysctls        skip restoring sysctls that are not available
  --lazy-pages          restore pages on demand
                        this requires running a second instance of criu
                        in lazy-pages mode: 'criu lazy-pages -D DIR'
                        --lazy-pages and lazy-pages mode require userfaultfd
  --stream              dump/restore images using criu-image-streamer
  --mntns-compat-mode   Use mount engine in compatibility mode. By default criu
                        tries to use mount-v2 mode with more reliable algorithm
                        based on MOVE_MOUNT_SET_GROUP kernel feature
  --network-lock METHOD network locking/unlocking method; argument
                        can be 'nftables' or 'iptables' (default).
  --unprivileged        accept limitations when running as non-root
                        consult documentation for further details

* External resources support:
  --external RES        dump objects from this list as external resources:
                        Formats of RES on dump:
                            tty[rdev:dev]
                            file[mnt_id:inode]
                            dev[major/minor]:NAME
                            unix[ino]
                            mnt[MOUNTPOINT]:COOKIE
                            mnt[]{:AUTO_OPTIONS}
                        Formats of RES on restore:
                            dev[NAME]:DEVPATH
                            veth[IFNAME]:OUTNAME{@BRIDGE}
                            macvlan[IFNAME]:OUTNAME
                            mnt[COOKIE]:ROOT
                            netdev[IFNAME]:ORIGNAME

* Special resources support:
     --tcp-established  checkpoint/restore established TCP connections
     --skip-in-flight   skip (ignore) in-flight TCP connections
     --tcp-close        don't dump the state of, or block, established tcp
                        connections, and restore them in closed state.
  -r|--root PATH        change the root filesystem (when run in mount namespace)
  --evasive-devices     use any path to a device file if the original one
                        is inaccessible
  --link-remap          allow one to link unlinked files back when possible
  --ghost-limit size    limit max size of deleted file contents inside image
  --ghost-fiemap        enable dumping of deleted files using fiemap
  --action-script FILE  add an external action script
  -j|--shell-job        allow one to dump and restore shell jobs
  -l|--file-locks       handle file locks, for safety, only used for container
  -L|--libdir           path to a plugin directory (by default /usr/lib/criu/)
  --timeout NUM         a timeout (in seconds) on collecting tasks during dump
                        (default 10 seconds)
  --force-irmap         force resolving names for inotify/fsnotify watches
  --irmap-scan-path FILE
                        add a path the irmap hints to scan
  --manage-cgroups [m]  dump/restore process' cgroups; argument can be one of
                        'none', 'props', 'soft' (default), 'full', 'strict'
                        or 'ignore'
  --cgroup-root [controller:]/newroot
                        on dump: change the root for the controller that will
                        be dumped. By default, only the paths with tasks in
                        them and below will be dumped.
                        on restore: change the root cgroup the controller will
                        be installed into. No controller means that root is the
                        default for all controllers not specified
  --cgroup-props STRING
                        define cgroup controllers and properties
                        to be checkpointed, which are described
                        via STRING using simplified YAML format
  --cgroup-props-file FILE
                        same as --cgroup-props, but taking description
                        from the path specified
  --cgroup-dump-controller NAME
                        define cgroup controller to be dumped
                        and skip anything else present in system
  --cgroup-yard PATH
                        instead of trying to mount cgroups in CRIU, provide
                        a path to a directory with already created cgroup yard.
                        Useful if you don't want to grant CAP_SYS_ADMIN to CRIU
  --lsm-profile TYPE:NAME
                        Specify an LSM profile to be used during restore.
                        The type can be either 'apparmor' or 'selinux'.
  --lsm-mount-context CTX
                        Specify a mount context to be used during restore.
                        Only mounts with an existing context will have their
                        mount context replaced with CTX.
  --skip-mnt PATH       ignore this mountpoint when dumping the mount namespace
  --enable-fs FSNAMES   a comma separated list of filesystem names or "all"
                        force criu to (try to) dump/restore these filesystem's
                        mountpoints even if fs is not supported
  --inherit-fd fd[NUM]:RES
                        Inherit file descriptors, treating fd NUM as being
                        already opened via an existing RES, which can be:
                            tty[rdev:dev]
                            pipe[inode]
                            socket[inode]
                            file[mnt_id:inode]
                            /memfd:name
                            path/to/file
  --empty-ns net        Create a namespace, but don't restore its properties
                        (assuming it will be restored by action scripts)
  -J|--join-ns NS:{PID|NS_FILE}[,OPTIONS]
                        Join existing namespace and restore process in it.
                        Namespace can be specified as either pid or file path.
                        OPTIONS can be used to specify parameters for userns:
                            user:PID,UID,GID
  --file-validation METHOD
                        pass the validation method to be used; argument
                        can be 'filesize' or 'buildid' (default).
  --skip-file-rwx-check
                        Skip checking file permissions
                        (r/w/x for u/g/o) on restore.

Check options:
  Without options, "criu check" checks availability of absolutely required
  kernel features, critical for performing dump and restore.
  --extra               add check for extra kernel features
  --experimental        add check for experimental kernel features
  --all                 same as --extra --experimental
  --feature FEAT        only check a particular feature, one of:
                            mnt_id, mem_dirty_track, aio_remap, timerfd, tun,
                            tun_ns, userns, fdinfo_lock, seccomp_suspend,
                            seccomp_filters, loginuid, cgroupns, autofs,
                            tcp_half_closed, compat_cr, uffd, uffd-noncoop,
                            can_map_vdso, sk_ns, sk_unix_file, net_diag_raw,
                            nsid, link_nsid, kcmp_epoll, timens,
                            external_net_ns, clone3_set_tid, newifindex,
                            nftables, has_ipt_legacy, pidfd_store, ns_pid,
                            apparmor_stacking, network_lock_nftables,
                            sockopt_buf_lock, memfd_hugetlb,
                            move_mount_set_group, openat2, get_rseq_conf,
                            ipv6_freebind, pagemap_scan, overlayfs_maps

* Logging:
  -o|--log-file FILE    log file name
     --log-pid          enable per-process logging to separate FILE.pid files
  -v[v...]|--verbosity  increase verbosity (can use multiple v)
  -vNUM|--verbosity=NUM set verbosity to NUM (higher level means more output):
                          -v1 - only errors and messages
                          -v2 - also warnings (default level)
                          -v3 - also information messages and timestamps
                          -v4 - lots of debug
  --display-stats       print out dump/restore stats

* Memory dumping options:
  --track-mem           turn on memory changes tracker in kernel
  --prev-images-dir DIR path to images from previous dump (relative to -D)
  --page-server         send pages to page server (see options below as well)
  --auto-dedup          when used on dump it will deduplicate "old" data in
                        pages images of previous dump
                        when used on restore, as soon as page is restored, it
                        will be punched from the image
  --pre-dump-mode       splice - parasite based pre-dumping (default)
                        read   - process_vm_readv syscall based pre-dumping

Page/Service server options:
  --address ADDR        address of server or service
  --port PORT           port of page server
  --ps-socket FD        use specified FD as page server socket
  -d|--daemon           run in the background after creating socket
  --status-fd FD        write \0 to the FD and close it once process is ready
                        to handle requests
  --tls-cacert FILE     trust certificates signed only by this CA
  --tls-cacrl FILE      path to CA certificate revocation list file
  --tls-cert FILE       path to TLS certificate file
  --tls-key FILE        path to TLS private key file
  --tls                 use TLS to secure remote connection
  --tls-no-cn-verify    do not verify common name in server certificate

Configuration file options:
  --config FILEPATH     pass a specific configuration file
  --no-default-config   forbid usage of default configuration files

Other options:
  -h|--help             show this text
  -V|--version          show version

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2186520.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

算法与数据结构--二分查找

原理 简单说就是每次二分取中间值&#xff0c;然后将中间值与我们要找的值比较&#xff0c;如果比它大就移动左边界到其右侧&#xff0c;如果比它小就移动右边界到其左侧。直到中间值等于该值或者经过移动直至右边界在左边界左侧为止。 二.具体实现 public int searchInsert(…

数据结构 ——— 单链表oj题:反转链表

目录 题目要求 手搓一个简易链表 代码实现 题目要求 给你单链表的头节点 head &#xff0c;请你反转链表&#xff0c;并返回反转后的链表 手搓一个简易链表 代码演示&#xff1a; struct ListNode* n1 (struct ListNode*)malloc(sizeof(struct ListNode)); assert(n1);…

【重学 MySQL】五十三、MySQL数据类型概述和字符集设置

【重学 MySQL】五十三、MySQL数据类型概述和字符集设置 MySQL数据类型概述MySQL字符集设置注意事项 MySQL数据类型概述 MySQL是一个流行的关系型数据库管理系统&#xff0c;它支持多种数据类型&#xff0c;以满足不同数据处理和存储的需求。理解并正确使用这些数据类型对于提高…

已解决:org.springframework.web.HttpMediaTypeNotAcceptableException

文章目录 写在前面问题描述报错原因分析&#xff1a; 解决思路解决办法1. 确保客户端请求的 Accept 头正确2. 修改 Controller 方法的 produces 参数3. 配置合适的消息转换器4. 检查 Spring 配置中的媒体类型5. 其他解决方案 总结 写在前面 在开发过程中&#xff0c;Spring 框…

实验1 集成开发环境的使用及程序设计入门

1、求两点之间的距离 【问题描述】从键盘输入平面上已知两点的坐标A(x1,y1)、B(x2,y2)&#xff0c;计算两点之间的距离。结果保留4位小数。 【输入形式】两个点的坐标 【输出形式】两点之间的距离 【样例输入】 0 0 3 4 【样例输出】 5.0000 #define _CRT_SECURE_NO_WARNI…

(C语言贪吃蛇)12.Linux线程概念引入及编程实现

目录 前言 Linux线程概念 解决方法 注意事项⚠️ 解决问题&#x1f525; 总结 前言 我们上节提出了两个死循环不能同时运行&#xff0c;导致我们无法控制贪吃蛇的运动方向&#xff0c;本节我们便来解决这个问题。 Linux线程概念 线程是一个进程内部的控制序列&#xff0c…

鸿蒙应用开发前置学习-TypeScript

注意&#xff1a;博主有个鸿蒙专栏&#xff0c;里面从上到下有关于鸿蒙next的教学文档&#xff0c;大家感兴趣可以学习下 如果大家觉得博主文章写的好的话&#xff0c;可以点下关注&#xff0c;博主会一直更新鸿蒙next相关知识 专栏地址: https://blog.csdn.net/qq_56760790/…

杭州电子科技大学《2019年+2023年861自动控制原理真题》 (完整版)

本文内容&#xff0c;全部选自自动化考研联盟的&#xff1a;《杭州电子科技大学861自控考研资料》的真题篇。后续会持续更新更多学校&#xff0c;更多年份的真题&#xff0c;记得关注哦~ 目录 2019年真题 2023年真题 Part1&#xff1a;2019年2023年完整版真题 2019年真题 2…

【Linux私房菜(九)之进程间通信】

文章目录 进程间通信介绍进程间通信的概念进程间通信的目的进程间通信的本质进程间通信的分类 管道什么是管道匿名管道匿名管道的原理pipe函数匿名管道使用步骤管道读写规则管道的特点管道的四种特殊情况管道的大小 命名管道命名管道的原理使用命令创建命名管道创建一个命名管道…

会声会影导出视频mp4格式哪个最高清,会声会影输出格式哪个清晰

调高分辨率后&#xff0c;mp4视频还是不清晰。哪怕全部使用4K级素材&#xff0c;仍然剪不出理想中的高画质作品。不是你的操作有问题&#xff0c;而是剪辑软件没选对。Corel公司拥有全球顶尖的图像处理技术&#xff0c;该公司研发的会声会影视频剪辑软件&#xff0c;在过去的20…

详解CSS中的伪元素

4.3 伪元素 可以把样式应用到文档树中根本不存在的元素上。 ::first-line 文本中的第一行 ::first-letter 文本中的第一个字母 ::after 元素之后添加 ::before 元素之前 代码&#xff1a; <!DOCTYPE html> <html> <head><meta charset"utf-8&q…

netty之Netty传输Java对象

前言 Netty在实际应用级开发中&#xff0c;有时候某些特定场景下会需要使用Java对象类型进行传输&#xff0c;但是如果使用Java本身序列化进行传输&#xff0c;那么对性能的损耗比较大。为此我们需要借助protostuff-core的工具包将对象以二进制形式传输并做编码解码处理。与直接…

无线物联网通信与智能家居

无线物联网通信技术与智能家居之间存在着密不可分的关系。无线物联网通信技术作为智能家居系统的核心支撑&#xff0c;为智能家居设备之间的互联互通提供了可能&#xff0c;从而实现了家居生活的智能化、便捷化和舒适化。 一、无线物联网通信技术在智能家居中的应用 1、传感器…

LabVIEW程序员从幼稚到成熟的标志是什么?

LabVIEW程序员从“幼稚”到“成熟”的转变标志主要体现在以下几个方面&#xff1a; 1. 系统性思维与架构设计 初学者通常会注重功能实现&#xff0c;常常直接编写功能模块&#xff0c;而忽略系统整体的架构设计。成熟的LabVIEW程序员则具备系统性思维&#xff0c;在开始编写代…

Ericsson EPSFB 通话掉话现象优化案例

Ericsson EPSFB 通话掉话现象优化案例 在移动通信网络中&#xff0c;用户体验的稳定性和通话质量至关重要。随着通信语言通话技术的发展&#xff0c;部分用户在通话时会遇到掉话现象&#xff0c;尤其是在采用EPSFB&#xff08;EvolvedPacket>System Fallback&#xff09;技术…

【WRF工具】cmip6-to-wrfinterm工具概述:生成WRF中间文件

cmip6-to-wrfinterm工具概述 cmip6-to-wrfinterm工具安装cmip6-to-wrfinterm工具使用快速启动&#xff08;Quick start&#xff09;情景1&#xff1a;MPI-ESM-1-2-HR&#xff08;默认&#xff09;&#xff1a;情景2&#xff1a;BCMM情景3&#xff1a;EC-Earth3 更改使用&#x…

SpringBoot框架下美容院管理系统的设计与实现

第二章 开发环境 对美容院管理系统进行开发&#xff0c;需要了解开发技术的理论与实际运用&#xff0c;对开发工具&#xff0c;尤其是数据库的使用方法需要进行掌握。 2.1 SpringBoot框架 SpringBoot框架的诞生是出于需要优化Spring框架的前提下&#xff0c;Spring框架随着时间…

【Simulink仿真】电池储能系统(BESS)与太阳能电站的SPS微电网模型

摘要 本文介绍了一个基于电池储能系统&#xff08;BESS&#xff09;与太阳能电站的微电网仿真模型。该模型使用SPS&#xff08;特殊保护系统&#xff09;进行模拟&#xff0c;能够在跟随电网和形成电网的两种模式下运行。微电网通过太阳能电站为主要能源&#xff0c;并结合了1…

ROS2功能包、节点、可执行程序是怎么来的、之间的关系是什么?详解!

在一个简单的ros2工作空间中&#xff0c;一般有一下几个文件夹&#xff0c; 1、src 2、install 3、build 4、log 其中&#xff0c;存放功能包项目的文件夹在src中&#xff0c;一般情况下&#xff0c;当我们要创建一个功能包项目的时候&#xff0c;要在src文件夹下输入以下…

安卓真机调试“no target device found“以及“ INSTALL_FAILED_USER_RESTRICTED“两个问题的解决办法

目录 1 no target device found问题解决办法 2 “INSTALL_FAILED_USER_RESTRICTED”解决办法 使用android studio 2023.2.1.23windows版本。手机为小米K70 Pro 1 no target device found问题解决办法 参考小米手机如何开启usb调试功能&#xff1f; (baidu.com) 1 联接手机…