zfs 快照发送与接收

简介:
zfs具备将快照输出到stdout,以及从stdout接收快照的功能。
这两个功能分别通过zfs send和zfs receive命令来完成。

例子,
1. zfs send
有 -n -v -P 参数时,仅仅输出统计信息,不产生数据流。统计信息输出到stdout。
没有 -n -v -P 参数时,产生数据流,数据流输出到stdout,统计信息输出到stderr。
全量发送统计信息预览
#zfs send -v -P -n zp1/data01@2015123101
full    zp1/data01@2015123101   1120712615896
size    1120712615896

跳跃增量发送统计信息预览
#zfs send -v -P -n -i zp1/data01@2015123101 zp1/data01@2015123103
incremental     2015123101      zp1/data01@2015123103   106612682112
size    106612682112

递归增量发送统计信息预览
#zfs send -v -P -n -I zp1/data01@2015123101 zp1/data01@2015123103
incremental     2015123101      zp1/data01@2015123102   78172555224
incremental     2015123102      zp1/data01@2015123103   34534252176
size    112706807400

发送到文件
# zfs send zp1/data03@2015010301 > /u02/dege.zzz/zfs_back/abc


2. zfs send
从标准输入接收快照信息,并在本地创建该快照。
-n -p 不创建快照,只输出统计信息
没有 -n -p 创建快照

例子:
# cat /u02/dege.zzz/zfs_back/abc | zfs receive -n -v -d zp1/data03
would receive full stream of zp1/data03@2015010301 into zp1/data03/data03@2015010301
abc存储的是全量快照 zp1/data03@2015010301
-d表示取名时删除第一个元素zp1,剩余的 data03@2015010301 写入目标zp1/data03后面,得到 zp1/data03/data03@2015010301

如果不使用-d,并且目标和源冲突的话,会报错如下:
# cat /u02/dege.zzz/zfs_back/abc | zfs receive -n -v zp1/data03
cannot receive new filesystem stream: destination 'zp1/data03' exists
must specify -F to overwrite it


接收增量快照时,增量快照的前置快照必须已经在本地了。才能顺利根据增量快照,生成新的快照。
例如:
HOST A:
zfs snapshot zp1/data03@01
zfs snapshot zp1/data03@02
zfs snapshot zp1/data03@03
zfs snapshot zp1/data03@04
zfs send zp1/data03@01 > 01
zfs send -i zp1/data03@01 zp1/data03@04  > 01_04

HOST B:
假设host b 上没有zp1/data03的zfs filesystem,那么下面会自动创建 zp1/data03
cat 01 | zfs receive -d zp1
这一步将生成
zp1/data03@01
df -h|grep data03
zp1/data03            3.1T  192K  3.1T   1% /zp1/data03

然后接收增量
cat 01_04 | zfs receive -d zp1
自动创建快照  zp1/data03@04   
#zfs list -t snapshot|grep data03
zp1/data03@01            16K      -   192K  -
zp1/data03@04              0      -   192K  -


[参考]
1. man zfs
      zfs send [-DnPpRveL] [-[iI] snapshot] snapshot

       zfs send [-eL] [-i snapshot|bookmark] filesystem|volume|snapshot

       zfs receive | recv [-vnFu] filesystem|volume|snapshot

       zfs receive | recv [-vnFu] [-d|-e] filesystem


发送快照到stdout
       zfs send [-DnPpRveL] [-[iI] snapshot] snapshot

           Creates  a  stream  representation  of the second snapshot, which is written to standard output. The output can be redirected to a file or to a different system (for example, using ssh(1). By default, a
           full stream is generated.

           -i snapshot

               Generate an incremental stream from the first snapshot (the incremental source) to the second snapshot (the incremental target).  The incremental source can be specified as the last component of the
               snapshot name (the @ character and following) and it is assumed to be from the same file system as the incremental target.

               If the destination is a clone, the source may be the origin snapshot, which must be fully specified (for example, pool/fs@origin, not just @origin).

           -I snapshot

               Generate  a  stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. For example, -I @a fs@d is similar to -i @a fs@b; -i @b fs@c; -i @c fs@d. The incre-
               mental source may be specified as with the -i option.

           -R

               Generate a replication stream package, which will replicate the specified filesystem, and all descendent file systems, up to the named snapshot. When received, all properties, snapshots,  descendent
               file systems, and clones are preserved.

               If  the  -i or -I flags are used in conjunction with the -R flag, an incremental replication stream is generated. The current values of properties, and current snapshot and file system names are set
               when the stream is received. If the -F flag is specified when this stream is received, snapshots and file systems that do not exist on the sending side are destroyed.

           -D

               Generate a deduplicated stream. Blocks which would have been sent multiple times in the send stream will only be sent once. The receiving system must also support this feature to receive a  dedupli-
               cated stream.  This flag can be used regardless of the dataset’s dedup  property, but performance will be much better if the filesystem uses a dedup-capable checksum (eg.  sha256).

           -L

               Generate  a  stream which may contain blocks larger than 128KB.  This flag has no effect if the large_blocks pool feature is disabled, or if the recordsize property of this filesystem has never been
               set above 128KB.  The receiving system must have the large_blocks pool feature enabled as well.  See zpool-features(5) for details on ZFS feature flags and the large_blocks feature.

           -e

               Generate a more compact stream by using WRITE_EMBEDDED records for blocks which are stored more compactly on disk by the embedded_data pool feature.  This flag has no  effect  if  the  embedded_data
               feature is disabled.  The receiving system must have the embedded_data feature enabled.  If the lz4_compress feature is active on the sending system, then the receiving system must have that feature
               enabled as well. See zpool-features(5) for details on ZFS feature flags and the embedded_data feature.

           -p

               Include the dataset’s properties in the stream.  This flag is implicit when -R is specified.  The receiving system must also support this feature.

           -n

               Do a dry-run ("No-op") send.  Do not generate any actual send data.  This is useful in conjunction with the -v or -P flags to determine what data will be sent.  In this case, the verbose output will
               be written to standard output (contrast with a non-dry-run, where the stream is written to standard output and the verbose output goes to standard error).

           -P

               Print machine-parsable verbose information about the stream package generated.

           -v


               Print verbose information about the stream package generated.  This information includes a per-second report of how much data has been sent.

           The format of the stream is committed. You will be able to receive your streams on future versions of ZFS.


发送快照到stdout
       zfs send [-eL] [-i snapshot|bookmark] filesystem|volume|snapshot

           Generate  a  send  stream,  which may be of a filesystem, and may be incremental from a bookmark.  If the destination is a filesystem or volume, the pool must be read-only, or the filesystem must not be
           mounted.  When the stream generated from a filesystem or volume is received, the default snapshot name will be "--head--".

           -i snapshot|bookmark

               Generate an incremental send stream.  The incremental source must be an earlier snapshot in the destination’s history. It will commonly be an earlier snapshot in  the  destination’s  filesystem,  in
               which case it can be specified as the last component of the name (the # or @ character and following).

               If the incremental target is a clone, the incremental source can be the origin snapshot, or an earlier snapshot in the origin’s filesystem, or the origin’s origin, etc.

           -L

               Generate  a  stream which may contain blocks larger than 128KB.  This flag has no effect if the large_blocks pool feature is disabled, or if the recordsize property of this filesystem has never been
               set above 128KB.  The receiving system must have the large_blocks pool feature enabled as well.  See zpool-features(5) for details on ZFS feature flags and the large_blocks feature.

           -e

               Generate a more compact stream by using WRITE_EMBEDDED records for blocks which are stored more compactly on disk by the embedded_data pool feature.  This flag has no  effect  if  the  embedded_data
               feature is disabled.  The receiving system must have the embedded_data feature enabled.  If the lz4_compress feature is active on the sending system, then the receiving system must have that feature
               enabled as well. See zpool-features(5) for details on ZFS feature flags and the embedded_data feature.


从stdin接收数据,并转存到zfs快照中
       zfs receive [-vnFu] filesystem|volume|snapshot
       zfs receive [-vnFu] [-d|-e] filesystem

           Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created as well. Streams are created  using  the  zfs
           send subcommand, which by default creates a full stream. zfs recv can be used as an alias for zfs receive.

           If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream’s source. For zvols, the destination device link
           is destroyed and recreated, which means the zvol cannot be accessed during the receive operation.

           When a snapshot replication package stream that is generated by using the zfs send -R command is  received, any snapshots that do not exist on the sending location are destroyed by using the zfs destroy
           -d command.

           The name of the snapshot (and file system, if a full stream is received) that this subcommand creates depends on the argument type and the use of the -d or -e options.

           If the argument is a snapshot name, the specified snapshot is created. If the argument is a file system or volume name, a snapshot with the same name as the sent snapshot is created within the specified
           filesystem or volume.  If neither of the -d or -e options are specified, the provided target snapshot name is used exactly as provided.

           The -d and -e options cause the file system name of the target snapshot to be determined by appending a portion of the sent snapshot’s name to the specified target filesystem. If the -d option is speci-
           fied, all but the first element of the sent snapshot’s file system path (usually the pool name) is used and any required intermediate file systems within the specified one are created.  If the -e option
           is specified, then only the last element of the sent snapshot’s file system name (i.e. the name of the source file system itself) is used as the target file system name.

           -d

               Discard the first element of the sent snapshot’s file system name, using the remaining elements to determine the name of the target file system for the new snapshot as  described  in  the  paragraph
               above.

           -e

               Discard all but the last element of the sent snapshot’s file system name, using that element to determine the name of the target file system for the new snapshot as described in the paragraph above.

           -u

               File system that is associated with the received stream is not mounted.

           -v

               Print verbose information about the stream and the time required to perform the receive operation.

           -n

               Do not actually receive the stream. This can be useful in conjunction with the -v option to verify the name the receive operation would use.

           -F

               Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated  by  zfs  send  -R
               -[iI]), destroy snapshots and file systems that do not exist on the sending side.


例子
       Example 12 Remotely Replicating ZFS Data

       The following commands send a full stream and then an incremental stream to a remote machine, restoring them into poolB/received/fs@aand poolB/received/fs@b, respectively. poolB must contain the file system
       poolB/received, and must not initially contain poolB/received/fs.

         # zfs send pool/fs@a | \
            ssh host zfs receive poolB/received/fs@a
         # zfs send -i a pool/fs@b | ssh host \
            zfs receive poolB/received/fs

       Example 13 Using the zfs receive -d Option

       The  following  command  sends  a full stream of poolA/fsA/fsB@snap to a remote machine, receiving it into poolB/received/fsA/fsB@snap. The fsA/fsB@snap portion of the received snapshot’s name is determined
       from the name of the sent snapshot. poolB must contain the file system poolB/received. If poolB/received/fsA does not exist, it is created as an empty file system.

         # zfs send poolA/fsA/fsB@snap | \
            ssh host zfs receive -d poolB/received

       Example 24 Creating a bookmark

       The following example create a bookmark to a snapshot. This bookmark can then be used instead of snapshot in send streams.

         # zfs bookmark rpool@snapshot rpool#bookmark

目录
相关文章
|
存储 缓存 安全
virtiofs per-inode DAX 介绍
## 背景信息 1. 什么是 virtiofs? virtiofs 是一种用于在 host/guest 之间共享文件的文件系统,由 Redhat 开源,它使得不同 guest 之间能够以快速、一致、安全的方式共享同一个 host 目录树结构,目前广泛应用于 Kata Container 作为容器的 rootfs。 2. 什么是 DAX? DAX (Direct Access) 最初是针对于
4017 0
virtiofs per-inode DAX 介绍
|
Linux
`grep`命令搜索当前目录及其子目录下的所有文件
`grep`命令搜索当前目录及其子目录下的所有文件
7622 1
|
存储 数据挖掘 Python
单细胞 轨迹分析 教程(长文+代码)
单细胞 轨迹分析 教程(长文+代码)
932 10
单细胞 轨迹分析 教程(长文+代码)
送福利!FlowBench客户端首批内测邀请函
魔搭AIGC搭子们,集合啦!ModelScope x FlowBench 团队
553 3
|
存储 Java C#
深入理解synchronized实现原理
本文深入讲解了Java中`synchronized`关键字的实现原理。`synchronized`确保同一时刻只有一个线程能进入临界区,并保证共享变量的内存可见性。它通过monitor机制实现,作用于方法时使用ACC_SYNCHRONIZED标志,作用于代码块时使用monitorenter和monitorexit指令。每个对象都有一个与之关联的monitor,线程需获取monitor锁才能执行同步代码。Monitor内部包含_EntryList、_Owner、_WaitSet等队列,管理线程的加锁、等待和唤醒过程。
511 0
深入理解synchronized实现原理
|
消息中间件 编解码 Kafka
Go语言并发模型与模式:Worker Pool 模式
Worker Pool(工作池)模式是Go语言中管理高并发任务的有效方法。通过限制 Goroutine 数量,避免资源耗尽或系统崩溃。其核心包括任务通道、工作者 Goroutine、结果通道(可选)及同步机制。示例代码展示了如何分配与处理任务,同时支持带返回值的实现。该模式适用于网络服务、批量任务处理、消息消费等场景,具有限制并发、提高稳定性和结构清晰的优点。但需注意通道关闭时机、任务取消机制及错误处理等问题。Worker Pool 是构建高效任务处理系统的强大工具。
|
缓存 NoSQL 中间件
Redis的线程模型
Redis采用单线程模型确保操作的原子性,每次只执行一个操作,避免并发冲突。它通过MULTI/EXEC事务机制、Lua脚本和复合指令(如MSET、GETSET等)保证多个操作要么全成功,要么全失败,确保数据一致性。Redis事务在EXEC前失败则不执行任何操作,EXEC后失败不影响其他操作。Pipeline虽高效但不具备原子性,适合非热点时段的数据调整。Redis 7引入Function功能,支持函数复用,简化复杂业务逻辑。总结来说,Redis的单线程模型简单高效,适用于高并发场景,但仍需合理选择指令执行方式以发挥其性能优势。
455 6
|
存储 数据库 索引
B-Tree和B+Tree的区别及各自的优势
B-Tree和B+Tree的区别及各自的优势
1327 0
|
人工智能 搜索推荐 机器人
[AI Mem0] 概览,智能自我改进记忆层
[AI Mem0] 概览,智能自我改进记忆层

热门文章

最新文章