LoginSignup
2
2

More than 5 years have passed since last update.

zfs send recvの差分転送を楽にする

Last updated at Posted at 2016-04-29

zfs send recvは手で書くと面倒なものです。関数を用意しました。

#!/bin/bash
send_recv_new () { #初回
    local from=${1} &&
    local to=${2} &&
    local snapshot=${3} &&
    local temp=${4} &&
    echo "${from} -> ${to} @${snapshot}" &&
    zfs snapshot "${from}@${temp}" &&
    zfs send     "${from}@${temp}" | zfs recv "${to}" &&
    zfs rename   "${from}@${temp}" "@${snapshot}" &&
    zfs rename   "${to}@${temp}" "@${snapshot}"
}
send_recv_new '<fromfs>' '<tofs>' '<fromfs>_to_<tofs>' 'temp'


inner_send_recv () { #内部処理
    local from=${1} &&
    local to=${2} &&
    local snapshot=${3} &&
    local temp=${4} &&
    echo "${from} -> ${to} @${snapshot}" &&
    zfs send -i "@${snapshot}" "${from}@${temp}" | zfs recv -F "${to}" && #-iで増分を送る
    zfs destroy "${from}@${snapshot}" &&
    zfs rename  "${from}@${temp}" "@${snapshot}" &&
    zfs destroy "${to}@${snapshot}" &&
    zfs rename  "${to}@${temp}" "@${snapshot}"
}
send_recv () { #2回目以降
    local from=${1} &&
    local to=${2} &&
    local snapshot=${3} &&
    local temp=${4} &&
    zfs snapshot "${from}@${temp}" &&
    inner_send_recv ${from} ${to} ${snapshot} ${temp}
}
send_recv '<fromfs>' '<tofs>' '<fromfs>_to_<tofs>' 'temp'

send_recv_r () { #2回目以降(再帰)
    local from=${1} &&
    local to=${2} &&
    local snapshot=${3} &&
    local temp=${4} &&
    zfs snapshot -r "${from}@${temp}" &&
    for fs in $(zfs list -H -r -o name ${from}); do
        local unique=${fs#${from}} &&
        inner_send_recv "${from}${unique}" "${to}${unique}" "${snapshot}" "${temp}"
        if [ $? -ne 0 ]; then
            return 1
        fi
    done
}
send_recv_r '<fromfs>' '<tofs>' '<fromfs>_to_<tofs>' 'temp'
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2