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
时间: 2024-12-21 02:02:01

zfs 快照发送与接收的相关文章

解决网络不通数据只发送不接收

网络的畅通是表现在既有发送包,也有接收包,只有来去都畅通才正常.但是如果只有发送,却没有接收,碰到这样的故障到底又是怎么回事呢?在笔者短暂的两年网管生涯中,出现了几次这样的故障,但他们发生的原因又各有不同.今天笔者就把一些解决方法奉献给大家. 一般来说,出现这种故障的时候,网络连接都是都是好的,即不会出现红色的叉子图标.但这又只是一种表现的正常,因此我们入手的时候必须先从自身入手. 从自身入手的第一点就是检查出现该故障前有没有安装过什么软件,有没有改过什么设置,尤其是杀毒软件.防火墙这一类的软件

php发送与接收流文件的方法

 这篇文章主要介绍了php发送与接收流文件的方法,实例分析了php针对流文件的常见操作技巧,需要的朋友可以参考下     本文实例讲述了php发送与接收流文件的方法.分享给大家供大家参考.具体如下: sendStreamFile.php 把文件以流的形式发送 receiveStreamFile.php 接收流文件并保存到本地 sendStreamFile.php文件: 代码如下: <?php /** php 发送流文件 * @param String $url 接收的路径 * @param St

android 蓝牙编程重点---如何发送和接收16进制数据

与蓝牙模块通信最重要的地方就是数据的发送和接收,因为是底层的操作,所以更多是发送16进制数据. 进制转换是我们程序员的必修课,属于基本素质.这里需要的是将字节数组转化为16进制字符串,方法都是通用的: public static String bytesToHexString(byte[] bytes) { String result = ""; for (int i = 0; i < bytes.length; i++) { String hexString = Integer

转 JavaMail发送和接收邮件API(详解)

一.JavaMail概述:     JavaMail是由Sun定义的一套收发电子邮件的API,不同的厂商可以提供自己的实现类.但它并没有包含在JDK中,而是作为JavaEE的一部分.     厂商所提供的JavaMail服务程序可以有选择地实现某些邮件协议,常见的邮件协议包括: SMTP:简单邮件传输协议,用于发送电子邮件的传输协议: POP3:用于接收电子邮件的标准协议: IMAP:互联网消息协议,是POP3的替代协议.     这三种协议都有对应SSL加密传输的协议,分别是SMTPS,POP

nat穿透 udp-谁给一个在两个不同局域网内的主机,实现socket编程,能够发送和接收简单的数据

问题描述 谁给一个在两个不同局域网内的主机,实现socket编程,能够发送和接收简单的数据 本鸟在 网上查了一下资料,大部分都是关于tcp,udp穿透nat的方案,有一种是通过在一个外网的服务端的基础上实现,这得需要买一个外网ip,这种方案,我放弃了,我没钱买一个在公网上的ip 还一种一方端口映射,,不用外网的ip这种方式怎么实现啊??难道只是在路由器的转发规则,虚拟服务器上把自己的主机的ip和那个端口号添上就可以吗??上就可以吗??

串口数据传输-为什么调用不了串口的接收函数呢 只能发送 不能接收? 本人菜鸟,求指点

问题描述 为什么调用不了串口的接收函数呢 只能发送 不能接收? 本人菜鸟,求指点 public partial class Form1 : Form { //SerialPort sp1 = new SerialPort();//声明一个串口类 bool isOpen = false;//打开串口标志位 bool isSetProperty = false;//属性设置标志位 bool isHex = false;//十六进制显示标志位 public Form1() { //sp1.DataRe

windows10的IE及Edge浏览器如何发送和接收数据

问题描述 windows10的IE及Edge浏览器如何发送和接收数据 项目需要管控浏览器发送和接收的HTTP报文,挖取报文中的URL地址进行判断是否允许,在其他windows操作系统中都能正常实现,而在windows10操作系统中,无论是用API钩子技术还是LSP技术去管控connect及send,recv接口,都无法拦截到函数的调用(压根就没进到我的函数里),windows10里面的这两个浏览器连接外部服务器及发送和接收数据是有新的接口或者新的机制么??求大神解答 解决方案 如果是IE浏览器,

android大文件切割发送,接收后在合并显示

问题描述 android大文件切割发送,接收后在合并显示 android 大文件怎么实现分块传输,最后在合并显示.可以通过切割实现吗 解决方案 是文件断点续传吗...

Asp.net Socket客户端(远程发送和接收数据)_实用技巧

复制代码 代码如下: /*************************************** * 对象名称: SocketObj * 功能说明: 远程发送与接收 * 试用示例: * using EC; //引用空间名 * string url = "218.75.111.74"; // URL也可以是(http://www.baidu.com/)这种形式 * int port = 8000; //端口 * string SendStr = "domainname\n